Merge branch 'sqlcoder'

This commit is contained in:
steffen123 2010-07-14 18:52:33 +02:00
commit 79043988c2
6 changed files with 67 additions and 44 deletions

View File

@ -521,6 +521,7 @@ class Database:
self.connection.commit() self.connection.commit()
self.cursor.close() self.cursor.close()
self.connection.close() self.connection.close()
self.__connected = False
def reconnect(self, due_to_error=False): def reconnect(self, due_to_error=False):
"""Reconnects the DB""" """Reconnects the DB"""

View File

@ -101,7 +101,7 @@ class GuiAutoImport (threading.Thread):
hbox.pack_start(lbl1, expand=True, fill=False) hbox.pack_start(lbl1, expand=True, fill=False)
self.doAutoImportBool = False self.doAutoImportBool = False
self.startButton = gtk.ToggleButton(" _Start Autoimport ") self.startButton = gtk.ToggleButton(" Start Autoimpor_t ")
self.startButton.connect("clicked", self.startClicked, "start clicked") self.startButton.connect("clicked", self.startClicked, "start clicked")
hbox.pack_start(self.startButton, expand=False, fill=False) hbox.pack_start(self.startButton, expand=False, fill=False)
@ -156,7 +156,7 @@ class GuiAutoImport (threading.Thread):
def do_import(self): def do_import(self):
"""Callback for timer to do an import iteration.""" """Callback for timer to do an import iteration."""
if self.doAutoImportBool: if self.doAutoImportBool:
self.startButton.set_label(u' I M P O R T I N G ') self.startButton.set_label(u' I M P O R _T I N G ')
self.importer.runUpdated() self.importer.runUpdated()
self.addText(".") self.addText(".")
#sys.stdout.write(".") #sys.stdout.write(".")
@ -167,9 +167,9 @@ class GuiAutoImport (threading.Thread):
def reset_startbutton(self): def reset_startbutton(self):
if self.pipe_to_hud is not None: if self.pipe_to_hud is not None:
self.startButton.set_label(u' _Stop Autoimport ') self.startButton.set_label(u' Stop Autoimpor_t ')
else: else:
self.startButton.set_label(u' _Start Autoimport ') self.startButton.set_label(u' Start Autoimpor_t ')
return False return False
@ -246,7 +246,7 @@ class GuiAutoImport (threading.Thread):
#print >>self.pipe_to_hud.stdin, "\n" #print >>self.pipe_to_hud.stdin, "\n"
self.pipe_to_hud.communicate('\n') # waits for process to terminate self.pipe_to_hud.communicate('\n') # waits for process to terminate
self.pipe_to_hud = None self.pipe_to_hud = None
self.startButton.set_label(u' _Start Autoimport ') self.startButton.set_label(u' Start Autoimpor_t ')
#end def GuiAutoImport.startClicked #end def GuiAutoImport.startClicked

View File

@ -66,6 +66,7 @@ class RingFilters(Filters.Filters):
# Outer Packing box # Outer Packing box
self.mainVBox = gtk.VBox(False, 0) self.mainVBox = gtk.VBox(False, 0)
self.found = {'nl':False, 'fl':False, 'pl':False, 'ring':False, 'tour':False}
self.label = {} self.label = {}
self.callback = {} self.callback = {}
@ -364,7 +365,7 @@ class RingFilters(Filters.Filters):
#end def __set_game_select #end def __set_game_select
def __set_limit_select(self, w, limit): def __set_limit_select(self, w, limit):
#print w.get_active() #print "__set_limit_select: limit =", limit, w.get_active()
self.limits[limit] = w.get_active() self.limits[limit] = w.get_active()
log.debug("self.limit[%s] set to %s" %(limit, self.limits[limit])) log.debug("self.limit[%s] set to %s" %(limit, self.limits[limit]))
if limit.isdigit() or (len(limit) > 2 and (limit[-2:] == 'nl' or limit[-2:] == 'fl' or limit[-2:] == 'pl')): if limit.isdigit() or (len(limit) > 2 and (limit[-2:] == 'nl' or limit[-2:] == 'fl' or limit[-2:] == 'pl')):
@ -627,7 +628,7 @@ class RingFilters(Filters.Filters):
self.cursor.execute(self.sql.query['getCashLimits']) self.cursor.execute(self.sql.query['getCashLimits'])
# selects limitType, bigBlind # selects limitType, bigBlind
result = self.db.cursor.fetchall() result = self.db.cursor.fetchall()
found = {'nl':False, 'fl':False, 'pl':False, 'ring':False, 'tour':False} self.found = {'nl':False, 'fl':False, 'pl':False, 'ring':False, 'tour':False}
if len(result) >= 1: if len(result) >= 1:
hbox = gtk.HBox(True, 0) hbox = gtk.HBox(True, 0)
@ -648,16 +649,16 @@ class RingFilters(Filters.Filters):
if True: #line[0] == 'ring': if True: #line[0] == 'ring':
if line[1] == 'fl': if line[1] == 'fl':
name = str(line[2]) name = str(line[2])
found['fl'] = True self.found['fl'] = True
elif line[1] == 'pl': elif line[1] == 'pl':
name = str(line[2])+line[1] name = str(line[2])+line[1]
found['pl'] = True self.found['pl'] = True
else: else:
name = str(line[2])+line[1] name = str(line[2])+line[1]
found['nl'] = True self.found['nl'] = True
self.cbLimits[name] = self.createLimitLine(hbox, name, name) self.cbLimits[name] = self.createLimitLine(hbox, name, name)
self.types[name] = line[0] self.types[name] = line[0]
found[line[0]] = True # type is ring/tour self.found[line[0]] = True # type is ring/tour
self.type = line[0] # if only one type, set it now self.type = line[0] # if only one type, set it now
if "LimitSep" in display and display["LimitSep"] == True and len(result) >= 2: if "LimitSep" in display and display["LimitSep"] == True and len(result) >= 2:
hbox = gtk.HBox(True, 0) hbox = gtk.HBox(True, 0)
@ -675,15 +676,21 @@ class RingFilters(Filters.Filters):
self.cbNoLimits = self.createLimitLine(hbox, 'none', self.filterText['limitsnone']) self.cbNoLimits = self.createLimitLine(hbox, 'none', self.filterText['limitsnone'])
dest = vbox3 # for ring/tour buttons dest = vbox3 # for ring/tour buttons
if "LimitType" in display and display["LimitType"] == True and found['nl'] and found['fl']: if "LimitType" in display and display["LimitType"] == True:
#if found['fl']: num_limit_types = 0
if self.found['fl']: num_limit_types = num_limit_types + 1
if self.found['pl']: num_limit_types = num_limit_types + 1
if self.found['nl']: num_limit_types = num_limit_types + 1
if num_limit_types > 1:
if self.found['fl']:
hbox = gtk.HBox(False, 0) hbox = gtk.HBox(False, 0)
vbox3.pack_start(hbox, False, False, 0) vbox3.pack_start(hbox, False, False, 0)
self.cbFL = self.createLimitLine(hbox, 'fl', self.filterText['limitsFL']) self.cbFL = self.createLimitLine(hbox, 'fl', self.filterText['limitsFL'])
#if found['nl']: if self.found['nl']:
hbox = gtk.HBox(False, 0) hbox = gtk.HBox(False, 0)
vbox3.pack_start(hbox, False, False, 0) vbox3.pack_start(hbox, False, False, 0)
self.cbNL = self.createLimitLine(hbox, 'nl', self.filterText['limitsNL']) self.cbNL = self.createLimitLine(hbox, 'nl', self.filterText['limitsNL'])
if self.found['pl']:
hbox = gtk.HBox(False, 0) hbox = gtk.HBox(False, 0)
vbox3.pack_start(hbox, False, False, 0) vbox3.pack_start(hbox, False, False, 0)
self.cbPL = self.createLimitLine(hbox, 'pl', self.filterText['limitsPL']) self.cbPL = self.createLimitLine(hbox, 'pl', self.filterText['limitsPL'])
@ -692,7 +699,7 @@ class RingFilters(Filters.Filters):
print "INFO: No games returned from database" print "INFO: No games returned from database"
log.info("No games returned from database") log.info("No games returned from database")
if "Type" in display and display["Type"] == True and found['ring'] and found['tour']: if "Type" in display and display["Type"] == True and self.found['ring'] and self.found['tour']:
rb1 = gtk.RadioButton(None, self.filterText['ring']) rb1 = gtk.RadioButton(None, self.filterText['ring'])
rb1.connect('clicked', self.__set_limit_select, 'ring') rb1.connect('clicked', self.__set_limit_select, 'ring')
rb2 = gtk.RadioButton(rb1, self.filterText['tour']) rb2 = gtk.RadioButton(rb1, self.filterText['tour'])

View File

@ -2834,7 +2834,7 @@ class Sql:
AND h.startTime < '<enddate_test>' AND h.startTime < '<enddate_test>'
<limit_test> <limit_test>
<game_test> <game_test>
AND gt.type is 'ring' AND gt.type = 'ring'
GROUP BY h.startTime, hp.handId, hp.sawShowdown, hp.totalProfit GROUP BY h.startTime, hp.handId, hp.sawShowdown, hp.totalProfit
ORDER BY h.startTime""" ORDER BY h.startTime"""

View File

@ -66,6 +66,7 @@ cl_options = string.join(sys.argv[1:])
(options, argv) = Options.fpdb_options() (options, argv) = Options.fpdb_options()
import logging, logging.config import logging, logging.config
log = logging.getLogger("fpdb")
try: try:
import pygtk import pygtk
@ -415,12 +416,18 @@ class fpdb:
# TODO: figure out why this seems to be necessary # TODO: figure out why this seems to be necessary
dia_restart = gtk.MessageDialog(parent=self.window, flags=0, type=gtk.MESSAGE_WARNING, dia_restart = gtk.MessageDialog(parent=self.window, flags=0, type=gtk.MESSAGE_WARNING,
buttons=(gtk.BUTTONS_OK), message_format="Restart fpdb") buttons=(gtk.BUTTONS_OK), message_format="Restart fpdb")
diastring = "Fpdb now needs to close. Please restart it."
dia_restart.format_secondary_text(diastring)
dia_restart.run() # sc: I don't see the need for this closedown - if it is a problem let me know
dia_restart.destroy() # and I will look into it .... (if there is a problem with db re-create I
self.quit(None, None) # would expect it to be before here, i.e. maybe user needs to restart before
# the re-create. Once here everything should be ok.)
# The recreate will not work if autoimport is running! Other than that it
# should work.
#diastring = "Fpdb now needs to close. Please restart it."
#dia_restart.format_secondary_text(diastring)
#dia_restart.run()
#dia_restart.destroy()
#self.quit(None, None)
elif response == gtk.RESPONSE_NO: elif response == gtk.RESPONSE_NO:
self.release_global_lock() self.release_global_lock()
print 'User cancelled recreating tables' print 'User cancelled recreating tables'
@ -842,18 +849,21 @@ class fpdb:
def quit(self, widget, data=None): def quit(self, widget, data=None):
# TODO: can we get some / all of the stuff done in this function to execute on any kind of abort? # TODO: can we get some / all of the stuff done in this function to execute on any kind of abort?
#FIXME get two "quitting normally" messages, following the addition of the self.window.destroy() call #FIXME get two "quitting normally" messages, following the addition of the self.window.destroy() call
# ... because self.window.destroy() leads to self.destroy() which calls this!
if not self.quitting:
print "Quitting normally" print "Quitting normally"
self.quitting = True
# TODO: check if current settings differ from profile, if so offer to save or abort # TODO: check if current settings differ from profile, if so offer to save or abort
if self.db!=None: if self.db!=None:
if self.db.backend==self.db.MYSQL_INNODB: if self.db.backend==self.db.MYSQL_INNODB:
try: try:
if self.db is not None and self.db.connected: if self.db is not None and self.db.connected():
self.db.disconnect() self.db.disconnect()
except _mysql_exceptions.OperationalError: # oh, damn, we're already disconnected except _mysql_exceptions.OperationalError: # oh, damn, we're already disconnected
pass pass
else: else:
if self.db is not None and self.db.connected: if self.db is not None and self.db.connected():
self.db.disconnect() self.db.disconnect()
else: else:
pass pass
@ -938,6 +948,7 @@ You can find the full license texts in agpl-3.0.txt, gpl-2.0.txt and gpl-3.0.txt
self.lock = interlocks.InterProcessLock(name="fpdb_global_lock") self.lock = interlocks.InterProcessLock(name="fpdb_global_lock")
self.db = None self.db = None
self.status_bar = None self.status_bar = None
self.quitting = False
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.connect("delete_event", self.delete_event) self.window.connect("delete_event", self.delete_event)

View File

@ -152,7 +152,9 @@ class Importer:
#Add an individual file to filelist #Add an individual file to filelist
def addImportFile(self, filename, site = "default", filter = "passthrough"): def addImportFile(self, filename, site = "default", filter = "passthrough"):
#TODO: test it is a valid file -> put that in config!! #TODO: test it is a valid file -> put that in config!!
if filename in self.filelist or not os.path.exists(unicode(filename,'utf-8')): #print "addimportfile: filename is a", filename.__class__
# filename now comes in as unicode
if filename in self.filelist or not os.path.exists(filename):
return return
self.filelist[filename] = [site] + [filter] self.filelist[filename] = [site] + [filter]
if site not in self.siteIds: if site not in self.siteIds:
@ -177,10 +179,11 @@ class Importer:
if os.path.isdir(inputPath): if os.path.isdir(inputPath):
for subdir in os.walk(inputPath): for subdir in os.walk(inputPath):
for file in subdir[2]: for file in subdir[2]:
self.addImportFile(os.path.join(subdir[0], file), site=site, self.addImportFile(unicode(os.path.join(subdir[0], file),'utf-8'),
filter=filter) site=site, filter=filter)
else: else:
self.addImportFile(inputPath, site=site, filter=filter)
self.addImportFile(unicode(inputPath,'utf-8'), site=site, filter=filter)
#Add a directory of files to filelist #Add a directory of files to filelist
#Only one import directory per site supported. #Only one import directory per site supported.
#dirlist is a hash of lists: #dirlist is a hash of lists:
@ -406,7 +409,8 @@ class Importer:
conv = None conv = None
(stored, duplicates, partial, errors, ttime) = (0, 0, 0, 0, time()) (stored, duplicates, partial, errors, ttime) = (0, 0, 0, 0, time())
file = file.decode("utf-8") #(Configuration.LOCALE_ENCODING) # sc: is there any need to decode this? maybe easier to skip it than guess at the encoding?
#file = file.decode("utf-8") #(Configuration.LOCALE_ENCODING)
# Load filter, process file, pass returned filename to import_fpdb_file # Load filter, process file, pass returned filename to import_fpdb_file
if self.settings['threads'] > 0 and self.writeq is not None: if self.settings['threads'] > 0 and self.writeq is not None: