1
From: Matthieu Baerts <matttbe@gmail.com>
2
Subject: Added the compatibility with python2.7
3
Origin: vendor, http://repos.archlinux.org/wsvn/packages/wicd/trunk/deepcopy%2Bpython27-fixes.patch
4
Origin: upstream, http://bazaar.launchpad.net/~wicd-devel/wicd/experimental/revision/564
5
Bug: https://bugs.launchpad.net/wicd/+bug/602825
9
wicd/configmanager.py | 39 +++++++++++++++++++++++----------------
10
1 file changed, 23 insertions(+), 16 deletions(-)
12
--- wicd.orig/wicd/configmanager.py
13
+++ wicd/wicd/configmanager.py
14
@@ -24,7 +24,7 @@ reusable for other purposes as well.
15
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
from ConfigParser import RawConfigParser, ParsingError
23
@@ -35,7 +35,10 @@ from dbus import Int32
24
class ConfigManager(RawConfigParser):
25
""" A class that can be used to manage a given configuration file. """
26
def __init__(self, path, debug=False, mark_whitespace="`'`"):
27
- RawConfigParser.__init__(self)
28
+ if sys.version_info >= (2, 7, 0):
29
+ RawConfigParser.__init__(self, allow_no_value=True)
31
+ RawConfigParser.__init__(self)
32
self.config_file = path
34
self.mrk_ws = mark_whitespace
35
@@ -46,7 +49,6 @@ class ConfigManager(RawConfigParser):
38
except ParsingError, p:
40
print "Could not start wicd: %s" % p.message
43
@@ -185,28 +187,33 @@ class ConfigManager(RawConfigParser):
46
def _copy_section(self, name):
47
- # Yes, deepcopy sucks, but it is robust to changes in both
48
- # this class and RawConfigParser.
49
- p = copy.deepcopy(self)
50
- for sname in p.sections():
52
- p.remove_section(sname)
53
+ p = ConfigManager("", self.debug, self.mrk_ws)
55
+ for (iname, value) in self.items(name):
56
+ p.set(name, iname, value)
57
+ # Store the filename this section was read from.
58
p.config_file = p.get_option(name, '_filename_', p.config_file)
59
p.remove_option(name, '_filename_')
63
""" Writes the loaded config file to disk. """
64
- # Really don't like this deepcopy.
65
- p = copy.deepcopy(self)
66
- for sname in p.sections():
67
- fname = p.get_option(sname, '_filename_')
69
+ for sname in self.sections():
70
+ fname = self.get_option(sname, '_filename_')
71
if fname and fname != self.config_file:
72
section = self._copy_section(sname)
73
- p.remove_section(sname)
76
+ # Save names of local sections
77
+ in_this_file.append(sname)
79
- for sname in p.sections():
80
+ # Make an instance with only these sections
81
+ p = ConfigManager("", self.debug, self.mrk_ws)
82
+ p.config_file = self.config_file
83
+ for sname in in_this_file:
84
+ p.add_section(sname)
85
+ for (iname, value) in self.items(sname):
86
+ p.set(sname, iname, value)
87
p.remove_option(sname, '_filename_')