remove connection code from fpdb_import.py and use fpdb_db.py instead
This commit is contained in:
parent
1a43ccf2da
commit
b62d1fb2a9
|
@ -36,6 +36,7 @@ import math
|
||||||
import os
|
import os
|
||||||
import datetime
|
import datetime
|
||||||
import re
|
import re
|
||||||
|
import fpdb_db
|
||||||
import fpdb_simple
|
import fpdb_simple
|
||||||
import fpdb_parse_logic
|
import fpdb_parse_logic
|
||||||
from time import time
|
from time import time
|
||||||
|
@ -47,7 +48,7 @@ class Importer:
|
||||||
self.settings=settings
|
self.settings=settings
|
||||||
self.caller=caller
|
self.caller=caller
|
||||||
self.config = config
|
self.config = config
|
||||||
self.db = None
|
self.fdb = None
|
||||||
self.cursor = None
|
self.cursor = None
|
||||||
self.filelist = {}
|
self.filelist = {}
|
||||||
self.dirlist = {}
|
self.dirlist = {}
|
||||||
|
@ -60,35 +61,12 @@ class Importer:
|
||||||
self.callHud = self.config.get_import_parameters().get("callFpdbHud")
|
self.callHud = self.config.get_import_parameters().get("callFpdbHud")
|
||||||
if not self.settings.has_key('minPrint'):
|
if not self.settings.has_key('minPrint'):
|
||||||
self.settings['minPrint'] = 30
|
self.settings['minPrint'] = 30
|
||||||
self.dbConnect()
|
self.fdb = fpdb_db.fpdb_db() # sets self.fdb.db self.fdb.cursor and self.fdb.sql
|
||||||
|
self.fdb.connect(self.settings['db-backend'],
|
||||||
# XXX: Why is this here, when fpdb_db.connect() already does the
|
self.settings['db-host'],
|
||||||
# same?
|
self.settings['db-databaseName'],
|
||||||
def dbConnect(self):
|
self.settings['db-user'],
|
||||||
#connect to DB
|
self.settings['db-password'])
|
||||||
if self.settings['db-backend'] == 2:
|
|
||||||
if not mysqlLibFound:
|
|
||||||
raise fpdb_simple.FpdbError("interface library MySQLdb not found but MySQL selected as backend - please install the library or change the config file")
|
|
||||||
self.db = MySQLdb.connect(self.settings['db-host'], self.settings['db-user'],
|
|
||||||
self.settings['db-password'], self.settings['db-databaseName'])
|
|
||||||
elif self.settings['db-backend'] == 3:
|
|
||||||
if not pgsqlLibFound:
|
|
||||||
raise fpdb_simple.FpdbError("interface library psycopg2 not found but PostgreSQL selected as backend - please install the library or change the config file")
|
|
||||||
print self.settings
|
|
||||||
if self.settings.has_key('db-host') and \
|
|
||||||
self.settings.has_key('db-user'):
|
|
||||||
self.db = psycopg2.connect(host = self.settings['db-host'],
|
|
||||||
user = self.settings['db-user'],
|
|
||||||
password = self.settings['db-password'],
|
|
||||||
database = self.settings['db-databaseName'])
|
|
||||||
else:
|
|
||||||
dbname = self.settings['db-databaseName']
|
|
||||||
self.db = psycopg2.connect(database = dbname)
|
|
||||||
elif self.settings['db-backend'] == 4:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
pass
|
|
||||||
self.cursor = self.db.cursor()
|
|
||||||
|
|
||||||
#Set functions
|
#Set functions
|
||||||
def setCallHud(self, value):
|
def setCallHud(self, value):
|
||||||
|
@ -243,12 +221,11 @@ class Importer:
|
||||||
self.hand=hand
|
self.hand=hand
|
||||||
|
|
||||||
try:
|
try:
|
||||||
handsId=fpdb_parse_logic.mainParser(self.settings['db-backend'], self.db
|
handsId=fpdb_parse_logic.mainParser(self.settings['db-backend'], self.fdb.db
|
||||||
,self.cursor, site, category, hand)
|
,self.fdb.cursor, site, category, hand)
|
||||||
self.db.commit()
|
self.fdb.db.commit()
|
||||||
|
|
||||||
stored+=1
|
stored+=1
|
||||||
self.db.commit()
|
|
||||||
if self.callHud:
|
if self.callHud:
|
||||||
#print "call to HUD here. handsId:",handsId
|
#print "call to HUD here. handsId:",handsId
|
||||||
#pipe the Hands.id out to the HUD
|
#pipe the Hands.id out to the HUD
|
||||||
|
@ -260,17 +237,17 @@ class Importer:
|
||||||
self.printEmailErrorMessage(errors, file, hand)
|
self.printEmailErrorMessage(errors, file, hand)
|
||||||
|
|
||||||
if (self.settings['failOnError']):
|
if (self.settings['failOnError']):
|
||||||
self.db.commit() #dont remove this, in case hand processing was cancelled.
|
self.fdb.db.commit() #dont remove this, in case hand processing was cancelled.
|
||||||
raise
|
raise
|
||||||
except (fpdb_simple.FpdbError), fe:
|
except (fpdb_simple.FpdbError), fe:
|
||||||
errors+=1
|
errors+=1
|
||||||
self.printEmailErrorMessage(errors, file, hand)
|
self.printEmailErrorMessage(errors, file, hand)
|
||||||
|
|
||||||
#fe.printStackTrace() #todo: get stacktrace
|
#fe.printStackTrace() #todo: get stacktrace
|
||||||
self.db.rollback()
|
self.fdb.db.rollback()
|
||||||
|
|
||||||
if (self.settings['failOnError']):
|
if (self.settings['failOnError']):
|
||||||
self.db.commit() #dont remove this, in case hand processing was cancelled.
|
self.fdb.db.commit() #dont remove this, in case hand processing was cancelled.
|
||||||
raise
|
raise
|
||||||
if (self.settings['minPrint']!=0):
|
if (self.settings['minPrint']!=0):
|
||||||
if ((stored+duplicates+partial+errors)%self.settings['minPrint']==0):
|
if ((stored+duplicates+partial+errors)%self.settings['minPrint']==0):
|
||||||
|
@ -295,7 +272,7 @@ class Importer:
|
||||||
print "failed to read a single hand from file:", inputFile
|
print "failed to read a single hand from file:", inputFile
|
||||||
handsId=0
|
handsId=0
|
||||||
#todo: this will cause return of an unstored hand number if the last hand was error or partial
|
#todo: this will cause return of an unstored hand number if the last hand was error or partial
|
||||||
self.db.commit()
|
self.fdb.db.commit()
|
||||||
self.handsId=handsId
|
self.handsId=handsId
|
||||||
return handsId
|
return handsId
|
||||||
#end def import_file_dict
|
#end def import_file_dict
|
||||||
|
|
Loading…
Reference in New Issue
Block a user