linux (and probably mac): fix copying of example config in case of missing config file
This commit is contained in:
parent
43b071515d
commit
d6b3197fb6
|
@ -78,7 +78,6 @@ def get_exec_path():
|
||||||
|
|
||||||
def get_config(file_name, fallback = True):
|
def get_config(file_name, fallback = True):
|
||||||
"""Looks in cwd and in self.default_config_path for a config file."""
|
"""Looks in cwd and in self.default_config_path for a config file."""
|
||||||
|
|
||||||
# look for example file even if not used here, path is returned to caller
|
# look for example file even if not used here, path is returned to caller
|
||||||
config_found,example_found,example_copy = False,False,False
|
config_found,example_found,example_copy = False,False,False
|
||||||
config_path, example_path = None,None
|
config_path, example_path = None,None
|
||||||
|
@ -88,17 +87,17 @@ def get_config(file_name, fallback = True):
|
||||||
config_path = os.path.join(exec_dir, 'pyfpdb', file_name)
|
config_path = os.path.join(exec_dir, 'pyfpdb', file_name)
|
||||||
else:
|
else:
|
||||||
config_path = os.path.join(exec_dir, file_name)
|
config_path = os.path.join(exec_dir, file_name)
|
||||||
# print "config_path=", config_path
|
#print "config_path=", config_path
|
||||||
if os.path.exists(config_path): # there is a file in the cwd
|
if os.path.exists(config_path): # there is a file in the cwd
|
||||||
config_found = True # so we use it
|
config_found = True # so we use it
|
||||||
else: # no file in the cwd, look where it should be in the first place
|
else: # no file in the cwd, look where it should be in the first place
|
||||||
default_dir = get_default_config_path()
|
default_dir = get_default_config_path()
|
||||||
config_path = os.path.join(default_dir, file_name)
|
config_path = os.path.join(default_dir, file_name)
|
||||||
# print "config path 2=", config_path
|
#print "config path 2=", config_path
|
||||||
if os.path.exists(config_path):
|
if os.path.exists(config_path):
|
||||||
config_found = True
|
config_found = True
|
||||||
|
|
||||||
# Example configuration for debian package
|
# Example configuration for debian package
|
||||||
if os.name == 'posix':
|
if os.name == 'posix':
|
||||||
# If we're on linux, try to copy example from the place
|
# If we're on linux, try to copy example from the place
|
||||||
# debian package puts it; get_default_config_path() creates
|
# debian package puts it; get_default_config_path() creates
|
||||||
|
@ -111,6 +110,13 @@ def get_config(file_name, fallback = True):
|
||||||
example_copy = True
|
example_copy = True
|
||||||
msg = _("Config file has been created at %s.\n") % config_path
|
msg = _("Config file has been created at %s.\n") % config_path
|
||||||
logging.info(msg)
|
logging.info(msg)
|
||||||
|
except IOError:
|
||||||
|
try:
|
||||||
|
example_path = file_name + '.example'
|
||||||
|
shutil.copyfile(example_path, config_path)
|
||||||
|
example_copy = True
|
||||||
|
msg = _("Config file has been created at %s.\n") % config_path
|
||||||
|
logging.info(msg)
|
||||||
except IOError:
|
except IOError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user