From de2b807c9b5d98d7f71ff2d4fb221dfa1d74676b Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Tue, 26 Jan 2010 21:54:58 +0000 Subject: [PATCH] refine hud_config handling some more (copies .exmaple to proper dir) --- pyfpdb/Configuration.py | 20 ++++++++++++-------- run_fpdb.py | 5 ++++- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/pyfpdb/Configuration.py b/pyfpdb/Configuration.py index 80ef0277..11d38bf4 100755 --- a/pyfpdb/Configuration.py +++ b/pyfpdb/Configuration.py @@ -56,8 +56,7 @@ def get_exec_path(): if hasattr(sys, "frozen"): # compiled by py2exe return os.path.dirname(sys.executable) else: - pathname = os.path.dirname(sys.argv[0]) - return os.path.abspath(pathname) + return sys.path[0] def get_config(file_name, fallback = True): """Looks in cwd and in self.default_config_path for a config file.""" @@ -78,14 +77,19 @@ def get_config(file_name, fallback = True): # OK, fall back to the .example file, should be in the start dir if os.path.exists(file_name + ".example"): try: - shutil.copyfile(file_name + ".example", file_name) + shutil.copyfile(file_name + ".example", config_path) print "No %s found, using %s.example.\n" % (file_name, file_name) - print "A %s file has been created. You will probably have to edit it." % file_name - sys.stderr.write("No %s found, using %s.example.\n" % (file_name, file_name) ) + print "Config file has been created at %s.\nYou will probably have to edit it." % config_path + sys.stderr.write("No %s found, copying %s.example.\n" % (file_name, file_name) ) + file_name = config_path except: - print "No %s found, cannot fall back. Exiting.\n" % file_name - sys.stderr.write("No %s found, cannot fall back. Exiting.\n" % file_name) + print "Error copying .example file, cannot fall back. Exiting.\n" + sys.stderr.write("Error copying .example file, cannot fall back. Exiting.\n") sys.exit() + else: + print "No %s found, cannot fall back. Exiting.\n" % file_name + sys.stderr.write("No %s found, cannot fall back. Exiting.\n" % file_name) + sys.exit() return file_name def get_logger(file_name, config = "config", fallback = False): @@ -408,7 +412,7 @@ class Config: sys.stderr.write("Configuration file %s not found. Using defaults." % (file)) file = None - if file is None: file = get_config("HUD_config.xml") + if file is None: file = get_config("HUD_config.xml", True) # 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 diff --git a/run_fpdb.py b/run_fpdb.py index a5c06952..24f6a4dd 100755 --- a/run_fpdb.py +++ b/run_fpdb.py @@ -19,8 +19,11 @@ import os import sys -# sys.path[0] holds the dir run_fpdb.py was in +# sys.path[0] holds the directory run_fpdb.py is in sys.path[0] = sys.path[0]+os.sep+"pyfpdb" +os.chdir(sys.path[0]) +#print "sys.path[0] =", sys.path[0], "cwd =", os.getcwd() + import fpdb