diff --git a/.gitignore b/.gitignore deleted file mode 100644 index f3d74a9a..00000000 --- a/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*.pyc -*~ diff --git a/pyfpdb/AbsoluteToFpdb.py b/pyfpdb/AbsoluteToFpdb.py index 503c1f4e..e8ac53ff 100644 --- a/pyfpdb/AbsoluteToFpdb.py +++ b/pyfpdb/AbsoluteToFpdb.py @@ -26,6 +26,12 @@ from HandHistoryConverter import * # Class for converting Absolute HH format. class Absolute(HandHistoryConverter): + + # Class Variables + sitename = "Absolute" + filetype = "text" + codepage = "cp1252" + siteid = 8 # Static regexes re_SplitHands = re.compile(r"\n\n\n+") @@ -48,24 +54,6 @@ class Absolute(HandHistoryConverter): # re_Board = re.compile(ur"\[ (?P.+) \]") - def __init__(self, in_path = '-', out_path = '-', follow = False, autostart=True, debugging=False, index=0): - """\ -in_path (default '-' = sys.stdin) -out_path (default '-' = sys.stdout) -follow : whether to tail -f the input -autostart: whether to run the thread (or you can call start() yourself) -debugging: if False, pass on partially supported game types. If true, have a go and error...""" - #print "DEBUG: XXXXXXXXXXXXXXX" - HandHistoryConverter.__init__(self, in_path, out_path, sitename="Absolute", follow=follow, index=index) - logging.info("Initialising Absolute converter class") - self.filetype = "text" - self.codepage = "cp1252" - self.siteId = 8 # Needs to match id entry in Sites database - 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]) if not players <= self.compiledPlayers: # x <= y means 'x is subset of y' diff --git a/pyfpdb/BetfairToFpdb.py b/pyfpdb/BetfairToFpdb.py index 1ccec5d0..59344991 100755 --- a/pyfpdb/BetfairToFpdb.py +++ b/pyfpdb/BetfairToFpdb.py @@ -26,6 +26,11 @@ from HandHistoryConverter import * class Betfair(HandHistoryConverter): + sitename = 'Betfair' + filetype = "text" + codepage = "cp1252" + siteId = 7 # Needs to match id entry in Sites database + # Static regexes re_GameInfo = re.compile("^(?PNL|PL|) (?P\$|)?(?P[.0-9]+)/\$?(?P[.0-9]+) (?P(Texas Hold\'em|Omaha Hi|Razz))", re.MULTILINE) re_SplitHands = re.compile(r'\n\n+') @@ -34,19 +39,6 @@ class Betfair(HandHistoryConverter): re_PlayerInfo = re.compile("Seat (?P[0-9]+): (?P.*)\s\(\s(\$(?P[.0-9]+)) \)") re_Board = re.compile(ur"\[ (?P.+) \]") - def __init__(self, in_path = '-', out_path = '-', follow = False, autostart=True, index=0): - """\ -in_path (default '-' = sys.stdin) -out_path (default '-' = sys.stdout) -follow : whether to tail -f the input""" - HandHistoryConverter.__init__(self, in_path, out_path, sitename="Betfair", follow=follow, index) # Call super class init. - logging.info("Initialising Betfair converter class") - self.filetype = "text" - self.codepage = "cp1252" - self.siteId = 7 # Needs to match id entry in Sites database - if autostart: - self.start() - def compilePlayerRegexs(self, hand): players = set([player[1] for player in hand.players]) diff --git a/pyfpdb/Configuration.py b/pyfpdb/Configuration.py index 2d59e8f1..f0277bca 100755 --- a/pyfpdb/Configuration.py +++ b/pyfpdb/Configuration.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +# -*- coding: utf-8 -*- """Configuration.py Handles HUD configuration files. @@ -73,11 +74,17 @@ class Layout: class Site: def __init__(self, node): + def normalizePath(path): + "Normalized existing pathes" + if os.path.exists(path): + return os.path.abspath(path) + return path + self.site_name = node.getAttribute("site_name") self.table_finder = node.getAttribute("table_finder") self.screen_name = node.getAttribute("screen_name") - self.site_path = node.getAttribute("site_path") - self.HH_path = node.getAttribute("HH_path") + self.site_path = normalizePath(node.getAttribute("site_path")) + self.HH_path = normalizePath(node.getAttribute("HH_path")) self.decoder = node.getAttribute("decoder") self.hudopacity = node.getAttribute("hudopacity") self.hudbgcolor = node.getAttribute("bgcolor") @@ -91,6 +98,8 @@ class Site: self.xpad = node.getAttribute("xpad") self.ypad = node.getAttribute("ypad") self.layout = {} + + print self.site_name, self.HH_path for layout_node in node.getElementsByTagName('layout'): lo = Layout(layout_node) @@ -542,6 +551,13 @@ class Config: if db_server != None: self.supported_databases[db_name].dp_server = db_server if db_type != None: self.supported_databases[db_name].dp_type = db_type return + + def getDefaultSite(self): + "Returns first enabled site or None" + for site_name,site in self.supported_sites.iteritems(): + if site.enabled: + return site_name + return None def get_tv_parameters(self): tv = {} @@ -573,14 +589,15 @@ class Config: except: imp['fastStoreHudCache'] = True return imp - def get_default_paths(self, site = "PokerStars"): + def get_default_paths(self, site = None): + if site is None: site = self.getDefaultSite() paths = {} try: - paths['hud-defaultPath'] = os.path.expanduser(self.supported_sites[site].HH_path) - paths['bulkImport-defaultPath'] = os.path.expanduser(self.supported_sites[site].HH_path) + path = os.path.expanduser(self.supported_sites[site].HH_path) + assert(os.path.isdir(path) or os.path.isfile(path)) # maybe it should try another site? + paths['hud-defaultPath'] = paths['bulkImport-defaultPath'] = path except: - paths['hud-defaultPath'] = "default" - paths['bulkImport-defaultPath'] = "default" + paths['hud-defaultPath'] = paths['bulkImport-defaultPath'] = "default" return paths def get_frames(self, site = "PokerStars"): diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index d59c879c..060c8dd7 100755 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -28,6 +28,7 @@ import sys import traceback from datetime import datetime, date, time, timedelta from time import time, strftime, sleep +from decimal import Decimal import string import re import logging @@ -1020,6 +1021,22 @@ class Database: print "Error during fdb.lock_for_insert:", str(sys.exc_value) #end def lock_for_insert + def getGameTypeId(self, siteid, game): + c = self.get_cursor() + #FIXME: Fixed for NL at the moment + c.execute(self.sql.query['getGametypeNL'], (siteid, game['type'], game['category'], game['limitType'], + int(Decimal(game['sb'])*100), int(Decimal(game['bb'])*100))) + tmp = c.fetchone() + if (tmp == None): + hilo = "h" + if game['category'] in ['studhilo', 'omahahilo']: + hilo = "s" + elif game['category'] in ['razz','27_3draw','badugi']: + hilo = "l" + tmp = self.insertGameTypes( (siteid, game['type'], game['base'], game['category'], game['limitType'], hilo, + int(Decimal(game['sb'])*100), int(Decimal(game['bb'])*100), 0, 0) ) + return tmp[0] + def getSqlPlayerIDs(self, pnames, siteid): result = {} if(self.pcache == None): @@ -1127,15 +1144,22 @@ class Database: sitehandno, handstart, importtime, + seats, maxseats, boardcard1, boardcard2, boardcard3, boardcard4, - boardcard5 + boardcard5, + street1Pot, + street2Pot, + street3Pot, + street4Pot, + showdownPot ) VALUES - (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)""" + (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, + %s, %s, %s, %s, %s, %s, %s)""" #--- texture, #-- playersVpi, #-- playersAtStreet1, @@ -1148,27 +1172,25 @@ class Database: #-- street2Raises, #-- street3Raises, #-- street4Raises, -#-- street1Pot, -#-- street2Pot, -#-- street3Pot, -#-- street4Pot, -#-- showdownPot #-- seats, q = q.replace('%s', self.sql.query['placeholder']) + print "DEBUG: p: %s" %p + print "DEBUG: gtid: %s" % p['gameTypeId'] self.cursor.execute(q, ( p['tableName'], + p['gameTypeId'], p['siteHandNo'], - p['gametypeid'], p['handStart'], datetime.today(), #importtime # len(p['names']), #seats p['maxSeats'], + p['seats'], p['boardcard1'], p['boardcard2'], p['boardcard3'], p['boardcard4'], - p['boardcard5']) + p['boardcard5'], # hudCache['playersVpi'], # hudCache['playersAtStreet1'], # hudCache['playersAtStreet2'], @@ -1180,12 +1202,12 @@ class Database: # hudCache['street2Raises'], # hudCache['street3Raises'], # hudCache['street4Raises'], -# hudCache['street1Pot'], -# hudCache['street2Pot'], -# hudCache['street3Pot'], -# hudCache['street4Pot'], -# hudCache['showdownPot'] - ) + p['street1Pot'], + p['street2Pot'], + p['street3Pot'], + p['street4Pot'], + p['showdownPot'] + )) #return getLastInsertId(backend, conn, cursor) # def storeHand diff --git a/pyfpdb/EverleafToFpdb.py b/pyfpdb/EverleafToFpdb.py index 9c63bcf0..2835b6ff 100755 --- a/pyfpdb/EverleafToFpdb.py +++ b/pyfpdb/EverleafToFpdb.py @@ -26,6 +26,11 @@ from HandHistoryConverter import * class Everleaf(HandHistoryConverter): + sitename = 'Everleaf' + filetype = "text" + codepage = "cp1252" + siteId = 3 # Needs to match id entry in Sites database + # Static regexes re_SplitHands = re.compile(r"\n\n\n+") re_TailSplitHands = re.compile(r"(\n\n\n+)") @@ -37,24 +42,6 @@ class Everleaf(HandHistoryConverter): re_Board = re.compile(ur"\[ (?P.+) \]") - def __init__(self, in_path = '-', out_path = '-', follow = False, autostart=True, debugging=False, index=0): - """\ -in_path (default '-' = sys.stdin) -out_path (default '-' = sys.stdout) -follow : whether to tail -f the input -autostart: whether to run the thread (or you can call start() yourself) -debugging: if False, pass on partially supported game types. If true, have a go and error...""" - #print "DEBUG: XXXXXXXXXXXXXXX" - HandHistoryConverter.__init__(self, in_path, out_path, sitename="Everleaf", follow=follow, index=index) - logging.info("Initialising Everleaf converter class") - self.filetype = "text" - self.codepage = "cp1252" - self.siteId = 3 # Needs to match id entry in Sites database - 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]) if not players <= self.compiledPlayers: # x <= y means 'x is subset of y' diff --git a/pyfpdb/Exceptions.py b/pyfpdb/Exceptions.py index fa76f3cd..8259a484 100644 --- a/pyfpdb/Exceptions.py +++ b/pyfpdb/Exceptions.py @@ -1 +1,4 @@ -class FpdbParseError(Exception): pass +class FpdbParseError(Exception): + def __init__(self,hid=None): + self.hid = hid + diff --git a/pyfpdb/FulltiltToFpdb.py b/pyfpdb/FulltiltToFpdb.py index a68c1cbd..e476dc30 100755 --- a/pyfpdb/FulltiltToFpdb.py +++ b/pyfpdb/FulltiltToFpdb.py @@ -27,8 +27,14 @@ from HandHistoryConverter import * class Fulltilt(HandHistoryConverter): + sitename = "Fulltilt" + filetype = "text" + codepage = "cp1252" + siteId = 1 # Needs to match id entry in Sites database + # Static regexes - re_GameInfo = re.compile('''(?:(?P.+)\s\((?P\d+)\),\s)? + re_GameInfo = re.compile('''.*\#(?P[0-9]+):\s + (?:(?P.+)\s\((?P\d+)\),\s)? .+ -\s(?P\$|)? (?P[.0-9]+)/ @@ -39,7 +45,7 @@ class Fulltilt(HandHistoryConverter): ''', re.VERBOSE) re_SplitHands = re.compile(r"\n\n+") re_TailSplitHands = re.compile(r"(\n\n+)") - re_HandInfo = re.compile('''.*\#(?P[0-9]+):\s + re_HandInfo = re.compile(r'''.*\#(?P[0-9]+):\s (?:(?P.+)\s\((?P\d+)\),\s)? Table\s (?PPlay\sChip\s|PC)? @@ -47,8 +53,9 @@ class Fulltilt(HandHistoryConverter): (\((?P.+)\)\s)?-\s \$?(?P[.0-9]+)/\$?(?P[.0-9]+)\s(Ante\s\$?(?P[.0-9]+)\s)?-\s (?P[a-zA-Z\/\'\s]+)\s-\s - (?P.*) - ''', re.VERBOSE) + (?P.*?)\n + (?:.*?\n(?PHand\s\#(?P=HID)\shas\sbeen\scanceled))? + ''', re.VERBOSE|re.DOTALL) re_Button = re.compile('^The button is in seat #(?P