Copy original file in backup_files method instead of renaming it in case write_config_file fails.

Add a 'none' entry to the implementation list.
This commit is contained in:
Ferdi Franceschini
2014-07-03 23:36:43 +10:00
parent 294b6fa776
commit abcf19553b

View File

@ -22,6 +22,7 @@
import os
import shutil
import argparse
import ConfigParser
import urwid
@ -221,11 +222,15 @@ class InstConfigData:
for s in self.file_parser.sections():
if self.file_parser.has_option(s, 'imptype'):
key = self.file_parser.get(s, 'imptype')
if 'none' not in self.imp_dict[key]:
self.imp_dict[key].append('none')
self.imp_dict[key].append(s)
if s not in self.imp2opt_dict:
print 'Add imp2opt_dict[{0}] = none'.format(s)
self.imp2opt_dict[s] = "none"
def read_config_file(self, config_filename):
self.config_filename = config_filename
self.file_parser = ConfigParser.SafeConfigParser()
@ -241,11 +246,11 @@ class InstConfigData:
os.rename(self.config_filename + "." + str(idx),
self.config_filename + "." + str(idx + 1))
if os.path.exists(self.config_filename):
os.rename(self.config_filename, self.config_filename + ".1")
shutil.copy(self.config_filename, self.config_filename + ".1")
def write_config_file(self):
for item,dict in self.opt_dict.iteritems():
if self.file_parser.get(item, 'enabled').lower() == 'always':
if 'permanent' in dict and dict['permanent'] == True:
enabled = 'Always'
else:
enabled = dict['enabled'].__str__()
@ -259,7 +264,7 @@ class InstConfigData:
self.file_parser.set(item, 'enabled', enabled)
for imp,opt in self.imp2opt_dict.iteritems():
if imp != 'none' and 'id' in self.opt_dict[opt]:
if imp != 'none' and opt != 'none' and 'id' in self.opt_dict[opt]:
self.file_parser.set(imp, 'id', self.opt_dict[opt]['id'])
with open(self.config_filename,'w') as cfile:
@ -338,7 +343,7 @@ class InstConfigManager:
else:
imp_items.append((imp, False))
imp_items.sort()
imp_items = imp_items[:1] + sorted(imp_items[1:])
return RadioButtonListWalker(imp_items, on_state_change=self.imp_statechange, user_data=opt)