changes to make consolidated config files happier

This commit is contained in:
Ray 2008-11-02 22:58:55 -05:00
parent b5ec60f5fa
commit 0f10f87373
2 changed files with 75 additions and 18 deletions

View File

@ -205,24 +205,19 @@ class Config:
sys.stderr.write("Configuration file %s not found. Using defaults." % (file))
file = None
# if "file" is invalid or None, we look for a HUD_config in the cwd
if file == None: # configuration file path not passed or invalid
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
# find the path to the default HUD_config for the current os
if os.name == 'posix':
config_path = os.path.join(os.path.expanduser("~"), '.fpdb', 'HUD_config.xml')
elif os.name == 'nt':
config_path = os.path.join(os.environ["APPDATA"], 'fpdb', 'HUD_config.xml')
else: config_path = False
file = self.find_config() #Look for a config file in the normal places
if config_path and os.path.exists(config_path):
file = config_path
else:
print "No HUD_config_xml found. Exiting"
sys.stderr.write("No HUD_config_xml found. Exiting")
sys.exit()
if file == None: # no config file in the normal places
file = self.find_example_config() #Look for an example file to edit
if file == None: # that didn't work either, just die
print "No HUD_config_xml found. Exiting"
sys.stderr.write("No HUD_config_xml found. Exiting")
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
try:
print "Reading configuration file %s\n" % (file)
doc = xml.dom.minidom.parse(file)
@ -274,6 +269,68 @@ class Config:
tv = Tv(node = tv_node)
self.tv = tv
db = self.get_db_parameters('fpdb')
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)
self.supported_databases['fpdb'].db_pass = df_parms['db-password']
self.supported_databases['fpdb'].db_ip = df_parms['db-host']
self.supported_databases['fpdb'].db_user = df_parms['db-user']
def find_config(self):
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
# find the path to the default HUD_config for the current os
if os.name == 'posix':
config_path = os.path.join(os.path.expanduser("~"), '.fpdb', 'HUD_config.xml')
elif os.name == 'nt':
config_path = os.path.join(os.environ["APPDATA"], 'fpdb', 'HUD_config.xml')
else: config_path = False
if config_path and os.path.exists(config_path):
file = config_path
else:
file = None
return file
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 = {}
fh = open(file, "r")
for line in fh:
line = string.strip(line)
(key, value) = line.split('=')
parms[key] = value
fh.close
return parms
def find_example_config(self):
if os.path.exists('HUD_config.xml.example'): # there is a HUD_config in the cwd
file = 'HUD_config.xml.example' # so we use it
print "No HUD_config.xml found, using HUD_config.xml.example.\n", \
"A HUD_config.xml will be written. You will probably have to edit it."
sys.stderr.write("No HUD_config.xml found, using HUD_config.xml.example.\n" + \
"A HUD_config.xml will be written. You will probably have to edit it.")
else:
file = None
return file
def get_site_node(self, site):
for site_node in self.doc.getElementsByTagName("site"):
if site_node.getAttribute("site_name") == site:

View File

@ -2,7 +2,7 @@
<FreePokerToolsConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FreePokerToolsConfig.xsd">
<supported_sites>
<site site_name="PokerStars" table_finder="PokerStars" screen_name="DO NOT NEED THIS YET" site_path="~/.wine/drive_c/Program Files/PokerStars/" HH_path="~/.wine/drive_c/Program Files/PokerStars/HandHistory/abc/" decoder="pokerstars_decode_table">
<site site_name="PokerStars" table_finder="PokerStars" screen_name="DO NOT NEED THIS YET" site_path="~/.wine/drive_c/Program Files/PokerStars/" HH_path="" decoder="pokerstars_decode_table">
<layout max="8" width="792" height="546" fav_seat="0">
<location seat="1" x="684" y="61"> </location>
<location seat="2" x="689" y="239"> </location>