[tor-commits] [stem/master] Updated config.save()
atagar at torproject.org
atagar at torproject.org
Thu Feb 9 03:19:36 UTC 2012
commit d48aadd31678e6a4dd670a4e23832a3d563c4072
Author: Sathyanarayanan Gunasekaran <gsathya.ceg at gmail.com>
Date: Thu Feb 9 00:05:19 2012 +0530
Updated config.save()
- Added Pydocs
- Added handling of multi-line entries
- Added path argument
- Changed single letter variable 'f' to 'output_file'
- Instead of calling sort() on config.keys() and
iterate over it, we pass config.keys() to sorted().
---
stem/util/conf.py | 31 ++++++++++++++++++-------------
1 files changed, 18 insertions(+), 13 deletions(-)
diff --git a/stem/util/conf.py b/stem/util/conf.py
index fe8ab68..b88dd10 100644
--- a/stem/util/conf.py
+++ b/stem/util/conf.py
@@ -250,21 +250,26 @@ class Config():
self._contents_lock.release()
# TODO: pending improvements...
- # - missing pydocs
- # - integ testing
- # - does not yet handle multi-line entries
- # - should have an optional path argument
- def save(self):
- self._contents_lock.acquire()
-
- config_keys = self.keys()
- config_keys.sort()
+ # - integ testing
+ def save(self, path = None):
+ """
+ Saves configuration contents to the config file or to the path
+ specified.
+
+ If path is not None, then the default path for this config handler
+ updated to the argument passed.
+ """
- with open(path, 'w') as f:
- for entry_key in config_keys:
+ self._contents_lock.acquire()
+
+ if path:
+ self.path = path
+
+ with open(self._path, 'w') as output_file:
+ for entry_key in sorted(self.keys()):
for entry_value in self.get_value(entry_key, multiple = True):
- f.write('%s %s\n' % (entry_key, entry_value))
-
+ output_file.write('%s\n|%s\n' % (entry_key, entry_value.replace("\n", "\n|")))
+
self._contents_lock.release()
def clear(self):
More information about the tor-commits
mailing list