2008-08-19 00:53:25 +02:00
|
|
|
#!/usr/bin/env python
|
2009-08-08 10:07:30 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2008-08-19 00:53:25 +02:00
|
|
|
"""Configuration.py
|
|
|
|
|
|
|
|
Handles HUD configuration files.
|
|
|
|
"""
|
2009-03-05 02:04:23 +01:00
|
|
|
# Copyright 2008, 2009, Ray E. Barker
|
2008-08-19 00:53:25 +02:00
|
|
|
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
|
|
|
########################################################################
|
|
|
|
|
|
|
|
# Standard Library modules
|
2009-09-16 07:13:42 +02:00
|
|
|
from __future__ import with_statement
|
2008-09-27 01:21:38 +02:00
|
|
|
import os
|
|
|
|
import sys
|
2008-12-13 23:37:23 +01:00
|
|
|
import inspect
|
2008-10-05 02:22:53 +02:00
|
|
|
import string
|
2008-09-29 16:12:04 +02:00
|
|
|
import traceback
|
2008-09-15 22:31:55 +02:00
|
|
|
import shutil
|
2008-08-19 00:53:25 +02:00
|
|
|
import xml.dom.minidom
|
|
|
|
from xml.dom.minidom import Node
|
|
|
|
|
2009-08-12 02:46:39 +02:00
|
|
|
import logging, logging.config
|
2009-10-21 19:24:46 +02:00
|
|
|
import ConfigParser
|
|
|
|
|
|
|
|
try: # local path
|
|
|
|
logging.config.fileConfig(os.path.join(sys.path[0],"logging.conf"))
|
|
|
|
except ConfigParser.NoSectionError: # debian package path
|
|
|
|
logging.config.fileConfig('/usr/share/python-fpdb/logging.conf')
|
|
|
|
|
2009-08-12 02:46:39 +02:00
|
|
|
log = logging.getLogger("config")
|
|
|
|
log.debug("config logger initialised")
|
|
|
|
|
2009-03-21 16:38:17 +01:00
|
|
|
def fix_tf(x, default = True):
|
2009-03-30 05:40:03 +02:00
|
|
|
# The xml parser doesn't translate "True" to True. Therefore, we never get
|
|
|
|
# True or False from the parser only "True" or "False". So translate the
|
|
|
|
# string to the python boolean representation.
|
2009-03-18 17:32:34 +01:00
|
|
|
if x == "1" or x == 1 or string.lower(x) == "true" or string.lower(x) == "t":
|
|
|
|
return True
|
|
|
|
if x == "0" or x == 0 or string.lower(x) == "false" or string.lower(x) == "f":
|
|
|
|
return False
|
2009-03-21 16:38:17 +01:00
|
|
|
return default
|
2009-03-18 17:32:34 +01:00
|
|
|
|
2008-08-19 00:53:25 +02:00
|
|
|
class Layout:
|
2009-03-07 03:46:34 +01:00
|
|
|
def __init__(self, node):
|
|
|
|
|
|
|
|
self.max = int( node.getAttribute('max') )
|
|
|
|
if node.hasAttribute('fav_seat'): self.fav_seat = int( node.getAttribute('fav_seat') )
|
|
|
|
self.width = int( node.getAttribute('width') )
|
|
|
|
self.height = int( node.getAttribute('height') )
|
|
|
|
|
2008-08-19 00:53:25 +02:00
|
|
|
self.location = []
|
2009-03-26 23:38:13 +01:00
|
|
|
self.location = map(lambda x: None, range(self.max+1)) # fill array with max seats+1 empty entries
|
2009-03-09 11:22:54 +01:00
|
|
|
|
2009-03-07 03:46:34 +01:00
|
|
|
for location_node in node.getElementsByTagName('location'):
|
|
|
|
if location_node.getAttribute('seat') != "":
|
|
|
|
self.location[int( location_node.getAttribute('seat') )] = (int( location_node.getAttribute('x') ), int( location_node.getAttribute('y')))
|
|
|
|
elif location_node.getAttribute('common') != "":
|
|
|
|
self.common = (int( location_node.getAttribute('x') ), int( location_node.getAttribute('y')))
|
|
|
|
|
2008-08-19 00:53:25 +02:00
|
|
|
def __str__(self):
|
2009-03-07 03:46:34 +01:00
|
|
|
temp = " Layout = %d max, width= %d, height = %d" % (self.max, self.width, self.height)
|
|
|
|
if hasattr(self, 'fav_seat'): temp = temp + ", fav_seat = %d\n" % self.fav_seat
|
|
|
|
else: temp = temp + "\n"
|
|
|
|
if hasattr(self, "common"):
|
|
|
|
temp = temp + " Common = (%d, %d)\n" % (self.common[0], self.common[1])
|
2008-08-19 00:53:25 +02:00
|
|
|
temp = temp + " Locations = "
|
2009-03-09 11:40:38 +01:00
|
|
|
for i in range(1, len(self.location)):
|
2008-08-19 00:53:25 +02:00
|
|
|
temp = temp + "(%d,%d)" % self.location[i]
|
|
|
|
|
2008-09-15 22:31:55 +02:00
|
|
|
return temp + "\n"
|
2008-08-19 00:53:25 +02:00
|
|
|
|
|
|
|
class Site:
|
|
|
|
def __init__(self, node):
|
2009-08-10 18:10:39 +02:00
|
|
|
def normalizePath(path):
|
|
|
|
"Normalized existing pathes"
|
|
|
|
if os.path.exists(path):
|
|
|
|
return os.path.abspath(path)
|
|
|
|
return path
|
|
|
|
|
2008-08-19 00:53:25 +02:00
|
|
|
self.site_name = node.getAttribute("site_name")
|
|
|
|
self.table_finder = node.getAttribute("table_finder")
|
|
|
|
self.screen_name = node.getAttribute("screen_name")
|
2009-08-10 18:10:39 +02:00
|
|
|
self.site_path = normalizePath(node.getAttribute("site_path"))
|
|
|
|
self.HH_path = normalizePath(node.getAttribute("HH_path"))
|
2008-08-19 00:53:25 +02:00
|
|
|
self.decoder = node.getAttribute("decoder")
|
2008-10-27 12:12:04 +01:00
|
|
|
self.hudopacity = node.getAttribute("hudopacity")
|
2008-10-27 11:29:39 +01:00
|
|
|
self.hudbgcolor = node.getAttribute("bgcolor")
|
|
|
|
self.hudfgcolor = node.getAttribute("fgcolor")
|
2008-11-04 10:40:03 +01:00
|
|
|
self.converter = node.getAttribute("converter")
|
2008-11-16 23:53:31 +01:00
|
|
|
self.aux_window = node.getAttribute("aux_window")
|
2008-12-18 03:57:05 +01:00
|
|
|
self.font = node.getAttribute("font")
|
|
|
|
self.font_size = node.getAttribute("font_size")
|
2009-06-20 15:43:05 +02:00
|
|
|
self.use_frames = node.getAttribute("use_frames")
|
2009-03-30 05:40:03 +02:00
|
|
|
self.enabled = fix_tf(node.getAttribute("enabled"), default = True)
|
2009-06-20 15:43:05 +02:00
|
|
|
self.xpad = node.getAttribute("xpad")
|
|
|
|
self.ypad = node.getAttribute("ypad")
|
2008-08-19 00:53:25 +02:00
|
|
|
self.layout = {}
|
2009-10-27 04:28:27 +01:00
|
|
|
|
2009-08-10 18:10:39 +02:00
|
|
|
print self.site_name, self.HH_path
|
2009-03-07 03:46:34 +01:00
|
|
|
|
2008-08-19 00:53:25 +02:00
|
|
|
for layout_node in node.getElementsByTagName('layout'):
|
2009-03-07 03:46:34 +01:00
|
|
|
lo = Layout(layout_node)
|
2008-08-19 00:53:25 +02:00
|
|
|
self.layout[lo.max] = lo
|
|
|
|
|
2009-06-20 15:43:05 +02:00
|
|
|
# Site defaults
|
|
|
|
if self.xpad == "": self.xpad = 1
|
|
|
|
else: self.xpad = int(self.xpad)
|
|
|
|
|
|
|
|
if self.ypad == "": self.ypad = 0
|
|
|
|
else: self.ypad = int(self.ypad)
|
|
|
|
|
|
|
|
if self.font_size == "": self.font_size = 7
|
|
|
|
else: self.font_size = int(self.font_size)
|
|
|
|
|
|
|
|
if self.hudopacity == "": self.hudopacity = 1.0
|
|
|
|
else: self.hudopacity = float(self.hudopacity)
|
|
|
|
|
|
|
|
if self.use_frames == "": self.use_frames = False
|
|
|
|
if self.font == "": self.font = "Sans"
|
|
|
|
if self.hudbgcolor == "": self.hudbgcolor = "000000"
|
|
|
|
if self.hudfgcolor == "": self.hudfgcolor = "FFFFFF"
|
|
|
|
|
2008-08-19 00:53:25 +02:00
|
|
|
def __str__(self):
|
2009-03-09 11:40:38 +01:00
|
|
|
temp = "Site = " + self.site_name + "\n"
|
2008-08-19 00:53:25 +02:00
|
|
|
for key in dir(self):
|
|
|
|
if key.startswith('__'): continue
|
|
|
|
if key == 'layout': continue
|
|
|
|
value = getattr(self, key)
|
|
|
|
if callable(value): continue
|
2008-10-30 03:37:05 +01:00
|
|
|
temp = temp + ' ' + key + " = " + str(value) + "\n"
|
2008-08-19 00:53:25 +02:00
|
|
|
|
|
|
|
for layout in self.layout:
|
2009-03-09 11:40:38 +01:00
|
|
|
temp = temp + "%s" % self.layout[layout]
|
2008-08-19 00:53:25 +02:00
|
|
|
|
|
|
|
return temp
|
|
|
|
|
|
|
|
class Stat:
|
|
|
|
def __init__(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def __str__(self):
|
2008-09-15 22:31:55 +02:00
|
|
|
temp = " stat_name = %s, row = %d, col = %d, tip = %s, click = %s, popup = %s\n" % (self.stat_name, self.row, self.col, self.tip, self.click, self.popup)
|
2008-08-19 00:53:25 +02:00
|
|
|
return temp
|
|
|
|
|
|
|
|
class Game:
|
|
|
|
def __init__(self, node):
|
|
|
|
self.game_name = node.getAttribute("game_name")
|
|
|
|
self.rows = int( node.getAttribute("rows") )
|
|
|
|
self.cols = int( node.getAttribute("cols") )
|
2009-06-20 15:43:05 +02:00
|
|
|
self.xpad = node.getAttribute("xpad")
|
|
|
|
self.ypad = node.getAttribute("ypad")
|
|
|
|
|
|
|
|
# Defaults
|
|
|
|
if self.xpad == "": self.xpad = 1
|
|
|
|
else: self.xpad = int(self.xpad)
|
|
|
|
if self.ypad == "": self.ypad = 0
|
|
|
|
else: self.ypad = int(self.ypad)
|
2009-03-05 02:04:23 +01:00
|
|
|
|
|
|
|
aux_text = node.getAttribute("aux")
|
|
|
|
aux_list = aux_text.split(',')
|
|
|
|
for i in range(0, len(aux_list)):
|
|
|
|
aux_list[i] = aux_list[i].strip()
|
|
|
|
self.aux = aux_list
|
2008-08-19 00:53:25 +02:00
|
|
|
|
|
|
|
self.stats = {}
|
|
|
|
for stat_node in node.getElementsByTagName('stat'):
|
|
|
|
stat = Stat()
|
|
|
|
stat.stat_name = stat_node.getAttribute("stat_name")
|
|
|
|
stat.row = int( stat_node.getAttribute("row") )
|
|
|
|
stat.col = int( stat_node.getAttribute("col") )
|
|
|
|
stat.tip = stat_node.getAttribute("tip")
|
|
|
|
stat.click = stat_node.getAttribute("click")
|
2008-09-15 22:31:55 +02:00
|
|
|
stat.popup = stat_node.getAttribute("popup")
|
2008-11-02 11:20:25 +01:00
|
|
|
stat.hudprefix = stat_node.getAttribute("hudprefix")
|
|
|
|
stat.hudsuffix = stat_node.getAttribute("hudsuffix")
|
2008-11-25 12:47:58 +01:00
|
|
|
stat.hudcolor = stat_node.getAttribute("hudcolor")
|
2008-08-19 00:53:25 +02:00
|
|
|
|
|
|
|
self.stats[stat.stat_name] = stat
|
|
|
|
|
|
|
|
def __str__(self):
|
2009-03-09 11:40:38 +01:00
|
|
|
temp = "Game = " + self.game_name + "\n"
|
|
|
|
temp = temp + " rows = %d\n" % self.rows
|
|
|
|
temp = temp + " cols = %d\n" % self.cols
|
2009-06-20 15:43:05 +02:00
|
|
|
temp = temp + " xpad = %d\n" % self.xpad
|
|
|
|
temp = temp + " ypad = %d\n" % self.ypad
|
2009-03-09 11:40:38 +01:00
|
|
|
temp = temp + " aux = %s\n" % self.aux
|
2008-08-19 00:53:25 +02:00
|
|
|
|
|
|
|
for stat in self.stats.keys():
|
2009-03-09 11:40:38 +01:00
|
|
|
temp = temp + "%s" % self.stats[stat]
|
2008-08-19 00:53:25 +02:00
|
|
|
|
|
|
|
return temp
|
|
|
|
|
|
|
|
class Database:
|
|
|
|
def __init__(self, node):
|
|
|
|
self.db_name = node.getAttribute("db_name")
|
|
|
|
self.db_server = node.getAttribute("db_server")
|
|
|
|
self.db_ip = node.getAttribute("db_ip")
|
|
|
|
self.db_user = node.getAttribute("db_user")
|
|
|
|
self.db_type = node.getAttribute("db_type")
|
|
|
|
self.db_pass = node.getAttribute("db_pass")
|
2009-08-12 02:46:39 +02:00
|
|
|
self.db_selected = fix_tf(node.getAttribute("default"),"False")
|
|
|
|
log.debug("Database db_name:'%(name)s' db_server:'%(server)s' db_ip:'%(ip)s' db_user:'%(user)s' db_type:'%(type)s' db_pass (not logged) selected:'%(sel)s'" \
|
|
|
|
% { 'name':self.db_name, 'server':self.db_server, 'ip':self.db_ip, 'user':self.db_user, 'type':self.db_type, 'sel':self.db_selected} )
|
2008-08-19 00:53:25 +02:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
temp = 'Database = ' + self.db_name + '\n'
|
|
|
|
for key in dir(self):
|
|
|
|
if key.startswith('__'): continue
|
|
|
|
value = getattr(self, key)
|
|
|
|
if callable(value): continue
|
2009-08-15 23:36:14 +02:00
|
|
|
temp = temp + ' ' + key + " = " + repr(value) + "\n"
|
2008-08-19 00:53:25 +02:00
|
|
|
return temp
|
|
|
|
|
2008-11-16 23:53:31 +01:00
|
|
|
class Aux_window:
|
2008-08-19 00:53:25 +02:00
|
|
|
def __init__(self, node):
|
2008-11-16 23:53:31 +01:00
|
|
|
for (name, value) in node.attributes.items():
|
|
|
|
setattr(self, name, value)
|
2009-03-07 03:46:34 +01:00
|
|
|
|
|
|
|
self.layout = {}
|
|
|
|
for layout_node in node.getElementsByTagName('layout'):
|
|
|
|
lo = Layout(layout_node)
|
|
|
|
self.layout[lo.max] = lo
|
2008-08-19 00:53:25 +02:00
|
|
|
|
|
|
|
def __str__(self):
|
2008-11-16 23:53:31 +01:00
|
|
|
temp = 'Aux = ' + self.name + "\n"
|
2008-08-19 00:53:25 +02:00
|
|
|
for key in dir(self):
|
|
|
|
if key.startswith('__'): continue
|
2009-03-07 03:46:34 +01:00
|
|
|
if key == 'layout': continue
|
2008-08-19 00:53:25 +02:00
|
|
|
value = getattr(self, key)
|
|
|
|
if callable(value): continue
|
|
|
|
temp = temp + ' ' + key + " = " + value + "\n"
|
2009-03-07 03:46:34 +01:00
|
|
|
|
|
|
|
for layout in self.layout:
|
|
|
|
temp = temp + "%s" % self.layout[layout]
|
2008-08-19 00:53:25 +02:00
|
|
|
return temp
|
|
|
|
|
2009-03-24 14:58:45 +01:00
|
|
|
class HHC:
|
|
|
|
def __init__(self, node):
|
|
|
|
self.site = node.getAttribute("site")
|
|
|
|
self.converter = node.getAttribute("converter")
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return "%s:\t%s" % (self.site, self.converter)
|
|
|
|
|
|
|
|
|
2008-09-15 22:31:55 +02:00
|
|
|
class Popup:
|
|
|
|
def __init__(self, node):
|
|
|
|
self.name = node.getAttribute("pu_name")
|
|
|
|
self.pu_stats = []
|
|
|
|
for stat_node in node.getElementsByTagName('pu_stat'):
|
|
|
|
self.pu_stats.append(stat_node.getAttribute("pu_stat_name"))
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
temp = "Popup = " + self.name + "\n"
|
|
|
|
for stat in self.pu_stats:
|
|
|
|
temp = temp + " " + stat
|
|
|
|
return temp + "\n"
|
|
|
|
|
2008-10-21 16:22:01 +02:00
|
|
|
class Import:
|
|
|
|
def __init__(self, node):
|
2009-09-10 03:21:27 +02:00
|
|
|
self.node = node
|
2008-11-08 14:01:07 +01:00
|
|
|
self.interval = node.getAttribute("interval")
|
|
|
|
self.callFpdbHud = node.getAttribute("callFpdbHud")
|
2009-02-19 13:15:12 +01:00
|
|
|
self.hhArchiveBase = node.getAttribute("hhArchiveBase")
|
2009-03-21 16:38:17 +01:00
|
|
|
self.saveActions = fix_tf(node.getAttribute("saveActions"), True)
|
2009-03-27 18:26:01 +01:00
|
|
|
self.fastStoreHudCache = fix_tf(node.getAttribute("fastStoreHudCache"), False)
|
2008-10-21 16:22:01 +02:00
|
|
|
|
|
|
|
def __str__(self):
|
2009-03-15 20:54:22 +01:00
|
|
|
return " interval = %s\n callFpdbHud = %s\n hhArchiveBase = %s\n saveActions = %s\n fastStoreHudCache = %s\n" \
|
2009-03-21 16:38:17 +01:00
|
|
|
% (self.interval, self.callFpdbHud, self.hhArchiveBase, self.saveActions, self.fastStoreHudCache)
|
2008-10-21 16:22:01 +02:00
|
|
|
|
2009-10-03 20:05:41 +02:00
|
|
|
class HudUI:
|
|
|
|
def __init__(self, node):
|
|
|
|
self.node = node
|
|
|
|
self.label = node.getAttribute('label')
|
2009-10-14 15:04:09 +02:00
|
|
|
#
|
|
|
|
self.aggregate_ring = fix_tf(node.getAttribute('aggregate_ring_game_stats'))
|
|
|
|
self.aggregate_tour = fix_tf(node.getAttribute('aggregate_tourney_stats'))
|
|
|
|
self.hud_style = node.getAttribute('stat_aggregation_range')
|
|
|
|
self.hud_days = node.getAttribute('aggregation_days')
|
|
|
|
self.agg_bb_mult = node.getAttribute('aggregation_level_multiplier')
|
|
|
|
#
|
|
|
|
self.h_aggregate_ring = fix_tf(node.getAttribute('aggregate_hero_ring_game_stats'))
|
|
|
|
self.h_aggregate_tour = fix_tf(node.getAttribute('aggregate_hero_tourney_stats'))
|
|
|
|
self.h_hud_style = node.getAttribute('hero_stat_aggregation_range')
|
|
|
|
self.h_hud_days = node.getAttribute('hero_aggregation_days')
|
|
|
|
self.h_agg_bb_mult = node.getAttribute('hero_aggregation_level_multiplier')
|
|
|
|
|
2009-10-03 20:05:41 +02:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return " label = %s\n" % self.label
|
|
|
|
|
|
|
|
|
2008-10-21 16:22:01 +02:00
|
|
|
class Tv:
|
|
|
|
def __init__(self, node):
|
|
|
|
self.combinedStealFold = node.getAttribute("combinedStealFold")
|
|
|
|
self.combined2B3B = node.getAttribute("combined2B3B")
|
|
|
|
self.combinedPostflop = node.getAttribute("combinedPostflop")
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return (" combinedStealFold = %s\n combined2B3B = %s\n combinedPostflop = %s\n" %
|
|
|
|
(self.combinedStealFold, self.combined2B3B, self.combinedPostflop) )
|
|
|
|
|
2008-08-19 00:53:25 +02:00
|
|
|
class Config:
|
2009-08-12 02:46:39 +02:00
|
|
|
def __init__(self, file = None, dbname = ''):
|
2008-09-27 01:21:38 +02:00
|
|
|
|
|
|
|
# "file" is a path to an xml file with the fpdb/HUD configuration
|
|
|
|
# we check the existence of "file" and try to recover if it doesn't exist
|
|
|
|
|
2008-11-05 11:49:05 +01:00
|
|
|
self.default_config_path = self.get_default_config_path()
|
2009-03-26 19:57:40 +01:00
|
|
|
if file != None: # configuration file path has been passed
|
2009-06-15 05:14:53 +02:00
|
|
|
file = os.path.expanduser(file)
|
2008-09-27 01:21:38 +02:00
|
|
|
if not os.path.exists(file):
|
|
|
|
print "Configuration file %s not found. Using defaults." % (file)
|
|
|
|
sys.stderr.write("Configuration file %s not found. Using defaults." % (file))
|
|
|
|
file = None
|
|
|
|
|
|
|
|
if file == None: # configuration file path not passed or invalid
|
2008-11-03 04:58:55 +01:00
|
|
|
file = self.find_config() #Look for a config file in the normal places
|
|
|
|
|
|
|
|
if file == None: # no config file in the normal places
|
|
|
|
file = self.find_example_config() #Look for an example file to edit
|
2009-03-26 19:57:40 +01:00
|
|
|
if file != None:
|
2008-11-05 11:49:05 +01:00
|
|
|
pass
|
2008-11-03 04:58:55 +01:00
|
|
|
|
|
|
|
if file == None: # that didn't work either, just die
|
2009-10-04 18:46:04 +02:00
|
|
|
print "No HUD_config_xml found after looking in current directory and "+self.default_config_path+"\nExiting"
|
|
|
|
sys.stderr.write("No HUD_config_xml found after looking in current directory and "+self.default_config_path+"\nExiting")
|
|
|
|
print "press enter to continue"
|
|
|
|
sys.stdin.readline()
|
2008-11-03 04:58:55 +01:00
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
# Parse even if there was no real config file found and we are using the example
|
|
|
|
# If using the example, we'll edit it later
|
2009-10-04 18:46:04 +02:00
|
|
|
# sc 2009/10/04 Example already copied to main filename, is this ok?
|
2009-09-16 06:30:59 +02:00
|
|
|
log.info("Reading configuration file %s" % file)
|
2009-10-04 18:46:04 +02:00
|
|
|
if os.sep in file:
|
|
|
|
print "\nReading configuration file %s\n" % file
|
|
|
|
else:
|
|
|
|
print "\nReading configuration file %s" % file
|
|
|
|
print "in %s\n" % os.getcwd()
|
2008-09-29 16:12:04 +02:00
|
|
|
try:
|
|
|
|
doc = xml.dom.minidom.parse(file)
|
2009-08-16 11:22:22 +02:00
|
|
|
except:
|
2009-08-12 02:46:39 +02:00
|
|
|
log.error("Error parsing %s. See error log file." % (file))
|
2008-09-29 16:12:04 +02:00
|
|
|
traceback.print_exc(file=sys.stderr)
|
|
|
|
print "press enter to continue"
|
|
|
|
sys.stdin.readline()
|
|
|
|
sys.exit()
|
2008-08-19 00:53:25 +02:00
|
|
|
|
2008-09-15 22:31:55 +02:00
|
|
|
self.doc = doc
|
|
|
|
self.file = file
|
2008-08-19 00:53:25 +02:00
|
|
|
self.supported_sites = {}
|
|
|
|
self.supported_games = {}
|
|
|
|
self.supported_databases = {}
|
2008-11-16 23:53:31 +01:00
|
|
|
self.aux_windows = {}
|
2009-03-24 14:58:45 +01:00
|
|
|
self.hhcs = {}
|
2008-09-15 22:31:55 +02:00
|
|
|
self.popup_windows = {}
|
2008-08-19 00:53:25 +02:00
|
|
|
|
|
|
|
# s_sites = doc.getElementsByTagName("supported_sites")
|
|
|
|
for site_node in doc.getElementsByTagName("site"):
|
|
|
|
site = Site(node = site_node)
|
|
|
|
self.supported_sites[site.site_name] = site
|
|
|
|
|
2008-10-21 16:22:01 +02:00
|
|
|
# s_games = doc.getElementsByTagName("supported_games")
|
2008-08-19 00:53:25 +02:00
|
|
|
for game_node in doc.getElementsByTagName("game"):
|
|
|
|
game = Game(node = game_node)
|
|
|
|
self.supported_games[game.game_name] = game
|
|
|
|
|
2008-10-21 16:22:01 +02:00
|
|
|
# s_dbs = doc.getElementsByTagName("supported_databases")
|
2009-09-04 23:12:35 +02:00
|
|
|
# select database from those defined in config by:
|
|
|
|
# 1) command line option
|
|
|
|
# or 2) selected="True" in config element
|
|
|
|
# or 3) just choose the first we come across
|
2008-08-19 00:53:25 +02:00
|
|
|
for db_node in doc.getElementsByTagName("database"):
|
2009-08-12 02:46:39 +02:00
|
|
|
try:
|
|
|
|
db = Database(node = db_node)
|
2009-09-16 06:30:59 +02:00
|
|
|
except:
|
|
|
|
raise FpdbError("Unable to create database object")
|
|
|
|
else:
|
2009-08-12 02:46:39 +02:00
|
|
|
if db.db_name in self.supported_databases:
|
|
|
|
raise FpdbError("Database names must be unique")
|
2009-09-16 06:30:59 +02:00
|
|
|
# If there is only one Database node, or none are marked
|
|
|
|
# default, use first
|
|
|
|
if not self.supported_databases:
|
2009-08-12 02:46:39 +02:00
|
|
|
self.db_selected = db.db_name
|
|
|
|
self.supported_databases[db.db_name] = db
|
|
|
|
if db.db_selected:
|
|
|
|
self.db_selected = db.db_name
|
2009-09-16 06:30:59 +02:00
|
|
|
|
2009-09-04 23:12:35 +02:00
|
|
|
if dbname and dbname in self.supported_databases:
|
|
|
|
self.db_selected = dbname
|
|
|
|
|
2008-10-21 16:22:01 +02:00
|
|
|
# s_dbs = doc.getElementsByTagName("mucked_windows")
|
2008-11-16 23:53:31 +01:00
|
|
|
for aw_node in doc.getElementsByTagName("aw"):
|
|
|
|
aw = Aux_window(node = aw_node)
|
|
|
|
self.aux_windows[aw.name] = aw
|
2008-08-19 00:53:25 +02:00
|
|
|
|
2009-03-24 14:58:45 +01:00
|
|
|
# s_dbs = doc.getElementsByTagName("mucked_windows")
|
|
|
|
for hhc_node in doc.getElementsByTagName("hhc"):
|
|
|
|
hhc = HHC(node = hhc_node)
|
|
|
|
self.hhcs[hhc.site] = hhc
|
|
|
|
|
2008-10-21 16:22:01 +02:00
|
|
|
# s_dbs = doc.getElementsByTagName("popup_windows")
|
2008-09-15 22:31:55 +02:00
|
|
|
for pu_node in doc.getElementsByTagName("pu"):
|
|
|
|
pu = Popup(node = pu_node)
|
|
|
|
self.popup_windows[pu.name] = pu
|
|
|
|
|
2008-10-21 16:22:01 +02:00
|
|
|
for imp_node in doc.getElementsByTagName("import"):
|
|
|
|
imp = Import(node = imp_node)
|
|
|
|
self.imp = imp
|
|
|
|
|
2009-10-03 20:05:41 +02:00
|
|
|
for hui_node in doc.getElementsByTagName('hud_ui'):
|
|
|
|
hui = HudUI(node = hui_node)
|
|
|
|
self.ui = hui
|
|
|
|
|
2008-10-21 16:22:01 +02:00
|
|
|
for tv_node in doc.getElementsByTagName("tv"):
|
|
|
|
tv = Tv(node = tv_node)
|
|
|
|
self.tv = tv
|
|
|
|
|
2009-03-27 15:49:22 +01:00
|
|
|
db = self.get_db_parameters()
|
2008-11-03 04:58:55 +01:00
|
|
|
if db['db-password'] == 'YOUR MYSQL PASSWORD':
|
|
|
|
df_file = self.find_default_conf()
|
|
|
|
if df_file == None: # this is bad
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
df_parms = self.read_default_conf(df_file)
|
2008-11-05 11:49:05 +01:00
|
|
|
self.set_db_parameters(db_name = 'fpdb', db_ip = df_parms['db-host'],
|
|
|
|
db_user = df_parms['db-user'],
|
|
|
|
db_pass = df_parms['db-password'])
|
|
|
|
self.save(file=os.path.join(self.default_config_path, "HUD_config.xml"))
|
|
|
|
|
2009-10-04 18:46:04 +02:00
|
|
|
print ""
|
|
|
|
|
2009-09-10 03:21:27 +02:00
|
|
|
def set_hhArchiveBase(self, path):
|
|
|
|
self.imp.node.setAttribute("hhArchiveBase", path)
|
|
|
|
|
2008-11-03 04:58:55 +01:00
|
|
|
def find_config(self):
|
2008-11-05 11:49:05 +01:00
|
|
|
"""Looks in cwd and in self.default_config_path for a config file."""
|
2008-11-03 04:58:55 +01:00
|
|
|
if os.path.exists('HUD_config.xml'): # there is a HUD_config in the cwd
|
|
|
|
file = 'HUD_config.xml' # so we use it
|
|
|
|
else: # no HUD_config in the cwd, look where it should be in the first place
|
2008-11-05 11:49:05 +01:00
|
|
|
config_path = os.path.join(self.default_config_path, 'HUD_config.xml')
|
|
|
|
if os.path.exists(config_path):
|
2008-11-03 04:58:55 +01:00
|
|
|
file = config_path
|
|
|
|
else:
|
|
|
|
file = None
|
|
|
|
return file
|
|
|
|
|
2008-11-05 11:49:05 +01:00
|
|
|
def get_default_config_path(self):
|
|
|
|
"""Returns the path where the fpdb config file _should_ be stored."""
|
|
|
|
if os.name == 'posix':
|
|
|
|
config_path = os.path.join(os.path.expanduser("~"), '.fpdb')
|
|
|
|
elif os.name == 'nt':
|
|
|
|
config_path = os.path.join(os.environ["APPDATA"], 'fpdb')
|
|
|
|
else: config_path = None
|
|
|
|
return config_path
|
|
|
|
|
|
|
|
|
2008-11-03 04:58:55 +01:00
|
|
|
def find_default_conf(self):
|
|
|
|
if os.name == 'posix':
|
|
|
|
config_path = os.path.join(os.path.expanduser("~"), '.fpdb', 'default.conf')
|
|
|
|
elif os.name == 'nt':
|
|
|
|
config_path = os.path.join(os.environ["APPDATA"], 'fpdb', 'default.conf')
|
|
|
|
else: config_path = False
|
|
|
|
|
|
|
|
if config_path and os.path.exists(config_path):
|
|
|
|
file = config_path
|
|
|
|
else:
|
|
|
|
file = None
|
|
|
|
return file
|
|
|
|
|
|
|
|
def read_default_conf(self, file):
|
|
|
|
parms = {}
|
2009-09-16 07:13:42 +02:00
|
|
|
with open(file, "r") as fh:
|
|
|
|
for line in fh:
|
|
|
|
line = string.strip(line)
|
|
|
|
(key, value) = line.split('=')
|
|
|
|
parms[key] = value
|
2008-11-03 04:58:55 +01:00
|
|
|
return parms
|
|
|
|
|
|
|
|
def find_example_config(self):
|
|
|
|
if os.path.exists('HUD_config.xml.example'): # there is a HUD_config in the cwd
|
2009-10-04 18:46:04 +02:00
|
|
|
file = 'HUD_config.xml' # so we use it
|
|
|
|
try:
|
|
|
|
shutil.copyfile(file+'.example', file)
|
|
|
|
except:
|
|
|
|
file = ''
|
2008-11-03 04:58:55 +01:00
|
|
|
print "No HUD_config.xml found, using HUD_config.xml.example.\n", \
|
2009-10-04 18:46:04 +02:00
|
|
|
"A HUD_config.xml has been created. You will probably have to edit it."
|
2008-11-03 04:58:55 +01:00
|
|
|
sys.stderr.write("No HUD_config.xml found, using HUD_config.xml.example.\n" + \
|
2009-10-04 18:46:04 +02:00
|
|
|
"A HUD_config.xml has been created. You will probably have to edit it.")
|
2008-11-03 04:58:55 +01:00
|
|
|
else:
|
|
|
|
file = None
|
|
|
|
return file
|
|
|
|
|
2008-09-15 22:31:55 +02:00
|
|
|
def get_site_node(self, site):
|
|
|
|
for site_node in self.doc.getElementsByTagName("site"):
|
|
|
|
if site_node.getAttribute("site_name") == site:
|
|
|
|
return site_node
|
|
|
|
|
2009-03-11 19:12:56 +01:00
|
|
|
def get_aux_node(self, aux):
|
|
|
|
for aux_node in self.doc.getElementsByTagName("aw"):
|
|
|
|
if aux_node.getAttribute("name") == aux:
|
|
|
|
return aux_node
|
|
|
|
|
2008-11-05 11:49:05 +01:00
|
|
|
def get_db_node(self, db_name):
|
|
|
|
for db_node in self.doc.getElementsByTagName("database"):
|
|
|
|
if db_node.getAttribute("db_name") == db_name:
|
|
|
|
return db_node
|
|
|
|
return None
|
|
|
|
|
2008-09-15 22:31:55 +02:00
|
|
|
def get_layout_node(self, site_node, layout):
|
|
|
|
for layout_node in site_node.getElementsByTagName("layout"):
|
2008-10-04 22:43:50 +02:00
|
|
|
if layout_node.getAttribute("max") == None:
|
|
|
|
return None
|
2008-09-15 22:31:55 +02:00
|
|
|
if int( layout_node.getAttribute("max") ) == int( layout ):
|
|
|
|
return layout_node
|
|
|
|
|
|
|
|
def get_location_node(self, layout_node, seat):
|
2009-03-15 20:27:47 +01:00
|
|
|
if seat == "common":
|
|
|
|
for location_node in layout_node.getElementsByTagName("location"):
|
|
|
|
if location_node.hasAttribute("common"):
|
|
|
|
return location_node
|
|
|
|
else:
|
|
|
|
for location_node in layout_node.getElementsByTagName("location"):
|
|
|
|
if int( location_node.getAttribute("seat") ) == int( seat ):
|
|
|
|
return location_node
|
2008-09-15 22:31:55 +02:00
|
|
|
|
|
|
|
def save(self, file = None):
|
2009-03-26 19:57:40 +01:00
|
|
|
if file != None:
|
2009-09-16 07:13:42 +02:00
|
|
|
with open(file, 'w') as f:
|
|
|
|
self.doc.writexml(f)
|
2008-09-15 22:31:55 +02:00
|
|
|
else:
|
|
|
|
shutil.move(self.file, self.file+".backup")
|
2009-09-17 12:26:06 +02:00
|
|
|
with open(self.file, 'w') as f:
|
2009-09-16 07:13:42 +02:00
|
|
|
self.doc.writexml(f)
|
2008-09-15 22:31:55 +02:00
|
|
|
|
|
|
|
def edit_layout(self, site_name, max, width = None, height = None,
|
|
|
|
fav_seat = None, locations = None):
|
|
|
|
site_node = self.get_site_node(site_name)
|
|
|
|
layout_node = self.get_layout_node(site_node, max)
|
2008-10-04 22:43:50 +02:00
|
|
|
if layout_node == None: return
|
2009-03-09 11:40:38 +01:00
|
|
|
for i in range(1, max + 1):
|
2008-09-15 22:31:55 +02:00
|
|
|
location_node = self.get_location_node(layout_node, i)
|
|
|
|
location_node.setAttribute("x", str( locations[i-1][0] ))
|
|
|
|
location_node.setAttribute("y", str( locations[i-1][1] ))
|
|
|
|
self.supported_sites[site_name].layout[max].location[i] = ( locations[i-1][0], locations[i-1][1] )
|
|
|
|
|
2009-03-11 19:12:56 +01:00
|
|
|
def edit_aux_layout(self, aux_name, max, width = None, height = None, locations = None):
|
|
|
|
aux_node = self.get_aux_node(aux_name)
|
|
|
|
layout_node = self.get_layout_node(aux_node, max)
|
2009-03-15 20:27:47 +01:00
|
|
|
if layout_node == None:
|
|
|
|
print "aux node not found"
|
|
|
|
return
|
|
|
|
print "editing locations =", locations
|
|
|
|
for (i, pos) in locations.iteritems():
|
2009-03-11 19:12:56 +01:00
|
|
|
location_node = self.get_location_node(layout_node, i)
|
2009-03-15 20:27:47 +01:00
|
|
|
location_node.setAttribute("x", str( locations[i][0] ))
|
|
|
|
location_node.setAttribute("y", str( locations[i][1] ))
|
|
|
|
if i == "common":
|
|
|
|
self.aux_windows[aux_name].layout[max].common = ( locations[i][0], locations[i][1] )
|
|
|
|
else:
|
|
|
|
self.aux_windows[aux_name].layout[max].location[i] = ( locations[i][0], locations[i][1] )
|
2009-03-11 19:12:56 +01:00
|
|
|
|
2009-03-27 15:49:22 +01:00
|
|
|
def get_db_parameters(self):
|
2008-10-05 02:22:53 +02:00
|
|
|
db = {}
|
2009-08-12 02:46:39 +02:00
|
|
|
name = self.db_selected
|
2009-09-16 06:30:59 +02:00
|
|
|
# TODO: What's up with all the exception handling here?!
|
2009-03-17 04:34:00 +01:00
|
|
|
try: db['db-databaseName'] = name
|
|
|
|
except: pass
|
|
|
|
|
|
|
|
try: db['db-host'] = self.supported_databases[name].db_ip
|
|
|
|
except: pass
|
|
|
|
|
|
|
|
try: db['db-user'] = self.supported_databases[name].db_user
|
|
|
|
except: pass
|
|
|
|
|
|
|
|
try: db['db-password'] = self.supported_databases[name].db_pass
|
|
|
|
except: pass
|
|
|
|
|
|
|
|
try: db['db-server'] = self.supported_databases[name].db_server
|
|
|
|
except: pass
|
|
|
|
|
2009-06-02 00:26:20 +02:00
|
|
|
try: db['db-type'] = self.supported_databases[name].db_type
|
|
|
|
except: pass
|
|
|
|
|
2009-03-17 04:34:00 +01:00
|
|
|
if string.lower(self.supported_databases[name].db_server) == 'mysql':
|
|
|
|
db['db-backend'] = 2
|
|
|
|
elif string.lower(self.supported_databases[name].db_server) == 'postgresql':
|
|
|
|
db['db-backend'] = 3
|
2009-07-14 01:04:10 +02:00
|
|
|
elif string.lower(self.supported_databases[name].db_server) == 'sqlite':
|
|
|
|
db['db-backend'] = 4
|
2009-03-17 04:34:00 +01:00
|
|
|
else: db['db-backend'] = None # this is big trouble
|
2008-10-05 02:22:53 +02:00
|
|
|
return db
|
|
|
|
|
2008-11-05 11:49:05 +01:00
|
|
|
def set_db_parameters(self, db_name = 'fpdb', db_ip = None, db_user = None,
|
|
|
|
db_pass = None, db_server = None, db_type = None):
|
|
|
|
db_node = self.get_db_node(db_name)
|
2009-03-26 19:57:40 +01:00
|
|
|
if db_node != None:
|
|
|
|
if db_ip != None: db_node.setAttribute("db_ip", db_ip)
|
|
|
|
if db_user != None: db_node.setAttribute("db_user", db_user)
|
|
|
|
if db_pass != None: db_node.setAttribute("db_pass", db_pass)
|
|
|
|
if db_server != None: db_node.setAttribute("db_server", db_server)
|
|
|
|
if db_type != None: db_node.setAttribute("db_type", db_type)
|
2008-11-05 11:49:05 +01:00
|
|
|
if self.supported_databases.has_key(db_name):
|
2009-03-26 19:57:40 +01:00
|
|
|
if db_ip != None: self.supported_databases[db_name].dp_ip = db_ip
|
|
|
|
if db_user != None: self.supported_databases[db_name].dp_user = db_user
|
|
|
|
if db_pass != None: self.supported_databases[db_name].dp_pass = db_pass
|
|
|
|
if db_server != None: self.supported_databases[db_name].dp_server = db_server
|
|
|
|
if db_type != None: self.supported_databases[db_name].dp_type = db_type
|
2008-11-05 11:49:05 +01:00
|
|
|
return
|
2009-08-08 10:07:30 +02:00
|
|
|
|
|
|
|
def getDefaultSite(self):
|
|
|
|
"Returns first enabled site or None"
|
|
|
|
for site_name,site in self.supported_sites.iteritems():
|
|
|
|
if site.enabled:
|
|
|
|
return site_name
|
|
|
|
return None
|
2008-11-05 11:49:05 +01:00
|
|
|
|
2008-10-21 16:22:01 +02:00
|
|
|
def get_tv_parameters(self):
|
|
|
|
tv = {}
|
2009-03-17 04:34:00 +01:00
|
|
|
try: tv['combinedStealFold'] = self.tv.combinedStealFold
|
|
|
|
except: tv['combinedStealFold'] = True
|
|
|
|
|
|
|
|
try: tv['combined2B3B'] = self.tv.combined2B3B
|
|
|
|
except: tv['combined2B3B'] = True
|
|
|
|
|
|
|
|
try: tv['combinedPostflop'] = self.tv.combinedPostflop
|
|
|
|
except: tv['combinedPostflop'] = True
|
2008-10-21 16:22:01 +02:00
|
|
|
return tv
|
2009-10-03 20:05:41 +02:00
|
|
|
|
|
|
|
# Allow to change the menu appearance
|
|
|
|
def get_hud_ui_parameters(self):
|
|
|
|
hui = {}
|
2009-10-15 08:06:31 +02:00
|
|
|
|
2009-10-03 20:05:41 +02:00
|
|
|
default_text = 'FPDB Menu - Right click\nLeft-Drag to Move'
|
|
|
|
try:
|
|
|
|
hui['label'] = self.ui.label
|
|
|
|
if self.ui.label == '': # Empty menu label is a big no-no
|
|
|
|
hui['label'] = default_text
|
|
|
|
except:
|
|
|
|
hui['label'] = default_text
|
2009-10-14 15:04:09 +02:00
|
|
|
|
|
|
|
try: hui['aggregate_ring'] = self.ui.aggregate_ring
|
|
|
|
except: hui['aggregate_ring'] = False
|
|
|
|
|
|
|
|
try: hui['aggregate_tour'] = self.ui.aggregate_tour
|
|
|
|
except: hui['aggregate_tour'] = True
|
|
|
|
|
|
|
|
try: hui['hud_style'] = self.ui.hud_style
|
|
|
|
except: hui['hud_style'] = 'A'
|
|
|
|
|
2009-10-14 18:33:19 +02:00
|
|
|
try: hui['hud_days'] = int(self.ui.hud_days)
|
2009-10-14 15:04:09 +02:00
|
|
|
except: hui['hud_days'] = 90
|
|
|
|
|
|
|
|
try: hui['agg_bb_mult'] = self.ui.agg_bb_mult
|
|
|
|
except: hui['agg_bb_mult'] = 1
|
|
|
|
|
|
|
|
# Hero specific
|
|
|
|
|
|
|
|
try: hui['h_aggregate_ring'] = self.ui.h_aggregate_ring
|
|
|
|
except: hui['h_aggregate_ring'] = False
|
|
|
|
|
|
|
|
try: hui['h_aggregate_tour'] = self.ui.h_aggregate_tour
|
|
|
|
except: hui['h_aggregate_tour'] = True
|
|
|
|
|
|
|
|
try: hui['h_hud_style'] = self.ui.h_hud_style
|
|
|
|
except: hui['h_hud_style'] = 'S'
|
|
|
|
|
2009-10-14 18:33:19 +02:00
|
|
|
try: hui['h_hud_days'] = int(self.ui.h_hud_days)
|
2009-10-14 15:04:09 +02:00
|
|
|
except: hui['h_hud_days'] = 30
|
|
|
|
|
|
|
|
try: hui['h_agg_bb_mult'] = self.ui.h_agg_bb_mult
|
|
|
|
except: hui['h_agg_bb_mult'] = 1
|
|
|
|
|
2009-10-03 20:05:41 +02:00
|
|
|
return hui
|
|
|
|
|
2008-10-21 16:22:01 +02:00
|
|
|
|
|
|
|
def get_import_parameters(self):
|
|
|
|
imp = {}
|
2009-03-17 04:34:00 +01:00
|
|
|
try: imp['callFpdbHud'] = self.imp.callFpdbHud
|
|
|
|
except: imp['callFpdbHud'] = True
|
|
|
|
|
|
|
|
try: imp['interval'] = self.imp.interval
|
|
|
|
except: imp['interval'] = 10
|
|
|
|
|
|
|
|
try: imp['hhArchiveBase'] = self.imp.hhArchiveBase
|
|
|
|
except: imp['hhArchiveBase'] = "~/.fpdb/HandHistories/"
|
|
|
|
|
|
|
|
try: imp['saveActions'] = self.imp.saveActions
|
|
|
|
except: imp['saveActions'] = True
|
|
|
|
|
|
|
|
try: imp['fastStoreHudCache'] = self.imp.fastStoreHudCache
|
|
|
|
except: imp['fastStoreHudCache'] = True
|
2008-10-21 16:22:01 +02:00
|
|
|
return imp
|
|
|
|
|
2009-08-08 10:07:30 +02:00
|
|
|
def get_default_paths(self, site = None):
|
|
|
|
if site is None: site = self.getDefaultSite()
|
2008-10-21 16:22:01 +02:00
|
|
|
paths = {}
|
|
|
|
try:
|
2009-08-08 10:07:30 +02:00
|
|
|
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
|
2009-08-16 11:22:22 +02:00
|
|
|
except AssertionError:
|
|
|
|
paths['hud-defaultPath'] = paths['bulkImport-defaultPath'] = "** ERROR DEFAULT PATH IN CONFIG DOES NOT EXIST **"
|
2008-10-21 16:22:01 +02:00
|
|
|
return paths
|
2009-02-25 21:25:58 +01:00
|
|
|
|
|
|
|
def get_frames(self, site = "PokerStars"):
|
2009-08-06 05:57:26 +02:00
|
|
|
if site not in self.supported_sites: return False
|
2009-03-29 16:08:33 +02:00
|
|
|
return self.supported_sites[site].use_frames == True
|
2008-10-21 16:22:01 +02:00
|
|
|
|
2008-10-30 03:37:05 +01:00
|
|
|
def get_default_colors(self, site = "PokerStars"):
|
|
|
|
colors = {}
|
2009-08-06 05:57:26 +02:00
|
|
|
if site not in self.supported_sites or self.supported_sites[site].hudopacity == "":
|
2009-03-09 11:40:38 +01:00
|
|
|
colors['hudopacity'] = 0.90
|
|
|
|
else:
|
|
|
|
colors['hudopacity'] = float(self.supported_sites[site].hudopacity)
|
2009-08-06 05:57:26 +02:00
|
|
|
if site not in self.supported_sites or self.supported_sites[site].hudbgcolor == "":
|
2009-03-09 11:40:38 +01:00
|
|
|
colors['hudbgcolor'] = "#FFFFFF"
|
|
|
|
else:
|
|
|
|
colors['hudbgcolor'] = self.supported_sites[site].hudbgcolor
|
2009-08-06 05:57:26 +02:00
|
|
|
if site not in self.supported_sites or self.supported_sites[site].hudfgcolor == "":
|
2009-03-09 11:40:38 +01:00
|
|
|
colors['hudfgcolor'] = "#000000"
|
|
|
|
else:
|
|
|
|
colors['hudfgcolor'] = self.supported_sites[site].hudfgcolor
|
2008-10-30 03:37:05 +01:00
|
|
|
return colors
|
2008-12-18 03:57:05 +01:00
|
|
|
|
|
|
|
def get_default_font(self, site = 'PokerStars'):
|
2009-03-09 11:40:38 +01:00
|
|
|
(font, font_size) = ("Sans", "8")
|
2009-08-06 05:57:26 +02:00
|
|
|
if site not in self.supported_sites:
|
|
|
|
return ("Sans", "8")
|
2009-03-09 11:40:38 +01:00
|
|
|
if self.supported_sites[site].font == "":
|
|
|
|
font = "Sans"
|
|
|
|
else:
|
|
|
|
font = self.supported_sites[site].font
|
|
|
|
|
|
|
|
if self.supported_sites[site].font_size == "":
|
|
|
|
font_size = "8"
|
|
|
|
else:
|
|
|
|
font_size = self.supported_sites[site].font_size
|
2008-12-18 03:57:05 +01:00
|
|
|
return (font, font_size)
|
2008-10-30 03:37:05 +01:00
|
|
|
|
|
|
|
def get_locations(self, site = "PokerStars", max = "8"):
|
2009-03-09 11:40:38 +01:00
|
|
|
|
2008-10-30 03:37:05 +01:00
|
|
|
try:
|
|
|
|
locations = self.supported_sites[site].layout[max].location
|
|
|
|
except:
|
|
|
|
locations = ( ( 0, 0), (684, 61), (689, 239), (692, 346),
|
|
|
|
(586, 393), (421, 440), (267, 440), ( 0, 361),
|
|
|
|
( 0, 280), (121, 280), ( 46, 30) )
|
|
|
|
return locations
|
|
|
|
|
2009-03-07 23:02:51 +01:00
|
|
|
def get_aux_locations(self, aux = "mucked", max = "9"):
|
|
|
|
|
|
|
|
try:
|
|
|
|
locations = self.aux_windows[aux].layout[max].location
|
|
|
|
except:
|
|
|
|
locations = ( ( 0, 0), (684, 61), (689, 239), (692, 346),
|
|
|
|
(586, 393), (421, 440), (267, 440), ( 0, 361),
|
|
|
|
( 0, 280), (121, 280), ( 46, 30) )
|
|
|
|
return locations
|
|
|
|
|
2009-03-30 05:40:03 +02:00
|
|
|
def get_supported_sites(self, all = False):
|
2008-11-11 15:40:31 +01:00
|
|
|
"""Returns the list of supported sites."""
|
2009-03-30 05:40:03 +02:00
|
|
|
the_sites = []
|
|
|
|
for site in self.supported_sites.keys():
|
|
|
|
params = self.get_site_parameters(site)
|
|
|
|
if all or params['enabled']:
|
|
|
|
the_sites.append(site)
|
|
|
|
return the_sites
|
2008-11-11 15:40:31 +01:00
|
|
|
|
2008-11-05 22:52:47 +01:00
|
|
|
def get_site_parameters(self, site):
|
|
|
|
"""Returns a dict of the site parameters for the specified site"""
|
|
|
|
parms = {}
|
|
|
|
parms["converter"] = self.supported_sites[site].converter
|
|
|
|
parms["decoder"] = self.supported_sites[site].decoder
|
|
|
|
parms["hudbgcolor"] = self.supported_sites[site].hudbgcolor
|
|
|
|
parms["hudfgcolor"] = self.supported_sites[site].hudfgcolor
|
|
|
|
parms["hudopacity"] = self.supported_sites[site].hudopacity
|
|
|
|
parms["screen_name"] = self.supported_sites[site].screen_name
|
|
|
|
parms["site_path"] = self.supported_sites[site].site_path
|
|
|
|
parms["table_finder"] = self.supported_sites[site].table_finder
|
|
|
|
parms["HH_path"] = self.supported_sites[site].HH_path
|
2008-11-11 15:40:31 +01:00
|
|
|
parms["site_name"] = self.supported_sites[site].site_name
|
2008-11-16 23:53:31 +01:00
|
|
|
parms["aux_window"] = self.supported_sites[site].aux_window
|
2008-12-18 03:57:05 +01:00
|
|
|
parms["font"] = self.supported_sites[site].font
|
|
|
|
parms["font_size"] = self.supported_sites[site].font_size
|
2009-03-30 05:40:03 +02:00
|
|
|
parms["enabled"] = self.supported_sites[site].enabled
|
2009-06-20 15:43:05 +02:00
|
|
|
parms["xpad"] = self.supported_sites[site].xpad
|
|
|
|
parms["ypad"] = self.supported_sites[site].ypad
|
2008-11-05 22:52:47 +01:00
|
|
|
return parms
|
|
|
|
|
|
|
|
def set_site_parameters(self, site_name, converter = None, decoder = None,
|
|
|
|
hudbgcolor = None, hudfgcolor = None,
|
|
|
|
hudopacity = None, screen_name = None,
|
|
|
|
site_path = None, table_finder = None,
|
2008-12-18 03:57:05 +01:00
|
|
|
HH_path = None, enabled = None,
|
|
|
|
font = None, font_size = None):
|
2008-11-05 22:52:47 +01:00
|
|
|
"""Sets the specified site parameters for the specified site."""
|
|
|
|
site_node = self.get_site_node(site_name)
|
2009-03-26 19:57:40 +01:00
|
|
|
if db_node != None:
|
|
|
|
if converter != None: site_node.setAttribute("converter", converter)
|
|
|
|
if decoder != None: site_node.setAttribute("decoder", decoder)
|
|
|
|
if hudbgcolor != None: site_node.setAttribute("hudbgcolor", hudbgcolor)
|
|
|
|
if hudfgcolor != None: site_node.setAttribute("hudfgcolor", hudfgcolor)
|
|
|
|
if hudopacity != None: site_node.setAttribute("hudopacity", hudopacity)
|
|
|
|
if screen_name != None: site_node.setAttribute("screen_name", screen_name)
|
|
|
|
if site_path != None: site_node.setAttribute("site_path", site_path)
|
|
|
|
if table_finder != None: site_node.setAttribute("table_finder", table_finder)
|
|
|
|
if HH_path != None: site_node.setAttribute("HH_path", HH_path)
|
|
|
|
if enabled != None: site_node.setAttribute("enabled", enabled)
|
|
|
|
if font != None: site_node.setAttribute("font", font)
|
|
|
|
if font_size != None: site_node.setAttribute("font_size", font_size)
|
2008-11-05 22:52:47 +01:00
|
|
|
return
|
|
|
|
|
2008-11-16 23:53:31 +01:00
|
|
|
def get_aux_windows(self):
|
|
|
|
"""Gets the list of mucked window formats in the configuration."""
|
|
|
|
mw = []
|
|
|
|
for w in self.aux_windows.keys():
|
|
|
|
mw.append(w)
|
|
|
|
return mw
|
|
|
|
|
|
|
|
def get_aux_parameters(self, name):
|
|
|
|
"""Gets a dict of mucked window parameters from the named mw."""
|
|
|
|
param = {}
|
2009-03-09 11:40:38 +01:00
|
|
|
if self.aux_windows.has_key(name):
|
2008-11-16 23:53:31 +01:00
|
|
|
for key in dir(self.aux_windows[name]):
|
|
|
|
if key.startswith('__'): continue
|
|
|
|
value = getattr(self.aux_windows[name], key)
|
|
|
|
if callable(value): continue
|
|
|
|
param[key] = value
|
|
|
|
|
|
|
|
return param
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_game_parameters(self, name):
|
|
|
|
"""Get the configuration parameters for the named game."""
|
|
|
|
param = {}
|
2009-03-09 11:40:38 +01:00
|
|
|
if self.supported_games.has_key(name):
|
2008-11-16 23:53:31 +01:00
|
|
|
param['game_name'] = self.supported_games[name].game_name
|
|
|
|
param['rows'] = self.supported_games[name].rows
|
|
|
|
param['cols'] = self.supported_games[name].cols
|
2009-06-20 15:43:05 +02:00
|
|
|
param['xpad'] = self.supported_games[name].xpad
|
|
|
|
param['ypad'] = self.supported_games[name].ypad
|
2008-11-16 23:53:31 +01:00
|
|
|
param['aux'] = self.supported_games[name].aux
|
|
|
|
return param
|
|
|
|
|
|
|
|
def get_supported_games(self):
|
|
|
|
"""Get the list of supported games."""
|
|
|
|
sg = []
|
2009-03-09 11:40:38 +01:00
|
|
|
for game in c.supported_games.keys():
|
2008-11-16 23:53:31 +01:00
|
|
|
sg.append(c.supported_games[game].game_name)
|
|
|
|
return sg
|
|
|
|
|
2008-12-13 23:37:23 +01:00
|
|
|
def execution_path(self, filename):
|
|
|
|
"""Join the fpdb path to filename."""
|
2009-03-05 02:12:15 +01:00
|
|
|
return os.path.join(os.path.dirname(inspect.getfile(sys._getframe(0))), filename)
|
2008-12-13 23:37:23 +01:00
|
|
|
|
2008-08-19 00:53:25 +02:00
|
|
|
if __name__== "__main__":
|
|
|
|
c = Config()
|
|
|
|
|
|
|
|
print "\n----------- SUPPORTED SITES -----------"
|
|
|
|
for s in c.supported_sites.keys():
|
|
|
|
print c.supported_sites[s]
|
|
|
|
print "----------- END SUPPORTED SITES -----------"
|
|
|
|
|
|
|
|
|
|
|
|
print "\n----------- SUPPORTED GAMES -----------"
|
|
|
|
for game in c.supported_games.keys():
|
|
|
|
print c.supported_games[game]
|
|
|
|
print "----------- END SUPPORTED GAMES -----------"
|
|
|
|
|
|
|
|
|
|
|
|
print "\n----------- SUPPORTED DATABASES -----------"
|
|
|
|
for db in c.supported_databases.keys():
|
|
|
|
print c.supported_databases[db]
|
|
|
|
print "----------- END SUPPORTED DATABASES -----------"
|
|
|
|
|
2008-11-16 23:53:31 +01:00
|
|
|
print "\n----------- AUX WINDOW FORMATS -----------"
|
|
|
|
for w in c.aux_windows.keys():
|
|
|
|
print c.aux_windows[w]
|
|
|
|
print "----------- END AUX WINDOW FORMATS -----------"
|
2009-03-24 14:58:45 +01:00
|
|
|
|
|
|
|
print "\n----------- HAND HISTORY CONVERTERS -----------"
|
|
|
|
for w in c.hhcs.keys():
|
|
|
|
print c.hhcs[w]
|
|
|
|
print "----------- END HAND HISTORY CONVERTERS -----------"
|
2008-10-21 16:22:01 +02:00
|
|
|
|
2008-09-15 22:31:55 +02:00
|
|
|
print "\n----------- POPUP WINDOW FORMATS -----------"
|
|
|
|
for w in c.popup_windows.keys():
|
|
|
|
print c.popup_windows[w]
|
2008-11-16 23:53:31 +01:00
|
|
|
print "----------- END POPUP WINDOW FORMATS -----------"
|
2008-09-15 22:31:55 +02:00
|
|
|
|
2008-10-21 16:22:01 +02:00
|
|
|
print "\n----------- IMPORT -----------"
|
2008-12-03 18:01:37 +01:00
|
|
|
print c.imp
|
2008-10-21 16:22:01 +02:00
|
|
|
print "----------- END IMPORT -----------"
|
|
|
|
|
|
|
|
print "\n----------- TABLE VIEW -----------"
|
2008-10-30 03:37:05 +01:00
|
|
|
# print c.tv
|
2008-10-21 16:22:01 +02:00
|
|
|
print "----------- END TABLE VIEW -----------"
|
|
|
|
|
2008-09-15 22:31:55 +02:00
|
|
|
c.edit_layout("PokerStars", 6, locations=( (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6) ))
|
2008-10-05 02:22:53 +02:00
|
|
|
c.save(file="testout.xml")
|
|
|
|
|
2008-10-30 03:37:05 +01:00
|
|
|
print "db = ", c.get_db_parameters()
|
|
|
|
# print "tv = ", c.get_tv_parameters()
|
|
|
|
# print "imp = ", c.get_import_parameters()
|
|
|
|
print "paths = ", c.get_default_paths("PokerStars")
|
|
|
|
print "colors = ", c.get_default_colors("PokerStars")
|
|
|
|
print "locs = ", c.get_locations("PokerStars", 8)
|
2008-11-16 23:53:31 +01:00
|
|
|
for mw in c.get_aux_windows():
|
|
|
|
print c.get_aux_parameters(mw)
|
2009-03-07 23:02:51 +01:00
|
|
|
|
|
|
|
print "mucked locations =", c.get_aux_locations('mucked', 9)
|
2009-03-15 20:54:22 +01:00
|
|
|
# c.edit_aux_layout('mucked', 9, locations = [(487, 113), (555, 469), (572, 276), (522, 345),
|
|
|
|
# (333, 354), (217, 341), (150, 273), (150, 169), (230, 115)])
|
|
|
|
# print "mucked locations =", c.get_aux_locations('mucked', 9)
|
2009-03-11 19:12:56 +01:00
|
|
|
|
2008-11-05 22:52:47 +01:00
|
|
|
for site in c.supported_sites.keys():
|
|
|
|
print "site = ", site,
|
2008-11-06 06:39:49 +01:00
|
|
|
print c.get_site_parameters(site)
|
2008-12-18 03:57:05 +01:00
|
|
|
print c.get_default_font(site)
|
2008-11-16 23:53:31 +01:00
|
|
|
|
|
|
|
for game in c.get_supported_games():
|
|
|
|
print c.get_game_parameters(game)
|
2008-12-13 23:37:23 +01:00
|
|
|
|
2009-02-19 13:15:12 +01:00
|
|
|
print "start up path = ", c.execution_path("")
|