Merge branch 'master' of git://git.assembla.com/mctfpdb

Conflicts:

	pyfpdb/fpdb_import.py
This commit is contained in:
Worros 2009-03-12 22:57:43 +09:00
commit c523fce123
4 changed files with 12 additions and 17 deletions

View File

@ -50,6 +50,7 @@ debugging: if False, pass on partially supported game types. If true, have a go
self.debugging = debugging self.debugging = debugging
if autostart: if autostart:
self.start() self.start()
# otherwise you need to call start yourself.
def compilePlayerRegexs(self, hand): def compilePlayerRegexs(self, hand):
players = set([player[1] for player in hand.players]) players = set([player[1] for player in hand.players])

View File

@ -102,10 +102,6 @@ If a player has None chips he won't be added."""
else: else:
logging.error("markstreets didn't match") logging.error("markstreets didn't match")
#def addHoleCards -- to Holdem subclass
def checkPlayerExists(self,player): def checkPlayerExists(self,player):
if player not in [p[1] for p in self.players]: if player not in [p[1] for p in self.players]:
print "checkPlayerExists", player, "fail" print "checkPlayerExists", player, "fail"

View File

@ -18,7 +18,6 @@
import Hand import Hand
import re import re
import sys import sys
import threading
import traceback import traceback
import logging import logging
from optparse import OptionParser from optparse import OptionParser
@ -72,10 +71,9 @@ letter2names = {
import gettext import gettext
gettext.install('myapplication') gettext.install('myapplication')
class HandHistoryConverter(threading.Thread): class HandHistoryConverter():
READ_CHUNK_SIZE = 1000 # bytes to read at a time from file READ_CHUNK_SIZE = 1000 # bytes to read at a time from file
def __init__(self, in_path = '-', out_path = '-', sitename = None, follow=False): def __init__(self, in_path = '-', out_path = '-', sitename = None, follow=False):
threading.Thread.__init__(self)
logging.info("HandHistory init called") logging.info("HandHistory init called")
# default filetype and codepage. Subclasses should set these properly. # default filetype and codepage. Subclasses should set these properly.
@ -90,7 +88,7 @@ class HandHistoryConverter(threading.Thread):
else: else:
# TODO: out_path should be sanity checked before opening. Perhaps in fpdb_import? # 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!='-' # 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.sitename = sitename
self.follow = follow self.follow = follow
self.compiledPlayers = set() self.compiledPlayers = set()
@ -110,7 +108,7 @@ class HandHistoryConverter(threading.Thread):
#tmp = tmp + "\tsb/bb: '%s/%s'\n" % (self.gametype[3], self.gametype[4]) #tmp = tmp + "\tsb/bb: '%s/%s'\n" % (self.gametype[3], self.gametype[4])
return tmp return tmp
def run(self): def start(self):
"""process a hand at a time from the input specified by in_path. """process a hand at a time from the input specified by in_path.
If in follow mode, wait for more data to turn up. If in follow mode, wait for more data to turn up.
Otherwise, finish at eof...""" Otherwise, finish at eof..."""
@ -135,9 +133,9 @@ Otherwise, finish at eof..."""
def tailHands(self): def tailHands(self):
"""Generator of handTexts from a tailed file: """Generator of handTexts from a tailed file:
Tail the in_path file and yield handTexts separated by re_SplitHands""" 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 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 = '' data = ''
while 1: while 1:
where = fd.tell() where = fd.tell()
@ -145,15 +143,15 @@ Tail the in_path file and yield handTexts separated by re_SplitHands"""
if not newdata: if not newdata:
fd_results = os.fstat(fd.fileno()) fd_results = os.fstat(fd.fileno())
try: try:
st_results = os.stat(filename) st_results = os.stat(self.in_path)
except OSError: except OSError:
st_results = fd_results st_results = fd_results
if st_results[1] == fd_results[1]: if st_results[1] == fd_results[1]:
time.sleep(interval) time.sleep(interval)
fd.seek(where) fd.seek(where)
else: else:
print "%s changed inode numbers from %d to %d" % (filename, fd_results[1], st_results[1]) print "%s changed inode numbers from %d to %d" % (self.in_path, fd_results[1], st_results[1])
fd = open(filename, 'r') fd = codecs.open(self.in_path, 'r', self.codepage)
fd.seek(where) fd.seek(where)
else: else:
# yield hands # yield hands

View File

@ -241,7 +241,7 @@ class Importer:
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 #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 = EverleafToFpdb.Everleaf(in_path = file, out_path = out_path)
conv.join() #~ conv.join()
elif filter == "FulltiltToFpdb": elif filter == "FulltiltToFpdb":
print "converting ", file print "converting ", file
conv = FulltiltToFpdb.FullTilt(in_fh = file, out_fh = out_fh) conv = FulltiltToFpdb.FullTilt(in_fh = file, out_fh = out_fh)
@ -254,7 +254,7 @@ class Importer:
# TODO: Check that gt is in supp - error appropriately if not # TODO: Check that gt is in supp - error appropriately if not
#conv.processFile() #conv.processFile()
if(conv.getStatus()): 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: else:
# conversion didn't work # conversion didn't work
# TODO: appropriate response? # TODO: appropriate response?