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

ENH: Try to download sample data again after loading fails #876

Closed

Conversation

cpinter
Copy link
Member

@cpinter cpinter commented Jan 22, 2018

@cpinter cpinter force-pushed the redownload-corrupted-sample-datasets branch from 1916278 to 9313dc6 Compare January 22, 2018 21:26
@@ -185,7 +185,7 @@ def setup(self):
# Add spacer to layout
self.layout.addStretch(1)

def logMessage(self,message):
def logMessage(self, message, isError=False):
Copy link
Member

Choose a reason for hiding this comment

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

instead of isError, you could have a logLevel parameter where value could be logging.INFO or logging.ERROR. See https://docs.python.org/2/library/logging.html#logging-levels

Copy link
Member

Choose a reason for hiding this comment

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

I also suggest to improve self.log.insertHtml(message) so that the message is displayed in orange if logging.WARNING, and red if above that level.

@@ -195,6 +195,10 @@ def logMessage(self,message):
self.log.insertPlainText('\n')
self.log.ensureCursorVisible()
self.log.repaint()
if isError:
Copy link
Member

@jcfr jcfr Jan 22, 2018

Choose a reason for hiding this comment

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

replacing this with logging.log(logLevel, message) should do it then

if os.access(filePath, os.W_OK):
os.remove(filePath)
else:
self.logMessage('<b>Load failed! Unable to delete and try again loading %s!</b>\n' % filePath, True)
Copy link
Member

Choose a reason for hiding this comment

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

The message is reported only if the file doesn't exist not if it couldn't be deleted.
Some exception would have to be caught.
See https://docs.python.org/2/library/os.html#os.remove

Using the Qt implementation may have a more robust behavior across platform.

@cpinter cpinter force-pushed the redownload-corrupted-sample-datasets branch from 9313dc6 to 797a66b Compare January 22, 2018 22:20
@cpinter
Copy link
Member Author

cpinter commented Jan 22, 2018

Thanks, @jcfr! I updated the commit.

def logMessage(self,message):
def logMessage(self, message, logLevel=logging.INFO):
# Set text color based on log level
if logLevel is logging.ERROR:
Copy link
Member

Choose a reason for hiding this comment

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

if logLevel >= logging.ERROR:

# Set text color based on log level
if logLevel is logging.ERROR:
message = '<font color="red">' + message + '</font>'
elif logLevel is logging.WARNING:
Copy link
Member

Choose a reason for hiding this comment

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

elif logLevel >= logging.WARNING:

self.logMessage('<b>Load failed! Trying to download again...</b>', logging.ERROR)
file = qt.QFile(filePath)
if not file.remove():
self.logMessage('<b>Load failed! Unable to delete and try again loading %s!</b>' % filePath, logging.ERROR)
Copy link
Member

Choose a reason for hiding this comment

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

If it failed to remove the file, I suggest to completely fail and not try again.

@cpinter cpinter force-pushed the redownload-corrupted-sample-datasets branch from 797a66b to 897884f Compare January 22, 2018 22:53
@cpinter
Copy link
Member Author

cpinter commented Jan 22, 2018

@jcfr Another round done.

@cpinter
Copy link
Member Author

cpinter commented Jan 23, 2018

Good to go then?

@jcfr
Copy link
Member

jcfr commented Jan 23, 2018

Nitpick: Since the message seems to be systematically bold, you could have <b> set in logMessage function.

Assuming you tested locally, merging as it is would be perfectly fine too .

@cpinter
Copy link
Member Author

cpinter commented Jan 23, 2018

I did, it works well. Good point about the bold font, I'll do that, it takes only a second. Thanks

@cpinter
Copy link
Member Author

cpinter commented Jan 23, 2018

It's not consistently bold, see
https://github.com/Slicer/Slicer/blob/master/Modules/Scripted/SampleData/SampleData.py#L183
or
https://github.com/Slicer/Slicer/blob/master/Modules/Scripted/SampleData/SampleData.py#L390
I think I'll just go ahead and integrate

@jcfr
Copy link
Member

jcfr commented Jan 23, 2018

not consistently bold,

Thanks for looking into it

I'll just go ahead and integrate

👍

@cpinter
Copy link
Member Author

cpinter commented Jan 23, 2018

Integrated in Slicer/Slicer@09d9918

@cpinter cpinter closed this Jan 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants