From ff675fb3aea6282ba82eae564045e018996ac4a7 Mon Sep 17 00:00:00 2001 From: Matt Turnbull Date: Thu, 12 Mar 2009 03:15:34 +0000 Subject: [PATCH 1/3] import working? --- pyfpdb/Hand.py | 4 ---- pyfpdb/fpdb_import.py | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index f77b9425..9591525e 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -102,10 +102,6 @@ If a player has None chips he won't be added.""" else: logging.error("markstreets didn't match") -#def addHoleCards -- to Holdem subclass - - - def checkPlayerExists(self,player): if player not in [p[1] for p in self.players]: print "checkPlayerExists", player, "fail" diff --git a/pyfpdb/fpdb_import.py b/pyfpdb/fpdb_import.py index d86c4214..15c25ac8 100644 --- a/pyfpdb/fpdb_import.py +++ b/pyfpdb/fpdb_import.py @@ -252,9 +252,9 @@ class Importer: 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() + #conv.processFile() if(conv.getStatus()): - (stored, duplicates, partial, errors, ttime) = self.import_fpdb_file(conv.getProcessedFile(), site) + (stored, duplicates, partial, errors, ttime) = self.import_fpdb_file(out_path, site) else: # conversion didn't work # TODO: appropriate response? From cd3d4ef835d90fb4d0f517b3d48dd2309e38206a Mon Sep 17 00:00:00 2001 From: Matt Turnbull Date: Thu, 12 Mar 2009 03:58:42 +0000 Subject: [PATCH 2/3] no longer 'safely' appends -- will now overwrite out_path. --- pyfpdb/HandHistoryConverter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyfpdb/HandHistoryConverter.py b/pyfpdb/HandHistoryConverter.py index 7ed679a4..a627766e 100644 --- a/pyfpdb/HandHistoryConverter.py +++ b/pyfpdb/HandHistoryConverter.py @@ -90,7 +90,7 @@ class HandHistoryConverter(threading.Thread): else: # TODO: out_path should be sanity checked before opening. Perhaps in fpdb_import? # I'm not sure what we're looking for, although we don't want out_path==in_path!='-' - self.out_fh = open(self.out_path, 'a') #TODO: append may be overly conservative. + self.out_fh = open(self.out_path, 'w') # doomswitch is now on :| self.sitename = sitename self.follow = follow self.compiledPlayers = set() From 76e467a5d48cedb9a6298201fab1c2f412078f50 Mon Sep 17 00:00:00 2001 From: Matt Turnbull Date: Thu, 12 Mar 2009 12:24:23 +0000 Subject: [PATCH 3/3] get rid of thread --- pyfpdb/EverleafToFpdb.py | 1 + pyfpdb/HandHistoryConverter.py | 16 +++++++--------- pyfpdb/fpdb_import.py | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/pyfpdb/EverleafToFpdb.py b/pyfpdb/EverleafToFpdb.py index 18466edc..c0ebedfe 100755 --- a/pyfpdb/EverleafToFpdb.py +++ b/pyfpdb/EverleafToFpdb.py @@ -51,6 +51,7 @@ debugging: if False, pass on partially supported game types. If true, have a go self.debugging = debugging if autostart: self.start() + # otherwise you need to call start yourself. def compilePlayerRegexs(self, hand): players = set([player[1] for player in hand.players]) diff --git a/pyfpdb/HandHistoryConverter.py b/pyfpdb/HandHistoryConverter.py index a627766e..d9b8a1b5 100644 --- a/pyfpdb/HandHistoryConverter.py +++ b/pyfpdb/HandHistoryConverter.py @@ -18,7 +18,6 @@ import Hand import re import sys -import threading import traceback import logging from optparse import OptionParser @@ -72,10 +71,9 @@ letter2names = { import gettext gettext.install('myapplication') -class HandHistoryConverter(threading.Thread): +class HandHistoryConverter(): READ_CHUNK_SIZE = 1000 # bytes to read at a time from file def __init__(self, in_path = '-', out_path = '-', sitename = None, follow=False): - threading.Thread.__init__(self) logging.info("HandHistory init called") # default filetype and codepage. Subclasses should set these properly. @@ -110,7 +108,7 @@ class HandHistoryConverter(threading.Thread): #tmp = tmp + "\tsb/bb: '%s/%s'\n" % (self.gametype[3], self.gametype[4]) return tmp - def run(self): + def start(self): """process a hand at a time from the input specified by in_path. If in follow mode, wait for more data to turn up. Otherwise, finish at eof...""" @@ -135,9 +133,9 @@ Otherwise, finish at eof...""" def tailHands(self): """Generator of handTexts from a tailed file: Tail the in_path file and yield handTexts separated by re_SplitHands""" - if in_path == '-': raise StopIteration + if self.in_path == '-': raise StopIteration interval = 1.0 # seconds to sleep between reads for new data - fd = open(filename,'r') + fd = codecs.open(self.in_path,'r', self.codepage) data = '' while 1: where = fd.tell() @@ -145,15 +143,15 @@ Tail the in_path file and yield handTexts separated by re_SplitHands""" if not newdata: fd_results = os.fstat(fd.fileno()) try: - st_results = os.stat(filename) + st_results = os.stat(self.in_path) except OSError: st_results = fd_results if st_results[1] == fd_results[1]: time.sleep(interval) fd.seek(where) else: - print "%s changed inode numbers from %d to %d" % (filename, fd_results[1], st_results[1]) - fd = open(filename, 'r') + print "%s changed inode numbers from %d to %d" % (self.in_path, fd_results[1], st_results[1]) + fd = codecs.open(self.in_path, 'r', self.codepage) fd.seek(where) else: # yield hands diff --git a/pyfpdb/fpdb_import.py b/pyfpdb/fpdb_import.py index 15c25ac8..3f23d363 100644 --- a/pyfpdb/fpdb_import.py +++ b/pyfpdb/fpdb_import.py @@ -241,7 +241,7 @@ class Importer: 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 conv = EverleafToFpdb.Everleaf(in_path = file, out_path = out_path) - conv.join() + #~ conv.join() elif filter == "FulltiltToFpdb": print "converting ", file conv = FulltiltToFpdb.FullTilt(in_fh = file, out_fh = out_fh)