Move more "options" from calling class into settings has of fpdb_import and fix all callers

This commit is contained in:
Worros 2008-10-12 02:14:06 +08:00
parent 1e8333ec5d
commit 638a6d6dab
4 changed files with 26 additions and 17 deletions

View File

@ -124,14 +124,14 @@ class GuiAutoImport (threading.Thread):
self.importer = fpdb_import.Importer(self,self.settings)
self.importer.setCallHud(True)
self.importer.setMinPrint(30)
self.importer.setQuiet(False)
self.importer.setFailOnError(False)
self.importer.setHandCount(0)
self.server=settings['db-host']
self.user=settings['db-user']
self.password=settings['db-password']
self.database=settings['db-databaseName']
self.quiet=False
self.failOnError=False
self.handCount=0
self.mainVBox=gtk.VBox(False,1)
self.mainVBox.show()

View File

@ -40,9 +40,9 @@ class GuiBulkImport (threading.Thread):
self.handCount=self.hand_count_tbuffer.get_text(self.hand_count_tbuffer.get_start_iter(), self.hand_count_tbuffer.get_end_iter())
if (self.handCount=="unlimited" or self.handCount=="Unlimited"):
self.handCount=0
self.importer.setHandCount(0)
else:
self.handCount=int(self.handCount)
self.importer.setHandCount(int(self.handCount))
self.errorFile="failed.txt"
@ -54,15 +54,15 @@ class GuiBulkImport (threading.Thread):
self.quiet=self.info_tbuffer.get_text(self.info_tbuffer.get_start_iter(), self.info_tbuffer.get_end_iter())
if (self.quiet=="yes"):
self.quiet=False
self.importer.setQuiet(False)
else:
self.quiet=True
self.importer.setQuiet(True)
self.failOnError=self.fail_error_tbuffer.get_text(self.fail_error_tbuffer.get_start_iter(), self.fail_error_tbuffer.get_end_iter())
if (self.failOnError=="no"):
self.failOnError=False
self.importer.setFailOnError(False)
else:
self.failOnError=True
self.importer.setFailOnError(True)
if os.path.isdir(self.inputFile):
self.import_dir()

View File

@ -251,11 +251,11 @@ class GuiTableViewer (threading.Thread):
self.user=self.db.user
self.password=self.db.password
self.quiet=False
self.failOnError=False
self.handCount=0
self.importer = fpdb_import.Importer(self, self.settings)
self.importer.setMinPrint(0)
self.importer.setQuiet(False)
self.importer.setFailOnError(False)
self.importer.setHandCount(0)
self.last_read_hand_id=self.importer.import_file_dict()
#end def table_viewer.import_clicked

View File

@ -83,6 +83,15 @@ class Importer:
def setMinPrint(self, value):
self.settings['minPrint'] = int(value)
def setHandCount(self, value):
self.settings['handCount'] = int(value)
def setQuiet(self, value):
self.settings['quiet'] = value
def setFailOnError(self, value):
self.settings['failOnError'] = value
def import_file_dict(self):
starttime = time()
last_read_hand=0
@ -168,7 +177,7 @@ class Importer:
errors+=1
self.printEmailErrorMessage(errors, self.caller.inputFile, hand[0])
if (self.caller.failOnError):
if (self.settings['failOnError']):
self.db.commit() #dont remove this, in case hand processing was cancelled.
raise
except (fpdb_simple.FpdbError), fe:
@ -178,16 +187,16 @@ class Importer:
#fe.printStackTrace() #todo: get stacktrace
self.db.rollback()
if (self.caller.failOnError):
if (self.settings['failOnError']):
self.db.commit() #dont remove this, in case hand processing was cancelled.
raise
if (self.settings['minPrint']!=0):
if ((stored+duplicates+partial+errors)%self.settings['minPrint']==0):
print "stored:", stored, "duplicates:", duplicates, "partial:", partial, "errors:", errors
if (self.caller.handCount!=0):
if ((stored+duplicates+partial+errors)>=self.caller.handCount):
if (not self.caller.quiet):
if (self.settings['handCount']!=0):
if ((stored+duplicates+partial+errors)>=self.settings['handCount']):
if (not self.settings['quiet']):
print "quitting due to reaching the amount of hands to be imported"
print "Total stored:", stored, "duplicates:", duplicates, "partial/damaged:", partial, "errors:", errors, " time:", (time() - starttime)
sys.exit(0)