clarify difference between site and filter to allow 2 sites from same network, prompt to add site to db if missing

This commit is contained in:
sqlcoder 2010-08-31 22:44:41 +01:00
parent 9704cd7fe5
commit 06b34e8648
5 changed files with 60 additions and 8 deletions

View File

@ -58,7 +58,6 @@ class Hand(object):
LCS = {'H':'h', 'D':'d', 'C':'c', 'S':'s'} LCS = {'H':'h', 'D':'d', 'C':'c', 'S':'s'}
SYMBOL = {'USD': '$', 'EUR': u'$', 'T$': '', 'play': ''} SYMBOL = {'USD': '$', 'EUR': u'$', 'T$': '', 'play': ''}
MS = {'horse' : 'HORSE', '8game' : '8-Game', 'hose' : 'HOSE', 'ha': 'HA'} 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"): def __init__(self, config, sitename, gametype, handText, builtFrom = "HHC"):
@ -66,7 +65,7 @@ class Hand(object):
self.config = config self.config = config
#log = Configuration.get_logger("logging.conf", "db", log_dir=self.config.dir_log) #log = Configuration.get_logger("logging.conf", "db", log_dir=self.config.dir_log)
self.sitename = sitename self.sitename = sitename
self.siteId = self.SITEIDS[sitename] self.siteId = self.config.get_site_id(sitename)
self.stats = DerivedStats.DerivedStats(self) self.stats = DerivedStats.DerivedStats(self)
self.gametype = gametype self.gametype = gametype
self.startTime = 0 self.startTime = 0

View File

@ -72,7 +72,9 @@ class HandHistoryConverter():
re_tzOffset = re.compile('^\w+[+-]\d{4}$') 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) in_path (default '-' = sys.stdin)
out_path (default '-' = sys.stdout) out_path (default '-' = sys.stdout)
@ -80,8 +82,10 @@ follow : whether to tail -f the input"""
self.config = config self.config = config
self.import_parameters = self.config.get_import_parameters() 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 = 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.index = index
self.starsArchive = starsArchive self.starsArchive = starsArchive
@ -114,7 +118,7 @@ follow : whether to tail -f the input"""
def __str__(self): def __str__(self):
return """ return """
HandHistoryConverter: '%(sitename)s' HandHistoryConverter: '%(sitename)s'
filetype '%(filetype)s' filetype '%(filetype)s'
in_path '%(in_path)s' in_path '%(in_path)s'
out_path '%(out_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.readFile()
self.obs = self.obs.strip() self.obs = self.obs.strip()
self.obs = self.obs.replace('\r\n', '\n') 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: if self.starsArchive == True:
log.debug(_("Converting starsArchive format to readable")) log.debug(_("Converting starsArchive format to readable"))
m = re.compile('^Hand #\d+', re.MULTILINE) m = re.compile('^Hand #\d+', re.MULTILINE)

View File

@ -45,7 +45,7 @@ else:
# OnGame HH Format # OnGame HH Format
class OnGame(HandHistoryConverter): class OnGame(HandHistoryConverter):
sitename = "OnGame" filter = "OnGame"
filetype = "text" filetype = "text"
codepage = ("utf8", "cp1252") codepage = ("utf8", "cp1252")
siteId = 5 # Needs to match id entry in Sites database siteId = 5 # Needs to match id entry in Sites database

View File

@ -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 return response
def validate_config(self): def validate_config(self):
# can this be removed now?
if self.config.get_import_parameters().get('saveStarsHH'): if self.config.get_import_parameters().get('saveStarsHH'):
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)
@ -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: elif response == gtk.RESPONSE_NO:
self.select_hhArchiveBase() 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): def main(self):
gtk.main() gtk.main()
return 0 return 0

View File

@ -384,7 +384,7 @@ class Importer:
#rulog.writelines("path exists ") #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 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]: 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: try:
if not os.path.isdir(file): if not os.path.isdir(file):
self.caller.addText("\n"+os.path.basename(file)) self.caller.addText("\n"+os.path.basename(file))
@ -457,7 +457,8 @@ class Importer:
idx = self.pos_in_file[file] idx = self.pos_in_file[file]
else: else:
self.pos_in_file[file] = 0 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(): if hhc.getStatus():
handlist = hhc.getProcessedHands() handlist = hhc.getProcessedHands()
self.pos_in_file[file] = hhc.getLastCharacterRead() self.pos_in_file[file] = hhc.getLastCharacterRead()