From f18cc00c0d1e7055eb34cdd2f9f8739903ce5b2f Mon Sep 17 00:00:00 2001 From: Mika Bostrom Date: Tue, 17 Aug 2010 08:18:46 +0300 Subject: [PATCH] Move sample copying after fallback test Only try to copy the example HUD_config.xml after fallback has been tested against, and even then only on platform where the debian path can exist --- pyfpdb/Configuration.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/pyfpdb/Configuration.py b/pyfpdb/Configuration.py index ae578f57..d1f0efec 100755 --- a/pyfpdb/Configuration.py +++ b/pyfpdb/Configuration.py @@ -84,18 +84,26 @@ def get_config(file_name, fallback = True): # print "config path 2=", config_path if os.path.exists(config_path): return (config_path,False) - # Copy from example (debian package) - try: - example_path = '/usr/share/python-fpdb/' + file_name + '.example' - shutil.copyfile(example_path, config_path) - return (config_path,False) - except IOError: - pass # No file found if not fallback: return (False,False) +# Example configuration for debian package + if os.name == 'posix': + # If we're on linux, try to copy example from the place + # debian package puts it; get_default_config_path() creates + # the config directory for us so there's no need to check it + # again + example_path = '/usr/share/python-fpdb/' + file_name + '.example' + try: + shutil.copyfile(example_path, config_path) + msg = 'Configuration file created: %s\n' % config_path + logging.info(msg) + return (config_path,False) + except IOError: + pass + # OK, fall back to the .example file, should be in the start dir if os.path.exists(file_name + ".example"): try: