summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Oros <poros@redhat.com>2013-06-19 16:50:05 +0200
committerArnaldo Carvalho de Melo <acme@redhat.com>2013-07-24 12:01:42 -0300
commited8e0fc14abd4380c0d2a1f3f8e13a1654213be5 (patch)
tree5b1e8bb87e3be465ffeb06e53a0d92dd5df844ca
parentef83898c745462832d88d6bcf5b706544436f32f (diff)
downloadtuna-ed8e0fc14abd4380c0d2a1f3f8e13a1654213be5.tar.gz
tuna: Auto Correction for config file errors BZ:974035
Description of problem: when tuna is launched on some custom kernel with missing /proc/sys entry, configuration is not loaded. Steps to Reproduce: 1. edit /etc/tuna/example.conf and put there nonsense /proc/sys entry with some value (e.g. kernel.crap = 1000 to [kernel] section) 2. run runa 3. check results Actual results: dialog with warning 'File not found: /proc/sys/kernel.crap' appears 'Profile management' tab not loaded BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=974035 Signed-off-by: Petr Oros <poros@redhat.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tuna/config.py25
-rw-r--r--tuna/gui/commonview.py31
-rw-r--r--tuna/gui/profileview.py21
3 files changed, 69 insertions, 8 deletions
diff --git a/tuna/config.py b/tuna/config.py
index 599a211..8701fbf 100644
--- a/tuna/config.py
+++ b/tuna/config.py
@@ -329,6 +329,7 @@ class Config:
return snapFileName
def checkConfigFile(self, filename):
+ self.empty = True
try:
msgStack = ''
if not os.path.exists(filename):
@@ -344,13 +345,31 @@ class Config:
for opt,val in current:
if not os.path.exists("/proc/sys/" + opt.replace(".","/")) and len(self.getFilesByFN("/proc/sys/",opt.replace(".","/"))) == 0:
msgStack = "%s%s%s\n" % (msgStack, _("Warning: File not found: /proc/sys/"), opt)
- #pos = [val.start() for val in re.finditer(',', val)]
- #if len(pos) > 0 and len(pos) != 2:
- # msgStack = msgStack + "Error: slider value format is LOW,HIGH,CURRENT. Value: " + opt + "\n"
+ self.empty = False
+ if self.empty:
+ msgStack = "%s%s" % (msgStack, _("Empty config File"))
return msgStack
except (ConfigParser.Error, IOError) as e:
return "Error {0}".format(str(e))
+ def fixConfigFile(self, filename):
+ try:
+ self.checkParser = ConfigParser.RawConfigParser()
+ self.checkParser.read(filename)
+ for option,value in self.checkParser.items('categories'):
+ if not self.checkParser.items(option):
+ self.checkParser.remove_option('categories', option)
+ self.checkParser.set('categories', '#' + option, value)
+ current = self.checkParser.items(option)
+ for opt,val in current:
+ if not os.path.exists("/proc/sys/" + opt.replace(".", "/")) and len(self.getFilesByFN("/proc/sys/", opt.replace(".", "/"))) == 0:
+ self.checkParser.remove_option(option, opt)
+ self.checkParser.set(option, '#' + opt, val)
+ except (ConfigParser.Error, IOError) as e:
+ return "Error {0}".format(str(e))
+ with open(filename, 'w') as configfile:
+ self.checkParser.write(configfile)
+
def isFnString(self, string):
regMatch = ['[', '*', '?']
for char in regMatch:
diff --git a/tuna/gui/commonview.py b/tuna/gui/commonview.py
index 4d018f5..199f0e0 100644
--- a/tuna/gui/commonview.py
+++ b/tuna/gui/commonview.py
@@ -187,12 +187,36 @@ class commonview:
ret = self.get_current_combo_selection()
if ret[0] < 0:
return False
+ self.restoreConfig = False
err = self.config.checkConfigFile(self.config.config['root']+ret[1])
if err != '':
- dialog = gtk.MessageDialog(None, 0, gtk.MESSAGE_ERROR,\
- gtk.BUTTONS_OK, (_("Config file contain errors: %s") % (err)))
- ret = dialog.run()
+ self.restoreConfig = True
+ dialog = gtk.MessageDialog(None,
+ gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
+ gtk.MESSAGE_WARNING, gtk.BUTTONS_YES_NO,
+ _("Config file contain errors: \n%s\nRun autocorrect?") % _(err))
+ dlgret = dialog.run()
dialog.destroy()
+ if dlgret == gtk.RESPONSE_YES:
+ self.config.fixConfigFile(self.config.config['root'] + ret[1])
+ err = self.config.checkConfigFile(self.config.config['root'] + ret[1])
+ if err != '':
+ dialog = gtk.MessageDialog(None,
+ gtk.DIALOG_DESTROY_WITH_PARENT,
+ gtk.MESSAGE_ERROR, gtk.BUTTONS_OK,
+ _("Config file contain errors: \n%s\nAutocorrect failed!") % _(err))
+ dialog.run()
+ dialog.destroy()
+ self.restoreConfig = True
+ else:
+ dialog = gtk.MessageDialog(None,
+ gtk.DIALOG_DESTROY_WITH_PARENT,
+ gtk.MESSAGE_INFO, gtk.BUTTONS_OK,
+ _("Autocorrect OK"))
+ dialog.run()
+ dialog.destroy()
+ self.restoreConfig = False
+ if self.restoreConfig:
old = self.config.cacheFileName.rfind("/")
old = self.config.cacheFileName[old+1:len(self.config.cacheFileName)]
cur = self.configFileCombo.get_model()
@@ -211,6 +235,7 @@ class commonview:
self.config.loadTuna(ret[1])
self.config.updateDefault(ret[1])
self.updateCommonView()
+ return True
def get_current_combo_selection(self):
combo_iter = self.configFileCombo.get_active_iter()
diff --git a/tuna/gui/profileview.py b/tuna/gui/profileview.py
index 96c4479..4fd99da 100644
--- a/tuna/gui/profileview.py
+++ b/tuna/gui/profileview.py
@@ -149,8 +149,25 @@ class profileview:
else:
self.frame.hide()
except RuntimeError as e:
- self.show_mbox_warning(_("Default %s" % str(e)))
- self.frame.hide()
+ dialog = gtk.MessageDialog(None,
+ gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
+ gtk.MESSAGE_WARNING, gtk.BUTTONS_YES_NO,
+ _("%s\nRun autocorect?") % _(str(e)))
+ dlgret = dialog.run()
+ dialog.destroy()
+ if dlgret == gtk.RESPONSE_YES:
+ if 'lastfile' in self.config.config:
+ self.config.fixConfigFile(self.config.config['root'] + self.config.config['lastfile'])
+ err = self.config.checkConfigFile(self.config.config['root'] + self.config.config['lastfile'])
+ if err != '':
+ self.show_mbox_warning(_("Default %s" % str(err)))
+ self.frame.hide()
+ else:
+ self.init_default_file()
+ else:
+ self.frame.hide()
+ else:
+ self.frame.hide()
def on_profileTree_button_press_event(self, treeview, event):
if event.button == 3: