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
|
||||
#Set defaults
|
||||
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['minPrint'] = 30
|
||||
if 'handCount' not in self.settings:
|
||||
#TODO: Is this value in the xml file?
|
||||
self.settings['handCount'] = 0
|
||||
|
||||
self.settings.setdefault("minPrint", 30)
|
||||
self.settings.setdefault("handCount", 0)
|
||||
|
||||
self.fdb = fpdb_db.fpdb_db() # sets self.fdb.db self.fdb.cursor and self.fdb.sql
|
||||
self.fdb.do_connect(self.config)
|
||||
|
||||
|
@ -266,10 +264,10 @@ class Importer:
|
|||
|
||||
def import_fpdb_file(self, file, site):
|
||||
starttime = time()
|
||||
last_read_hand=0
|
||||
last_read_hand = 0
|
||||
loc = 0
|
||||
if (file=="stdin"):
|
||||
inputFile=sys.stdin
|
||||
if file == "stdin":
|
||||
inputFile = sys.stdin
|
||||
else:
|
||||
if os.path.exists(file):
|
||||
inputFile = open(file, "rU")
|
||||
|
@ -282,7 +280,7 @@ class Importer:
|
|||
pass
|
||||
# Read input file into class and close file
|
||||
inputFile.seek(loc)
|
||||
self.lines=fpdb_simple.removeTrailingEOL(inputFile.readlines())
|
||||
self.lines = fpdb_simple.removeTrailingEOL(inputFile.readlines())
|
||||
self.pos_in_file[file] = inputFile.tell()
|
||||
inputFile.close()
|
||||
|
||||
|
@ -298,29 +296,29 @@ class Importer:
|
|||
#self.parseTourneyHistory()
|
||||
return 0
|
||||
|
||||
site=fpdb_simple.recogniseSite(firstline)
|
||||
category=fpdb_simple.recogniseCategory(firstline)
|
||||
site = fpdb_simple.recogniseSite(firstline)
|
||||
category = fpdb_simple.recogniseCategory(firstline)
|
||||
|
||||
startpos=0
|
||||
stored=0 #counter
|
||||
duplicates=0 #counter
|
||||
partial=0 #counter
|
||||
errors=0 #counter
|
||||
startpos = 0
|
||||
stored = 0 #counter
|
||||
duplicates = 0 #counter
|
||||
partial = 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
|
||||
if (len(self.lines[i])<2):
|
||||
endpos=i
|
||||
hand=self.lines[startpos:endpos]
|
||||
if len(self.lines[i]) < 2:
|
||||
endpos = i
|
||||
hand = self.lines[startpos:endpos]
|
||||
|
||||
if (len(hand[0])<2):
|
||||
hand=hand[1:]
|
||||
if len(hand[0]) < 2:
|
||||
hand = hand[1:]
|
||||
|
||||
cancelled=False
|
||||
damaged=False
|
||||
if (site=="ftp"):
|
||||
for i in range (len(hand)):
|
||||
if (hand[i].endswith(" has been canceled")): #this is their typo. this is a typo, right?
|
||||
cancelled=True
|
||||
if hand[i].endswith(" has been canceled"): #this is their typo. this is a typo, right?
|
||||
cancelled = True
|
||||
|
||||
#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
|
||||
|
@ -334,15 +332,15 @@ class Importer:
|
|||
hand.insert(i+1, hand[i][mo.start()+1:])
|
||||
hand[i] = hand[i][0:mo.start()]
|
||||
|
||||
if (len(hand)<3):
|
||||
if len(hand) < 3:
|
||||
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.
|
||||
elif (hand[0].endswith(" (partial)")): #partial hand - do nothing
|
||||
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?
|
||||
partial+=1
|
||||
elif (cancelled or damaged):
|
||||
partial+=1
|
||||
elif hand[0].endswith(" (partial)"): #partial hand - do nothing
|
||||
partial += 1
|
||||
elif "Seat" not in hand[1] and "Seat" not in hand[2] and "Seat" not in hand[3]:
|
||||
partial += 1
|
||||
elif cancelled or damaged:
|
||||
partial += 1
|
||||
if damaged:
|
||||
print """
|
||||
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 "Line: %s" %(startpos)
|
||||
else: #normal processing
|
||||
isTourney=fpdb_simple.isTourney(hand[0])
|
||||
isTourney = fpdb_simple.isTourney(hand[0])
|
||||
if not isTourney:
|
||||
hand = fpdb_simple.filterAnteBlindFold(site,hand)
|
||||
self.hand=hand
|
||||
|
||||
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.db.commit()
|
||||
|
||||
stored+=1
|
||||
stored += 1
|
||||
if self.callHud:
|
||||
#print "call to HUD here. handsId:",handsId
|
||||
#pipe the Hands.id out to the HUD
|
||||
self.caller.pipe_to_hud.stdin.write("%s" % (handsId) + os.linesep)
|
||||
except fpdb_simple.DuplicateError:
|
||||
duplicates+=1
|
||||
duplicates += 1
|
||||
except (ValueError), fe:
|
||||
errors+=1
|
||||
errors += 1
|
||||
self.printEmailErrorMessage(errors, file, hand)
|
||||
|
||||
if (self.settings['failOnError']):
|
||||
self.fdb.db.commit() #dont remove this, in case hand processing was cancelled.
|
||||
raise
|
||||
except (fpdb_simple.FpdbError), fe:
|
||||
errors+=1
|
||||
errors += 1
|
||||
self.printEmailErrorMessage(errors, file, hand)
|
||||
|
||||
#fe.printStackTrace() #todo: get stacktrace
|
||||
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.
|
||||
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
|
||||
|
||||
if (self.settings['handCount']!=0):
|
||||
if ((stored+duplicates+partial+errors)>=self.settings['handCount']):
|
||||
if (not self.settings['quiet']):
|
||||
if self.settings['handCount']:
|
||||
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)
|
||||
startpos=endpos
|
||||
startpos = endpos
|
||||
ttime = time() - starttime
|
||||
print "\rTotal stored:", stored, "duplicates:", duplicates, "partial:", partial, "errors:", errors, " time:", ttime
|
||||
|
||||
if stored==0:
|
||||
if duplicates>0:
|
||||
for line_no in range(len(self.lines)):
|
||||
if not stored:
|
||||
if duplicates:
|
||||
for line_no in xrange(len(self.lines)):
|
||||
if self.lines[line_no].find("Game #")!=-1:
|
||||
final_game_line=self.lines[line_no]
|
||||
handsId=fpdb_simple.parseSiteHandNo(final_game_line)
|
||||
|
|
Loading…
Reference in New Issue
Block a user