[bug 802] 802-Ability-to-undo-or-restore-changes-to-the-preferences #802
- fixed the errors in case of missing configs - restore file is stored in writable path
This commit is contained in:
parent
2fe3ad8b08
commit
6fc6d7f658
|
@ -713,22 +713,55 @@ class ConfigBase(Borg):
|
||||||
return filename
|
return filename
|
||||||
|
|
||||||
def save_config_with_suffix(self, suffix):
|
def save_config_with_suffix(self, suffix):
|
||||||
filename = self.get_config_filename()
|
try:
|
||||||
#save the current config, to revert any changes make in preferences
|
filename = self.get_config_filename()
|
||||||
cur_loaded_file = filename + suffix
|
|
||||||
shutil.copy2(filename, cur_loaded_file)
|
#save the current config, to revert any changes make in preferences
|
||||||
|
#save the current config to config_dir path which is at least writable
|
||||||
|
cfg_filename = os.path.join(get_config_dir(), 'config')
|
||||||
|
cur_loaded_file = cfg_filename + suffix
|
||||||
|
|
||||||
|
if os.path.exists(filename) and cur_loaded_file:
|
||||||
|
dbg('copy file:%s to' \
|
||||||
|
' file:%s' % (filename, cur_loaded_file))
|
||||||
|
shutil.copy2(filename, cur_loaded_file)
|
||||||
|
elif cur_loaded_file:
|
||||||
|
open(cur_loaded_file, 'a').close()
|
||||||
|
else:
|
||||||
|
err('ConfigBase:: Unable to get filename to save')
|
||||||
|
except Exception as ex:
|
||||||
|
err('ConfigBase::save_config_with_suffix' \
|
||||||
|
' Unable to save config: %s' % ex)
|
||||||
|
|
||||||
def restore_config_with_suffix(self, suffix):
|
def restore_config_with_suffix(self, suffix):
|
||||||
filename = self.get_config_filename()
|
try:
|
||||||
cur_loaded_file = filename + suffix
|
filename = self.get_config_filename()
|
||||||
dbg("restoring from file:%s to file:%s" % (cur_loaded_file, filename))
|
|
||||||
shutil.copy2(cur_loaded_file, filename)
|
cfg_filename = os.path.join(get_config_dir(), 'config')
|
||||||
|
cur_loaded_file = cfg_filename + suffix
|
||||||
|
if os.path.exists(cur_loaded_file):
|
||||||
|
if not os.access(filename, os.W_OK):
|
||||||
|
dbg('path:%s not writable' \
|
||||||
|
' restoring to path:%s' % (filename,cfg_filename))
|
||||||
|
filename = cfg_filename
|
||||||
|
|
||||||
|
dbg('restore from file:%s to file:%s'
|
||||||
|
% (cur_loaded_file, filename))
|
||||||
|
shutil.copy2(cur_loaded_file, filename)
|
||||||
|
except Exception as ex:
|
||||||
|
err('ConfigBase::restore_config_with_suffix' \
|
||||||
|
' Unable to restore config: %s' % ex)
|
||||||
|
|
||||||
def remove_config_with_suffix(self, suffix):
|
def remove_config_with_suffix(self, suffix):
|
||||||
filename = self.get_config_filename()
|
try:
|
||||||
cur_loaded_file = filename + suffix
|
cfg_filename = os.path.join(get_config_dir(), 'config')
|
||||||
if os.path.exists(cur_loaded_file):
|
cur_loaded_file = cfg_filename + suffix
|
||||||
os.remove(cur_loaded_file)
|
if os.path.exists(cur_loaded_file):
|
||||||
|
dbg('remove file:%s' % (cur_loaded_file))
|
||||||
|
os.remove(cur_loaded_file)
|
||||||
|
except Exception as ex:
|
||||||
|
err('ConfigBase::remove_config_with_suffix' \
|
||||||
|
' Unable to remove config: %s' % ex)
|
||||||
|
|
||||||
def reload(self):
|
def reload(self):
|
||||||
"""Force a reload of the base config"""
|
"""Force a reload of the base config"""
|
||||||
|
@ -795,7 +828,8 @@ class ConfigBase(Borg):
|
||||||
open(filename, 'a').close()
|
open(filename, 'a').close()
|
||||||
|
|
||||||
backup_file = filename + '~'
|
backup_file = filename + '~'
|
||||||
shutil.copy2(filename, backup_file)
|
if os.path.exists(filename):
|
||||||
|
shutil.copy2(filename, backup_file)
|
||||||
|
|
||||||
with open(filename, 'wb') as fh:
|
with open(filename, 'wb') as fh:
|
||||||
parser.write(fh)
|
parser.write(fh)
|
||||||
|
|
Loading…
Reference in New Issue