add general section to configuration. currently includes default bulk import path and start of day offset

This commit is contained in:
sqlcoder 2010-03-15 21:48:25 +00:00
parent a10f7c144e
commit a4a4eaa87b
2 changed files with 44 additions and 1 deletions

View File

@ -452,6 +452,24 @@ class Tv:
return (" combinedStealFold = %s\n combined2B3B = %s\n combinedPostflop = %s\n" %
(self.combinedStealFold, self.combined2B3B, self.combinedPostflop) )
class General(dict):
def __init__(self):
super(General, self).__init__()
def add_elements(self, node):
# HH_bulk_path - if set, used as default path for bulk imports:
# day_start - number n where 0.0 <= n < 24.0 representing start of day for user
# e.g. user could set to 4.0 for day to start at 4am local time
for (name, value) in node.attributes.items():
log.debug("config.general: adding %s = %s" % (name,value))
self[name] = value
def __str__(self):
s = ""
for k in self:
s = s + " %s = %s\n" % (k, self[k])
return(s)
class Config:
def __init__(self, file = None, dbname = ''):
# "file" is a path to an xml file with the fpdb/HUD configuration
@ -506,7 +524,10 @@ class Config:
self.popup_windows = {}
self.db_selected = None # database the user would like to use
self.tv = None
self.general = General()
for gen_node in doc.getElementsByTagName("general"):
self.general.add_elements(node=gen_node) # add/overwrite elements in self.general
# s_sites = doc.getElementsByTagName("supported_sites")
for site_node in doc.getElementsByTagName("site"):
@ -839,6 +860,8 @@ class Config:
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
if 'HH_bulk_path' in self.general and self.general['HH_bulk_path']:
paths['bulkImport-defaultPath'] = self.general['HH_bulk_path']
except AssertionError:
paths['hud-defaultPath'] = paths['bulkImport-defaultPath'] = "** ERROR DEFAULT PATH IN CONFIG DOES NOT EXIST **"
return paths
@ -987,6 +1010,9 @@ class Config:
"""Join the fpdb path to filename."""
return os.path.join(os.path.dirname(inspect.getfile(sys._getframe(0))), filename)
def get_general_params(self):
return( self.general )
if __name__== "__main__":
c = Config()

View File

@ -58,6 +58,11 @@ class Filters(threading.Thread):
,'limitsFL':'FL', 'limitsNL':'NL', 'limitsPL':'PL', 'ring':'Ring', 'tour':'Tourney'
}
gen = self.conf.get_general_params()
self.day_start = 0
if 'day_start' in gen:
self.day_start = float(gen['day_start'])
# Outer Packing box
self.mainVBox = gtk.VBox(False, 0)
@ -864,6 +869,9 @@ class Filters(threading.Thread):
self.end_date.set_text('')
def __get_dates(self):
# self.day_start gives user's start of day in hours
offset = int(self.day_start * 3600) # calc day_start in seconds
t1 = self.start_date.get_text()
t2 = self.end_date.get_text()
@ -872,6 +880,15 @@ class Filters(threading.Thread):
if t2 == '':
t2 = '2020-12-12'
s1 = strptime(t1, "%Y-%m-%d") # make time_struct
s2 = strptime(t2, "%Y-%m-%d")
e1 = mktime(s1) + offset # s1 is localtime, but returned time since epoch is UTC, then add the
e2 = mktime(s2) + offset # s2 is localtime, but returned time since epoch is UTC
adj_t1 = strftime("%Y-%m-%d %H:%M:%S", gmtime(e1)) # make adjusted string including time
adj_t1 = strftime("%Y-%m-%d %H:%M:%S", gmtime(e1))
log.info("t1="+t1+" adj_t1="+adj_t1+'.')
return (t1, t2)
def __get_date(self, widget, calendar, entry, win):