mostly spacing cleanup
This commit is contained in:
parent
c91244cdad
commit
465f27af4d
|
@ -67,12 +67,10 @@ class Importer:
|
||||||
self.pos_in_file = {} # dict to remember how far we have read in the file
|
self.pos_in_file = {} # dict to remember how far we have read in the file
|
||||||
#Set defaults
|
#Set defaults
|
||||||
self.callHud = self.config.get_import_parameters().get("callFpdbHud")
|
self.callHud = self.config.get_import_parameters().get("callFpdbHud")
|
||||||
if 'minPrint' not in self.settings:
|
|
||||||
#TODO: Is this value in the xml file?
|
self.settings.setdefault("minPrint", 30)
|
||||||
self.settings['minPrint'] = 30
|
self.settings.setdefault("handCount", 0)
|
||||||
if 'handCount' not in self.settings:
|
|
||||||
#TODO: Is this value in the xml file?
|
|
||||||
self.settings['handCount'] = 0
|
|
||||||
self.fdb = fpdb_db.fpdb_db() # sets self.fdb.db self.fdb.cursor and self.fdb.sql
|
self.fdb = fpdb_db.fpdb_db() # sets self.fdb.db self.fdb.cursor and self.fdb.sql
|
||||||
self.fdb.do_connect(self.config)
|
self.fdb.do_connect(self.config)
|
||||||
|
|
||||||
|
@ -216,7 +214,7 @@ class Importer:
|
||||||
else:
|
else:
|
||||||
removeFromFileList[file] = True
|
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:
|
||||||
if file in self.filelist:
|
if file in self.filelist:
|
||||||
del self.filelist[file]
|
del self.filelist[file]
|
||||||
|
@ -266,10 +264,10 @@ class Importer:
|
||||||
|
|
||||||
def import_fpdb_file(self, file, site):
|
def import_fpdb_file(self, file, site):
|
||||||
starttime = time()
|
starttime = time()
|
||||||
last_read_hand=0
|
last_read_hand = 0
|
||||||
loc = 0
|
loc = 0
|
||||||
if (file=="stdin"):
|
if file == "stdin":
|
||||||
inputFile=sys.stdin
|
inputFile = sys.stdin
|
||||||
else:
|
else:
|
||||||
if os.path.exists(file):
|
if os.path.exists(file):
|
||||||
inputFile = open(file, "rU")
|
inputFile = open(file, "rU")
|
||||||
|
@ -282,7 +280,7 @@ class Importer:
|
||||||
pass
|
pass
|
||||||
# Read input file into class and close file
|
# Read input file into class and close file
|
||||||
inputFile.seek(loc)
|
inputFile.seek(loc)
|
||||||
self.lines=fpdb_simple.removeTrailingEOL(inputFile.readlines())
|
self.lines = fpdb_simple.removeTrailingEOL(inputFile.readlines())
|
||||||
self.pos_in_file[file] = inputFile.tell()
|
self.pos_in_file[file] = inputFile.tell()
|
||||||
inputFile.close()
|
inputFile.close()
|
||||||
|
|
||||||
|
@ -298,29 +296,29 @@ class Importer:
|
||||||
#self.parseTourneyHistory()
|
#self.parseTourneyHistory()
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
site=fpdb_simple.recogniseSite(firstline)
|
site = fpdb_simple.recogniseSite(firstline)
|
||||||
category=fpdb_simple.recogniseCategory(firstline)
|
category = fpdb_simple.recogniseCategory(firstline)
|
||||||
|
|
||||||
startpos=0
|
startpos = 0
|
||||||
stored=0 #counter
|
stored = 0 #counter
|
||||||
duplicates=0 #counter
|
duplicates = 0 #counter
|
||||||
partial=0 #counter
|
partial = 0 #counter
|
||||||
errors=0 #counter
|
errors = 0 #counter
|
||||||
|
|
||||||
for i in xrange (len(self.lines)): #main loop, iterates through the lines of a file and calls the appropriate parser method
|
for i in xrange (len(self.lines)): #main loop, iterates through the lines of a file and calls the appropriate parser method
|
||||||
if (len(self.lines[i])<2):
|
if len(self.lines[i]) < 2:
|
||||||
endpos=i
|
endpos = i
|
||||||
hand=self.lines[startpos:endpos]
|
hand = self.lines[startpos:endpos]
|
||||||
|
|
||||||
if (len(hand[0])<2):
|
if len(hand[0]) < 2:
|
||||||
hand=hand[1:]
|
hand = hand[1:]
|
||||||
|
|
||||||
cancelled=False
|
cancelled=False
|
||||||
damaged=False
|
damaged=False
|
||||||
if (site=="ftp"):
|
if (site=="ftp"):
|
||||||
for i in range (len(hand)):
|
for i in range (len(hand)):
|
||||||
if (hand[i].endswith(" has been canceled")): #this is their typo. this is a typo, right?
|
if hand[i].endswith(" has been canceled"): #this is their typo. this is a typo, right?
|
||||||
cancelled=True
|
cancelled = True
|
||||||
|
|
||||||
#FTP generates lines looking like:
|
#FTP generates lines looking like:
|
||||||
#Seat 1: IOS Seat 2: kashman59 (big blind) showed [8c 9d] and won ($3.25) with a pair of Eights
|
#Seat 1: IOS Seat 2: kashman59 (big blind) showed [8c 9d] and won ($3.25) with a pair of Eights
|
||||||
|
@ -334,15 +332,15 @@ class Importer:
|
||||||
hand.insert(i+1, hand[i][mo.start()+1:])
|
hand.insert(i+1, hand[i][mo.start()+1:])
|
||||||
hand[i] = hand[i][0:mo.start()]
|
hand[i] = hand[i][0:mo.start()]
|
||||||
|
|
||||||
if (len(hand)<3):
|
if len(hand) < 3:
|
||||||
pass
|
pass
|
||||||
#todo: the above 2 lines are kind of a dirty hack, the mentioned circumstances should be handled elsewhere but that doesnt work with DOS/Win EOL. actually this doesnt work.
|
#todo: the above 2 lines are kind of a dirty hack, the mentioned circumstances should be handled elsewhere but that doesnt work with DOS/Win EOL. actually this doesnt work.
|
||||||
elif (hand[0].endswith(" (partial)")): #partial hand - do nothing
|
elif hand[0].endswith(" (partial)"): #partial hand - do nothing
|
||||||
partial+=1
|
partial += 1
|
||||||
elif (hand[1].find("Seat")==-1 and hand[2].find("Seat")==-1 and hand[3].find("Seat")==-1):#todo: should this be or instead of and?
|
elif "Seat" not in hand[1] and "Seat" not in hand[2] and "Seat" not in hand[3]:
|
||||||
partial+=1
|
partial += 1
|
||||||
elif (cancelled or damaged):
|
elif cancelled or damaged:
|
||||||
partial+=1
|
partial += 1
|
||||||
if damaged:
|
if damaged:
|
||||||
print """
|
print """
|
||||||
DEBUG: Partial hand triggered by a line containing 'Seat X:' twice. This is a
|
DEBUG: Partial hand triggered by a line containing 'Seat X:' twice. This is a
|
||||||
|
@ -352,57 +350,58 @@ class Importer:
|
||||||
print "File: %s" %(file)
|
print "File: %s" %(file)
|
||||||
print "Line: %s" %(startpos)
|
print "Line: %s" %(startpos)
|
||||||
else: #normal processing
|
else: #normal processing
|
||||||
isTourney=fpdb_simple.isTourney(hand[0])
|
isTourney = fpdb_simple.isTourney(hand[0])
|
||||||
if not isTourney:
|
if not isTourney:
|
||||||
hand = fpdb_simple.filterAnteBlindFold(site,hand)
|
hand = fpdb_simple.filterAnteBlindFold(site,hand)
|
||||||
self.hand=hand
|
self.hand=hand
|
||||||
|
|
||||||
try:
|
try:
|
||||||
handsId=fpdb_parse_logic.mainParser(self.settings['db-backend'], self.fdb.db
|
handsId = fpdb_parse_logic.mainParser(self.settings['db-backend'], self.fdb.db
|
||||||
,self.fdb.cursor, site, category, hand, self.config)
|
,self.fdb.cursor, site, category, hand, self.config)
|
||||||
self.fdb.db.commit()
|
self.fdb.db.commit()
|
||||||
|
|
||||||
stored+=1
|
stored += 1
|
||||||
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
|
||||||
self.caller.pipe_to_hud.stdin.write("%s" % (handsId) + os.linesep)
|
self.caller.pipe_to_hud.stdin.write("%s" % (handsId) + os.linesep)
|
||||||
except fpdb_simple.DuplicateError:
|
except fpdb_simple.DuplicateError:
|
||||||
duplicates+=1
|
duplicates += 1
|
||||||
except (ValueError), fe:
|
except (ValueError), fe:
|
||||||
errors+=1
|
errors += 1
|
||||||
self.printEmailErrorMessage(errors, file, hand)
|
self.printEmailErrorMessage(errors, file, hand)
|
||||||
|
|
||||||
if (self.settings['failOnError']):
|
if (self.settings['failOnError']):
|
||||||
self.fdb.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.fdb.db.rollback()
|
self.fdb.db.rollback()
|
||||||
|
|
||||||
if (self.settings['failOnError']):
|
if self.settings['failOnError']:
|
||||||
self.fdb.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 ((stored+duplicates+partial+errors)%self.settings['minPrint']==0):
|
if self.settings['minPrint']:
|
||||||
|
if not ((stored+duplicates+partial+errors) % self.settings['minPrint']):
|
||||||
print "stored:", stored, "duplicates:", duplicates, "partial:", partial, "errors:", errors
|
print "stored:", stored, "duplicates:", duplicates, "partial:", partial, "errors:", errors
|
||||||
|
|
||||||
if (self.settings['handCount']!=0):
|
if self.settings['handCount']:
|
||||||
if ((stored+duplicates+partial+errors)>=self.settings['handCount']):
|
if ((stored+duplicates+partial+errors) >= self.settings['handCount']):
|
||||||
if (not self.settings['quiet']):
|
if not self.settings['quiet']:
|
||||||
print "quitting due to reaching the amount of hands to be imported"
|
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)
|
print "Total stored:", stored, "duplicates:", duplicates, "partial/damaged:", partial, "errors:", errors, " time:", (time() - starttime)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
startpos=endpos
|
startpos = endpos
|
||||||
ttime = time() - starttime
|
ttime = time() - starttime
|
||||||
print "\rTotal stored:", stored, "duplicates:", duplicates, "partial:", partial, "errors:", errors, " time:", ttime
|
print "\rTotal stored:", stored, "duplicates:", duplicates, "partial:", partial, "errors:", errors, " time:", ttime
|
||||||
|
|
||||||
if stored==0:
|
if not stored:
|
||||||
if duplicates>0:
|
if duplicates:
|
||||||
for line_no in range(len(self.lines)):
|
for line_no in xrange(len(self.lines)):
|
||||||
if self.lines[line_no].find("Game #")!=-1:
|
if self.lines[line_no].find("Game #")!=-1:
|
||||||
final_game_line=self.lines[line_no]
|
final_game_line=self.lines[line_no]
|
||||||
handsId=fpdb_simple.parseSiteHandNo(final_game_line)
|
handsId=fpdb_simple.parseSiteHandNo(final_game_line)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user