~reyammer/wicd/bug-476982

« back to all changes in this revision

Viewing changes to debian/patches/06-dont_bomb_out_on_configparser_error.patch

  • Committer: Bazaar Package Importer
  • Author(s): David Paleino
  • Date: 2009-11-07 16:59:06 UTC
  • mfrom: (8.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20091107165906-hed2k3kf24limqlg
Tags: 1.6.2.2-3
* debian/po/ja.po updated (Closes: #554838)
* debian/patches/06-dont_bomb_out_on_configparser_error.patch added
  (Closes: #554949)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
From: David Paleino <d.paleino@gmail.com>
 
2
Subject: gracefully handle (and try to fix) configuration parsing errors
 
3
 From time to time, it happens that an empty section "[]" is added to
 
4
 wired-settings.conf. (Un)fortunately, RawConfigParser doesn't seem to
 
5
 remove it with self.remove_section(""), but it automagically disappears
 
6
 if the configfile is re-written again. Exceptions on errors are caught
 
7
 if that was not the error.
 
8
Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=553197
 
9
 http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=554949
 
10
Forwarded: no
 
11
 
 
12
---
 
13
 wicd/configmanager.py |   15 ++++++++++++---
 
14
 1 file changed, 12 insertions(+), 3 deletions(-)
 
15
 
 
16
--- wicd.orig/wicd/configmanager.py
 
17
+++ wicd/wicd/configmanager.py
 
18
@@ -24,7 +24,7 @@ reusable for other purposes as well.
 
19
 #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
 #
 
21
 
 
22
-from ConfigParser import RawConfigParser
 
23
+from ConfigParser import RawConfigParser, ParsingError
 
24
 
 
25
 from wicd.misc import Noneify, to_unicode
 
26
 
 
27
@@ -37,8 +37,17 @@ class ConfigManager(RawConfigParser):
 
28
         self.config_file = path
 
29
         self.debug = debug
 
30
         self.mrk_ws = mark_whitespace
 
31
-        self.read(path)
 
32
-        
 
33
+        try:
 
34
+            self.read(path)
 
35
+        except ParsingError, e:
 
36
+            self.write()
 
37
+            try:
 
38
+                self.read(path)
 
39
+            except ParsingError, p:
 
40
+                import sys
 
41
+                print "Could not start wicd: %s" % p.message
 
42
+                sys.exit(1)
 
43
+
 
44
     def __repr__(self):
 
45
         return self.config_file
 
46