Turn fpdb_import functions into class Importer

Fix all callers of fpdb_import
This commit is contained in:
Worros 2008-10-09 01:36:08 +08:00
parent 79651706f6
commit 98b556f42c
7 changed files with 26 additions and 17 deletions

View File

@ -57,7 +57,7 @@ class GuiAutoImport (threading.Thread):
self.inputFile = os.path.join(self.path, file) self.inputFile = os.path.join(self.path, file)
stat_info = os.stat(self.inputFile) stat_info = os.stat(self.inputFile)
if not self.import_files.has_key(self.inputFile) or stat_info.st_mtime > self.import_files[self.inputFile]: if not self.import_files.has_key(self.inputFile) or stat_info.st_mtime > self.import_files[self.inputFile]:
fpdb_import.import_file_dict(self, self.settings, callHud = True) self.importer.import_file_dict(self, self.settings, callHud = True)
self.import_files[self.inputFile] = stat_info.st_mtime self.import_files[self.inputFile] = stat_info.st_mtime
print "GuiAutoImport.import_dir done" print "GuiAutoImport.import_dir done"
@ -121,6 +121,7 @@ class GuiAutoImport (threading.Thread):
def __init__(self, settings, debug=True): def __init__(self, settings, debug=True):
"""Constructor for GuiAutoImport""" """Constructor for GuiAutoImport"""
self.settings=settings self.settings=settings
self.importer = fpdb_import.Importer()
self.server=settings['db-host'] self.server=settings['db-host']
self.user=settings['db-user'] self.user=settings['db-user']

View File

@ -32,7 +32,7 @@ class GuiBulkImport (threading.Thread):
print "BulkImport is not recursive - please select the final directory in which the history files are" print "BulkImport is not recursive - please select the final directory in which the history files are"
else: else:
self.inputFile=self.path+os.sep+file self.inputFile=self.path+os.sep+file
fpdb_import.import_file_dict(self, self.settings, False) self.importer.import_file_dict(self, self.settings, False)
print "GuiBulkImport.import_dir done" print "GuiBulkImport.import_dir done"
def load_clicked(self, widget, data=None): def load_clicked(self, widget, data=None):
@ -69,7 +69,7 @@ class GuiBulkImport (threading.Thread):
if os.path.isdir(self.inputFile): if os.path.isdir(self.inputFile):
self.import_dir() self.import_dir()
else: else:
fpdb_import.import_file_dict(self, self.settings, False) self.importer.import_file_dict(self, self.settings, False)
def get_vbox(self): def get_vbox(self):
"""returns the vbox of this thread""" """returns the vbox of this thread"""
@ -83,6 +83,7 @@ class GuiBulkImport (threading.Thread):
def __init__(self, db, settings): def __init__(self, db, settings):
self.db=db self.db=db
self.settings=settings self.settings=settings
self.importer = fpdb_import.Importer()
self.vbox=gtk.VBox(False,1) self.vbox=gtk.VBox(False,1)
self.vbox.show() self.vbox.show()

View File

@ -255,8 +255,9 @@ class GuiTableViewer (threading.Thread):
self.failOnError=False self.failOnError=False
self.minPrint=0 self.minPrint=0
self.handCount=0 self.handCount=0
self.importer = fpdb_import.Importer()
self.last_read_hand_id=fpdb_import.import_file_dict(self, self.settings, False) self.last_read_hand_id=importer.import_file_dict(self, self.settings, False)
#end def table_viewer.import_clicked #end def table_viewer.import_clicked
def all_clicked(self, widget, data): def all_clicked(self, widget, data):

0
pyfpdb/HUD_main.py Normal file → Executable file
View File

View File

@ -57,19 +57,19 @@ class TestSequenceFunctions(unittest.TestCase):
print self.pgdict.query['list_tables'] print self.pgdict.query['list_tables']
self.result = self.pg_db.cursor.execute(self.pgdict.query['list_tables']) self.result = self.pg_db.cursor.execute(self.pgdict.query['list_tables'])
self.failUnless(self.result==13, "Number of tables in database incorrect. Expected 13 got " + str(self.result)) self.failUnless(self.result==13, "Number of tables in database incorrect. Expected 13 got " + str(self.result))
def testMySQLRecreateTables(self): def testMySQLRecreateTables(self):
"""Test droping then recreating fpdb table schema""" """Test droping then recreating fpdb table schema"""
self.mysql_db.recreate_tables() self.mysql_db.recreate_tables()
self.result = self.mysql_db.cursor.execute("SHOW TABLES") self.result = self.mysql_db.cursor.execute("SHOW TABLES")
self.failUnless(self.result==13, "Number of tables in database incorrect. Expected 13 got " + str(self.result)) self.failUnless(self.result==13, "Number of tables in database incorrect. Expected 13 got " + str(self.result))
def testPostgresSQLRecreateTables(self): def testPostgresSQLRecreateTables(self):
"""Test droping then recreating fpdb table schema""" """Test droping then recreating fpdb table schema"""
self.pg_db.recreate_tables() self.pg_db.recreate_tables()
self.result = self.pg_db.cursor.execute(self.pgdict.query['list_tables']) self.result = self.pg_db.cursor.execute(self.pgdict.query['list_tables'])
self.failUnless(self.result==13, "Number of tables in database incorrect. Expected 13 got " + str(self.result)) self.failUnless(self.result==13, "Number of tables in database incorrect. Expected 13 got " + str(self.result))
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -32,6 +32,7 @@ import GuiBulkImport
import GuiTableViewer import GuiTableViewer
import GuiAutoImport import GuiAutoImport
import GuiGraphViewer import GuiGraphViewer
import FpdbSQLQueries
class fpdb: class fpdb:
def tab_clicked(self, widget, tab_name): def tab_clicked(self, widget, tab_name):

View File

@ -38,17 +38,22 @@ import fpdb_simple
import fpdb_parse_logic import fpdb_parse_logic
from optparse import OptionParser from optparse import OptionParser
class Importer:
def import_file(server, database, user, password, inputFile): def __init__(self):
self.server=server """Constructor"""
self.database=database
self.user=user
self.password=password
self.inputFile=inputFile
self.settings={'imp-callFpdbHud':False}
import_file_dict(self, settings)
def import_file_dict(options, settings, callHud=False):
def import_file(self, server, database, user, password, inputFile):
self.server=server
self.database=database
self.user=user
self.password=password
self.inputFile=inputFile
self.settings={'imp-callFpdbHud':False}
self.import_file_dict(self, settings)
def import_file_dict(self, options, settings, callHud=False):
last_read_hand=0 last_read_hand=0
if (options.inputFile=="stdin"): if (options.inputFile=="stdin"):
inputFile=sys.stdin inputFile=sys.stdin
@ -225,4 +230,4 @@ if __name__ == "__main__":
(options, sys.argv) = parser.parse_args() (options, sys.argv) = parser.parse_args()
settings={'imp-callFpdbHud':False, 'db-backend':2} settings={'imp-callFpdbHud':False, 'db-backend':2}
import_file_dict(options, settings, False) # import_file_dict(options, settings, False)