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

BUG: fix runtime error related to creation of DICOM database directory #640

Closed
wants to merge 2 commits into from

Conversation

fedorov
Copy link
Member

@fedorov fedorov commented Dec 19, 2016

In some situations, user settings may point to a temporary directory with multiple
nesting levels, which cannot be created by os.mkdir().

To solve the issue, when exception occurs, fall back to creating the DICOM DB
directory in the default location.

Also fix a typo for the name of the DICOM DB location in developer mode.

cc: @che85

@fedorov fedorov requested review from pieper and jcfr December 19, 2016 18:07
try:
os.mkdir(databaseDirectory)
except OSError:
databaseDirectory = defaultDatabaseDirectory
Copy link

@che85 che85 Dec 19, 2016

Choose a reason for hiding this comment

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

@fedorov I would assign defaultDatabaseDirectory=os.path.join(documents, "SlicerDICOMDatabase") here because we could run into problems causing the variable to be referenced before assigned

Copy link
Member Author

Choose a reason for hiding this comment

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

You mean it could happen with testingEnabled, but failing to create the directory? I guess it is not impossible, but in this case wouldn't it make sense to move definition of defaultDatabaseDirectory to the top of the function?

Copy link

Choose a reason for hiding this comment

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

Oh yeah makes sense. I didn't see the message variable...

@pieper
Copy link
Member

pieper commented Dec 19, 2016

LGTM

if not os.path.exists(databaseDirectory):
os.mkdir(databaseDirectory)
try:
os.mkdir(databaseDirectory)
Copy link
Contributor

Choose a reason for hiding this comment

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

os.makedirs works recursively, use that to take care of nested directories
(permission or other issues may still prevent directory creation, so it's fine to keep exception handling)

Copy link
Member Author

Choose a reason for hiding this comment

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

@pieper is there any particular reason why os.makedirs was not used in the first place? If there is no some hidden logic, I will push the change.

Copy link
Member

Choose a reason for hiding this comment

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

+1 to os.mkdirs

message = "DICOM Database will be stored in\n\n{}\n\nUse the Local Database button in " \
"the DICOM Browser to pick a different location.".format(databaseDirectory)
slicer.util.infoDisplay(message, windowTitle='DICOM')
documentsLocation = qt.QDesktopServices.DocumentsLocation
Copy link
Contributor

Choose a reason for hiding this comment

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

I had to spend several minutes reviewing this couple of lines of code and I'm still not sure about intent and correctness. Please put variable initializations where to the closest possible place where variables are actually used (similarly as it was in the original version).

Copy link
Member Author

Choose a reason for hiding this comment

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

I did not move initialization of the variables, they remain in the same places where they were in the original version. It looks like I moved them, but I just changed the spacing. I think the location is alright, not sure what can be improved here.

Copy link
Member Author

Choose a reason for hiding this comment

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

@fedorov
Copy link
Member Author

fedorov commented Jan 4, 2017

I updated the code to rearrange few variables and use os.makedirs().

@fedorov
Copy link
Member Author

fedorov commented Jan 6, 2017

@lassoan I believe I addressed your concerns. Please let me know if any further changes are needed. Thank you.

@lassoan
Copy link
Contributor

lassoan commented Jan 6, 2017

Thank you.

In some situations, user settings may point to a temporary directory with multiple
nesting levels, which cannot be created by os.mkdir().

To solve the issue, when exception occurs, fall back to creating the DICOM DB
directory in the default location.

Also fix a typo for the name of the DICOM DB location in developer mode.
Also use os.makedirs() in place of os.mkdir()
@fedorov
Copy link
Member Author

fedorov commented Jan 6, 2017

Thanks!

Integrated in r25633 = 2a6e43e

@fedorov fedorov closed this Jan 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants