Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if folder already exists by checking its actual name, not the name of the entry to -d flag #2425

Merged
merged 5 commits into from
Sep 13, 2019

Conversation

gmotzespina
Copy link
Contributor

@gmotzespina gmotzespina commented Sep 3, 2019

Removes folder names based on it's name not on data_name

Fixes: #2425

@@ -127,24 +128,46 @@ def main(args=None):
data_name = arguments['-d']
verbose = int(arguments.get('-v'))
sct.init_sct(log_level=verbose, update=True) # Update log level
dest_folder = arguments.get('-o', os.path.abspath(os.curdir))
dest_tmp_folder = arguments.get('-o', os.path.abspath(os.curdir)+'/tmp')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"/" doesn't work in Windows, and what if user already has a local folder called "./tmp/"?
there are better ways to generate temp folders, see class sct_utils.TempFolder

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh ok, nice one, looking at it.

# unzip
unzip(tmp_file, dest_tmp_folder, verbose)
data_extracted_name = data_name
if dest_tmp_folder != os.path.abspath(os.curdir)+'/bin':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why "bin"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it is the path where the installation requirements are downloaded.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sct_download_data is not only used for installing binaries (look at the help)

Copy link
Member

@jcohenadad jcohenadad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Travis failing: https://travis-ci.org/neuropoly/spinalcordtoolbox/jobs/580121506#L1089

likely because of problem when downloading the data

@gmotzespina gmotzespina changed the title Remove folder based on name not on data_name WIP Remove folder based on name not on data_name Sep 4, 2019
'https://www.neuro.polymtl.ca/_media/downloads/sct/20180613_deepseg_lesion_models.zip'],
'c2c3_disc_models': ['https://osf.io/t97ap/?action=download',
'https://www.neuro.polymtl.ca/_media/downloads/sct/20190117_c2c3_disc_models.zip']
"sct_example_data": [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gmotzespina please see the convention: https://github.com/neuropoly/spinalcordtoolbox/wiki/Single-or-double-quotes

unless you have a good reason for going with double quote?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started testing out Black, and it changed my file to double quotes, since it is kind of the black standard. I'll revert all of this changes before sending the request again.

While checking out black I also figured out that using double quotes instead of single might be a better option since we can write stuff like this: "it's a test" otherwise, while using single quotes we would need to write the same text this way: 'it\'s a test'.

What do you think about it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the double quote argument is indeed a good argument, but we could also make the argument that with single quote, we can do that: 'When using this option, enter parameter "n"'. Also, single quotes makes the code lighter.

Anyway, regardless the decision, this should be mixed with this PR, which is about fixing a specific problem, not changing code cosmetic. Otherwise, it makes it difficult for me to review your code.

so: open a separate issue regarding code cosmetic, and we will address it specifically

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I didn't thought about the options.

Yeah, I'll revert those changes once the PR is ready, they just got mixed because of Black, but it was not intended to have those changes in this PR.

sct.rmtree(data_name)
# Extracting the binaries doesn't require removing the previously created directories
# since binaries are files, not directories
if "binaries" in data_name:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will break if compressed files don't have the term "binaries" in it. Why not simply:

  • check if the uncompressed zip gives you a folder
  • check if the folder already exists
  • if it does, remove it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I figured out that this would happen, I'm currently working on a fix. to have this done in a cleaner way.

for folder in dirs:
folders.append(os.path.join(root, folder))
data_extracted_path = folders[0]
directories = data_extracted_path.split("/")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

python has built-in modules to do such manipulations which will break with windows (when, one day, SCT will be compatible with windows...)

@gmotzespina gmotzespina force-pushed the gmo/folder_removal_based_on_name_2390 branch from 0e910c6 to 7914530 Compare September 10, 2019 17:37
Copy link
Member

@jcohenadad jcohenadad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@jcohenadad jcohenadad changed the title WIP Remove folder based on name not on data_name Remove folder based on its name, not on data_name Sep 13, 2019
@jcohenadad jcohenadad changed the title Remove folder based on its name, not on data_name Check if folder already exists by checking its actual name, not the name of the entry to -d flag Sep 13, 2019
@jcohenadad jcohenadad added enhancement category: improves performance/results of an existing feature sct_download_data context: labels Sep 13, 2019
@gmotzespina gmotzespina merged commit 8746c6f into master Sep 13, 2019
jcohenadad pushed a commit that referenced this pull request Dec 18, 2019
…ame_2390

Check if folder already exists by checking its actual name, not the name of the entry to -d flag

Former-commit-id: da80ab466bdefc3f979d6a1991735f1533838b6a [formerly 23c02c9 [formerly 8746c6f]]
Former-commit-id: f0c6acc3c6e40757a255a2fa097c065acaa29f79
Former-commit-id: 3eb4950
jcohenadad pushed a commit that referenced this pull request Dec 18, 2019
…ame_2390

Check if folder already exists by checking its actual name, not the name of the entry to -d flag

Former-commit-id: 8746c6f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement category: improves performance/results of an existing feature sct_download_data context:
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants