fix runUpdated() to not freak out if a file disappears on it

This commit is contained in:
eblade 2009-03-13 06:21:48 -04:00
parent 382ed4b067
commit a5b9ea860d

View File

@ -190,24 +190,26 @@ class Importer:
self.addImportDirectory(self.dirlist[site][0], False, site, self.dirlist[site][1]) self.addImportDirectory(self.dirlist[site][0], False, site, self.dirlist[site][1])
for file in self.filelist: for file in self.filelist:
stat_info = os.stat(file) if os.path.exists(file):
try: stat_info = os.stat(file)
lastupdate = self.updated[file] try:
if stat_info.st_mtime > lastupdate: lastupdate = self.updated[file]
self.import_file_dict(file, self.filelist[file][0], self.filelist[file][1]) if stat_info.st_mtime > lastupdate:
self.import_file_dict(file, self.filelist[file][0], self.filelist[file][1])
self.updated[file] = time()
except:
self.updated[file] = time() self.updated[file] = time()
except: # If modified in the last minute run an immediate import.
self.updated[file] = time() # This codepath only runs first time the file is found.
# If modified in the last minute run an immediate import. if os.path.isdir(file) or (time() - stat_info.st_mtime) < 60:
# This codepath only runs first time the file is found. # TODO attach a HHC thread to the file
if os.path.isdir(file) or (time() - stat_info.st_mtime) < 60: # TODO import the output of the HHC thread -- this needs to wait for the HHC to block?
# TODO attach a HHC thread to the file self.import_file_dict(file, self.filelist[file][0], self.filelist[file][1])
# TODO import the output of the HHC thread -- this needs to wait for the HHC to block?
self.import_file_dict(file, self.filelist[file][0], self.filelist[file][1])
# TODO we also test if directory, why? # TODO we also test if directory, why?
#if os.path.isdir(file): #if os.path.isdir(file):
#self.import_file_dict(file, self.filelist[file][0], self.filelist[file][1]) #self.import_file_dict(file, self.filelist[file][0], self.filelist[file][1])
else:
removeFromFileList[file] = True
self.addToDirList = filter(lambda x: self.addImportDirectory(x, True, self.addToDirList[x][0], self.addToDirList[x][1]), self.addToDirList) self.addToDirList = filter(lambda x: self.addImportDirectory(x, True, self.addToDirList[x][0], self.addToDirList[x][1]), self.addToDirList)
for file in self.removeFromFileList: for file in self.removeFromFileList: