From 06b34e86487d6b6498c977f0e766f1345c86eb7e Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Tue, 31 Aug 2010 22:44:41 +0100 Subject: [PATCH] clarify difference between site and filter to allow 2 sites from same network, prompt to add site to db if missing --- pyfpdb/Hand.py | 3 +-- pyfpdb/HandHistoryConverter.py | 13 +++++++--- pyfpdb/OnGameToFpdb.py | 2 +- pyfpdb/fpdb.pyw | 45 ++++++++++++++++++++++++++++++++++ pyfpdb/fpdb_import.py | 5 ++-- 5 files changed, 60 insertions(+), 8 deletions(-) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index 7ae5f044..b56002c3 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -58,7 +58,6 @@ class Hand(object): LCS = {'H':'h', 'D':'d', 'C':'c', 'S':'s'} SYMBOL = {'USD': '$', 'EUR': u'$', 'T$': '', 'play': ''} MS = {'horse' : 'HORSE', '8game' : '8-Game', 'hose' : 'HOSE', 'ha': 'HA'} - SITEIDS = {'Fulltilt':1, 'PokerStars':2, 'Everleaf':3, 'Win2day':4, 'OnGame':5, 'UltimateBet':6, 'Betfair':7, 'Absolute':8, 'PartyPoker':9, 'Partouche':10, 'Carbon':11, 'PKR':12 } def __init__(self, config, sitename, gametype, handText, builtFrom = "HHC"): @@ -66,7 +65,7 @@ class Hand(object): self.config = config #log = Configuration.get_logger("logging.conf", "db", log_dir=self.config.dir_log) self.sitename = sitename - self.siteId = self.SITEIDS[sitename] + self.siteId = self.config.get_site_id(sitename) self.stats = DerivedStats.DerivedStats(self) self.gametype = gametype self.startTime = 0 diff --git a/pyfpdb/HandHistoryConverter.py b/pyfpdb/HandHistoryConverter.py index 860d05e1..6506afca 100644 --- a/pyfpdb/HandHistoryConverter.py +++ b/pyfpdb/HandHistoryConverter.py @@ -72,7 +72,9 @@ class HandHistoryConverter(): re_tzOffset = re.compile('^\w+[+-]\d{4}$') - def __init__(self, config, in_path = '-', out_path = '-', follow=False, index=0, autostart=True, starsArchive=False, ftpArchive=False): + # maybe archive params should be one archive param, then call method in specific converter. if archive: convert_archive() + def __init__( self, config, in_path = '-', out_path = '-', follow=False, index=0 + , autostart=True, starsArchive=False, ftpArchive=False, sitename="PokerStars" ): """\ in_path (default '-' = sys.stdin) out_path (default '-' = sys.stdout) @@ -80,8 +82,10 @@ follow : whether to tail -f the input""" self.config = config self.import_parameters = self.config.get_import_parameters() + self.sitename = sitename #log = Configuration.get_logger("logging.conf", "parser", log_dir=self.config.dir_log) - log.info("HandHistory init - %s subclass, in_path '%s'; out_path '%s'" % (self.sitename, in_path, out_path) ) + log.info("HandHistory init - %s site, %s subclass, in_path '%s'; out_path '%s'" + % (self.sitename, self.__class__, in_path, out_path) ) # should use self.filter, not self.sitename self.index = index self.starsArchive = starsArchive @@ -114,7 +118,7 @@ follow : whether to tail -f the input""" def __str__(self): return """ -HandHistoryConverter: '%(sitename)s' +HandHistoryConverter: '%(sitename)s' filetype '%(filetype)s' in_path '%(in_path)s' out_path '%(out_path)s' @@ -252,6 +256,9 @@ which it expects to find at self.re_TailSplitHands -- see for e.g. Everleaf.py. self.readFile() self.obs = self.obs.strip() self.obs = self.obs.replace('\r\n', '\n') + # maybe archive params should be one archive param, then call method in specific converter? + # if self.archive: + # self.obs = self.convert_archive(self.obs) if self.starsArchive == True: log.debug(_("Converting starsArchive format to readable")) m = re.compile('^Hand #\d+', re.MULTILINE) diff --git a/pyfpdb/OnGameToFpdb.py b/pyfpdb/OnGameToFpdb.py index 8ba8f9b4..d54972ac 100755 --- a/pyfpdb/OnGameToFpdb.py +++ b/pyfpdb/OnGameToFpdb.py @@ -45,7 +45,7 @@ else: # OnGame HH Format class OnGame(HandHistoryConverter): - sitename = "OnGame" + filter = "OnGame" filetype = "text" codepage = ("utf8", "cp1252") siteId = 5 # Needs to match id entry in Sites database diff --git a/pyfpdb/fpdb.pyw b/pyfpdb/fpdb.pyw index adeb34c7..b067073a 100755 --- a/pyfpdb/fpdb.pyw +++ b/pyfpdb/fpdb.pyw @@ -1232,6 +1232,7 @@ You can find the full license texts in agpl-3.0.txt, gpl-2.0.txt, gpl-3.0.txt an return response def validate_config(self): + # can this be removed now? if self.config.get_import_parameters().get('saveStarsHH'): hhbase = self.config.get_import_parameters().get("hhArchiveBase") hhbase = os.path.expanduser(hhbase) @@ -1251,6 +1252,50 @@ You can find the full license texts in agpl-3.0.txt, gpl-2.0.txt, gpl-3.0.txt an elif response == gtk.RESPONSE_NO: self.select_hhArchiveBase() + # check if sites in config file are in DB + for site in self.config.get_supported_sites(True): # get site names from config file + try: + self.config.get_site_id(site) # and check against list from db + except KeyError as exc: + log.warning("site %s missing from db" % site) + dia = gtk.MessageDialog(parent=None, flags=0, type=gtk.MESSAGE_WARNING, buttons=(gtk.BUTTONS_YES_NO), message_format="Unknown Site") + diastring = _("WARNING: Unable to find site '%s'\n\nPress YES to add this site to the database.") % site + dia.format_secondary_text(diastring) + response = dia.run() + dia.destroy() + if response == gtk.RESPONSE_YES: + self.add_site(site) + + def add_site(self, site): + dia = gtk.Dialog( title="Add Site", parent=self.window + , flags=gtk.DIALOG_DESTROY_WITH_PARENT + , buttons=(gtk.STOCK_SAVE, gtk.RESPONSE_ACCEPT + ,gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT) + ) + + h = gtk.HBox() + dia.vbox.pack_start(h, padding=5) # sets horizontal padding + label = gtk.Label( _("\nEnter short code for %s\n(up to 3 characters):\n") % site ) + h.pack_start(label, padding=20) # sets horizontal padding + #label.set_alignment(1.0, 0.5) + + h = gtk.HBox() + dia.vbox.add(h) + e_code = gtk.Entry(max=3) + e_code.set_width_chars(5) + h.pack_start(e_code, True, False, padding=5) + + label = gtk.Label( "" ) + dia.vbox.add(label) # create space below entry, maybe padding arg above makes this redundant? + + dia.show_all() + response = dia.run() + site_code = e_code.get_text() + if response == gtk.RESPONSE_ACCEPT and site_code is not None and site_code != "": + self.db.add_site(site, site_code) + self.db.commit() + dia.destroy() + def main(self): gtk.main() return 0 diff --git a/pyfpdb/fpdb_import.py b/pyfpdb/fpdb_import.py index 8ff2ba86..5fcbd1b0 100755 --- a/pyfpdb/fpdb_import.py +++ b/pyfpdb/fpdb_import.py @@ -384,7 +384,7 @@ class Importer: #rulog.writelines("path exists ") if file in self.updatedsize: # we should be able to assume that if we're in size, we're in time as well if stat_info.st_size > self.updatedsize[file] or stat_info.st_mtime > self.updatedtime[file]: -# print "file",counter," updated", os.path.basename(file), stat_info.st_size, self.updatedsize[file], stat_info.st_mtime, self.updatedtime[file] +# print "file",file," updated", os.path.basename(file), stat_info.st_size, self.updatedsize[file], stat_info.st_mtime, self.updatedtime[file] try: if not os.path.isdir(file): self.caller.addText("\n"+os.path.basename(file)) @@ -457,7 +457,8 @@ class Importer: idx = self.pos_in_file[file] else: self.pos_in_file[file] = 0 - hhc = obj(self.config, in_path = file, out_path = out_path, index = idx, starsArchive = self.settings['starsArchive']) + hhc = obj( self.config, in_path = file, out_path = out_path, index = idx + , starsArchive = self.settings['starsArchive'], sitename = site ) if hhc.getStatus(): handlist = hhc.getProcessedHands() self.pos_in_file[file] = hhc.getLastCharacterRead()