[tor-bugs] #4913 [Stem]: Add stem.util.conf.Config.save()
Tor Bug Tracker & Wiki
torproject-admin at torproject.org
Sun Jan 15 18:25:19 UTC 2012
#4913: Add stem.util.conf.Config.save()
-------------------------+--------------------------------------------------
Reporter: gsathya | Owner: atagar
Type: enhancement | Status: new
Priority: normal | Milestone:
Component: Stem | Version:
Keywords: | Parent:
Points: | Actualpoints:
-------------------------+--------------------------------------------------
Added a new save method that saves the current config contents into the
configuration file by overwriting the old one.
{{{
def save(self):
self._contents_lock.acquire()
with open(path, 'w') as f:
for entry in self.keys():
f.write('%s %s\n' % (entry, self.get(entry)))
self._contents_lock.release()
}}}
If we want to retain the comments --
{{{
def save(self):
self._contents_lock.acquire()
with open(path, 'w') as f:
for line in self._raw_contents:
key, value = ""
comment_start = line.find("#")
if comment_start != -1:
comment = line[comment_start:]
line = line[:comment_start]
line = line.strip()
if line:
try:
key, value = line.split(" ", 1)
except ValueError:
key, value = line, ""
f.write("%s %s %s\n" % (key, self.get(key, value), comment)
self._contents_lock.release()
}}}
Since we strip the lines, we don't really know what the formatting is
like. This messes up the white spaces a bit.
Do we have an alternative? Or is one these fine?
--
Ticket URL: <https://trac.torproject.org/projects/tor/ticket/4913>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online
More information about the tor-bugs
mailing list