Refactor HHC call a bit, make sure out_fh gets closed

This commit is contained in:
Worros 2009-03-13 00:31:29 +09:00
parent c523fce123
commit 2d849c69e7
2 changed files with 16 additions and 18 deletions

View File

@ -116,6 +116,7 @@ Otherwise, finish at eof..."""
if not self.sanityCheck(): if not self.sanityCheck():
print "Cowardly refusing to continue after failed sanity check" print "Cowardly refusing to continue after failed sanity check"
return return
if self.follow: if self.follow:
numHands = 0 numHands = 0
for handText in self.tailHands(): for handText in self.tailHands():
@ -129,6 +130,9 @@ Otherwise, finish at eof..."""
numHands= len(handsList) numHands= len(handsList)
endtime = time.time() endtime = time.time()
print "Processed %d hands in %.3f seconds" % (numHands, endtime - starttime) print "Processed %d hands in %.3f seconds" % (numHands, endtime - starttime)
if self.out_fh != sys.stdout:
self.out_fh.close()
def tailHands(self): def tailHands(self):
"""Generator of handTexts from a tailed file: """Generator of handTexts from a tailed file:

View File

@ -229,9 +229,7 @@ class Importer:
# Load filter, process file, pass returned filename to import_fpdb_file # Load filter, process file, pass returned filename to import_fpdb_file
# TODO: Shouldn't we be able to use some sort of lambda or something to just call a Python object by whatever name we specify? then we don't have to hardcode them, # TODO: Shouldn't we be able to use some sort of lambda or something to just call a Python object by whatever name we specify? then we don't have to hardcode them,
# someone can just create their own python module for it print "converting %s" % file
if filter in ("EverleafToFpdb","Everleaf"):
print "converting ", file
hhbase = self.config.get_import_parameters().get("hhArchiveBase") hhbase = self.config.get_import_parameters().get("hhArchiveBase")
hhbase = os.path.expanduser(hhbase) hhbase = os.path.expanduser(hhbase)
hhdir = os.path.join(hhbase,site) hhdir = os.path.join(hhbase,site)
@ -239,20 +237,16 @@ class Importer:
out_path = os.path.join(hhdir, file.split(os.path.sep)[-2]+"-"+os.path.basename(file)) out_path = os.path.join(hhdir, file.split(os.path.sep)[-2]+"-"+os.path.basename(file))
except: except:
out_path = os.path.join(hhdir, "x"+strftime("%d-%m-%y")+os.path.basename(file)) out_path = os.path.join(hhdir, "x"+strftime("%d-%m-%y")+os.path.basename(file))
#out_fh = open(ofile, 'w') # TODO: seek to previous place in input and append output
# someone can just create their own python module for it
if filter in ("EverleafToFpdb","Everleaf"):
conv = EverleafToFpdb.Everleaf(in_path = file, out_path = out_path) conv = EverleafToFpdb.Everleaf(in_path = file, out_path = out_path)
#~ conv.join()
elif filter == "FulltiltToFpdb": elif filter == "FulltiltToFpdb":
print "converting ", file conv = FulltiltToFpdb.FullTilt(in_path = file, out_path = out_path)
conv = FulltiltToFpdb.FullTilt(in_fh = file, out_fh = out_fh)
else: else:
print "Unknown filter ", filter print "Unknown filter ", filter
return return
supp = conv.readSupportedGames() # Should this be done by HHC on init?
#gt = conv.determineGameType()
# TODO: Check that gt is in supp - error appropriately if not
#conv.processFile()
if(conv.getStatus()): if(conv.getStatus()):
(stored, duplicates, partial, errors, ttime) = self.import_fpdb_file(out_path, site) (stored, duplicates, partial, errors, ttime) = self.import_fpdb_file(out_path, site)
else: else:
@ -280,7 +274,7 @@ class Importer:
loc = self.pos_in_file[file] loc = self.pos_in_file[file]
except: except:
pass pass
print "DEBUG: XXXXX in import_fpdb_file"
# 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())
@ -290,7 +284,7 @@ class Importer:
try: # sometimes we seem to be getting an empty self.lines, in which case, we just want to return. try: # sometimes we seem to be getting an empty self.lines, in which case, we just want to return.
firstline = self.lines[0] firstline = self.lines[0]
except: except:
# print "import_fpdb_file", file, site, self.lines, "\n" print "DEBUG: import_fpdb_file: failed on self.lines[0]: '%s' '%s' '%s' '%s' " %( file, site, self.lines, loc)
return (0,0,0,1,0) return (0,0,0,1,0)
if firstline.find("Tournament Summary")!=-1: if firstline.find("Tournament Summary")!=-1: