1
0
mirror of https://github.com/gryf/wicd.git synced 2026-02-17 06:35:45 +01:00

committed patch to fix Python 2.7 support and use python2 instead of python to run monitor.py -- thanks to Archlinux and Rémy Oudompheng

This commit is contained in:
Adam Blackburn
2010-10-27 11:17:15 -05:00
parent e773b3b1f3
commit 194714c7e7
2 changed files with 21 additions and 14 deletions

View File

@@ -35,7 +35,7 @@ from dbus import Int32
class ConfigManager(RawConfigParser): class ConfigManager(RawConfigParser):
""" A class that can be used to manage a given configuration file. """ """ A class that can be used to manage a given configuration file. """
def __init__(self, path, debug=False, mark_whitespace="`'`"): def __init__(self, path, debug=False, mark_whitespace="`'`"):
RawConfigParser.__init__(self) RawConfigParser.__init__(self, allow_no_value=True)
self.config_file = path self.config_file = path
self.debug = debug self.debug = debug
self.mrk_ws = mark_whitespace self.mrk_ws = mark_whitespace
@@ -185,28 +185,35 @@ class ConfigManager(RawConfigParser):
def _copy_section(self, name): def _copy_section(self, name):
# Yes, deepcopy sucks, but it is robust to changes in both p = ConfigManager("", self.debug, self.mrk_ws)
# this class and RawConfigParser. p.add_section(name)
p = copy.deepcopy(self) for (iname, value) in self.items(name):
for sname in p.sections(): p.set(name, iname, value)
if sname != name: # Store the filename this section was read from.
p.remove_section(sname)
p.config_file = p.get_option(name, '_filename_', p.config_file) p.config_file = p.get_option(name, '_filename_', p.config_file)
p.remove_option(name, '_filename_') p.remove_option(name, '_filename_')
return p return p
def write(self): def write(self):
""" Writes the loaded config file to disk. """ """ Writes the loaded config file to disk. """
# Really don't like this deepcopy. in_this_file = []
p = copy.deepcopy(self) for sname in self.sections():
for sname in p.sections(): fname = self.get_option(sname, '_filename_')
fname = p.get_option(sname, '_filename_')
if fname and fname != self.config_file: if fname and fname != self.config_file:
# Write sections from other files
section = self._copy_section(sname) section = self._copy_section(sname)
p.remove_section(sname)
section._write_one() section._write_one()
else:
# Save names of local sections
in_this_file.append(sname)
for sname in p.sections(): # Make an instance with only these sections
p = ConfigManager("", self.debug, self.mrk_ws)
p.config_file = self.config_file
for sname in in_this_file:
p.add_section(sname)
for (iname, value) in self.items(sname):
p.set(sname, iname, value)
p.remove_option(sname, '_filename_') p.remove_option(sname, '_filename_')
p._write_one() p._write_one()

View File

@@ -1806,7 +1806,7 @@ def main(argv):
wicd_bus = dbus.service.BusName('org.wicd.daemon', bus=bus) wicd_bus = dbus.service.BusName('org.wicd.daemon', bus=bus)
daemon = WicdDaemon(wicd_bus, auto_connect=auto_connect) daemon = WicdDaemon(wicd_bus, auto_connect=auto_connect)
if not no_poll: if not no_poll:
child_pid = Popen([misc.find_path("python"), "-O", child_pid = Popen([misc.find_path("python2"), "-O",
os.path.join(wpath.daemon, "monitor.py")], os.path.join(wpath.daemon, "monitor.py")],
shell=False, close_fds=True).pid shell=False, close_fds=True).pid
atexit.register(on_exit, child_pid) atexit.register(on_exit, child_pid)