Merge branch 'master' of git://git.assembla.com/fpdb-sql

This commit is contained in:
Worros 2010-09-01 11:08:04 +08:00
commit 7aeb5e4531
7 changed files with 78 additions and 9 deletions

View File

@ -697,10 +697,11 @@ class Config:
self.aux_windows = {}
self.hhcs = {}
self.popup_windows = {}
self.db_selected = None # database the user would like to use
self.db_selected = None # database the user would like to use
self.general = General()
self.emails = {}
self.gui_cash_stats = GUICashStats()
self.site_ids = {} # site ID list from the database
added,n = 1,0 # use n to prevent infinite loop if add_missing_elements() fails somehow
while added > 0 and n < 2:
@ -1390,6 +1391,12 @@ class Config:
if font_size is not None: site_node.setAttribute("font_size", font_size)
return
def set_site_ids(self, sites):
self.site_ids = dict(sites)
def get_site_id(self, site):
return( self.site_ids[site] )
def get_aux_windows(self):
"""Gets the list of mucked window formats in the configuration."""
return self.aux_windows.keys()

View File

@ -302,6 +302,7 @@ class Database:
self.saveActions = False if self.import_options['saveActions'] == False else True
if self.is_connected():
self.get_sites()
self.connection.rollback() # make sure any locks taken so far are released
#end def __init__
@ -466,6 +467,15 @@ class Database:
self.cursor.execute(self.sql.query['set tx level'])
self.check_version(database=database, create=create)
def get_sites(self):
self.cursor.execute("SELECT name,id FROM Sites")
sites = self.cursor.fetchall()
self.config.set_site_ids(sites)
def add_site(self, site, site_code):
self.cursor.execute("INSERT INTO Sites "
"SELECT max(id)+1, '%s', '%s' "
"FROM Sites " % (site, site_code) )
def check_version(self, database, create):
self.wrongDbVersion = False

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -1214,6 +1214,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)
@ -1233,6 +1234,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

View File

@ -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()