def update(self): filesFailed = [] while not self.updateQueue.empty(): # get filename from queue filename = self.updateQueue.get() # ensure the pathname for the file is complete # in order to prevent errors indicating a file doesn't exist filepath = path.join(self.watchDirectory, os.path.basename(filename)) # update file to the dropbox server file = open(filepath, "rb") try: self.client.put_file(path.join(self.destDirectory, path.basename(filename)), file, overwrite=True) log.printLog("file updated to dropbox: " + filename) except (urllib3.exceptions.MaxRetryError, dropbox.rest.ErrorResponse): log.printLog("failed to upload: " + filename) # add file to the list of failed files filesFailed.append(filename) file.close() # notify that the current task is done self.updateQueue.task_done() if filesFailed: # readd failed files to the queue for filename in filesFailed: self.updateQueue.put(filename)
if answer == 'n': settings = dict() finally: print # Check that all global settings are valid if len(settings) != len(settingsDescriptions) and len(settingsDescriptions) != 0: try: print "Please enter the following information:" for s in settingsDescriptions: if s not in settings: settings[s] = raw_input('{}: '.format(settingsDescriptions[s])) st.writeSettings(scriptDir, settings) finally: print modes = ["Run MOSS", "Archive submissions"] mode = modes.index(ui.selectOption('What would you like to do?', modes)) if mode == 0: run.RunMode(settings) elif mode == 1: archive.ArchiveMode(settings) else: raise Exception('Invalid mode') except KeyboardInterrupt, SystemExit: print '\nCancelled!' except Exception as ex: log.printLog(repr(ex))
def on_created(self, event): if not event.is_directory: self.updateQueue.put(event.src_path) log.printLog("added the file " + event.src_path)