diff options
author | Csaba Henk <csaba@gluster.com> | 2011-02-07 20:42:24 +0000 |
---|---|---|
committer | Anand V. Avati <avati@dev.gluster.com> | 2011-02-10 22:17:54 -0800 |
commit | 07402f590e12b097e8267e924e0ae69d9b8964fb (patch) | |
tree | 5828f0b4514ad36516509ff119cbf2a6b4d5b5a2 /configinterface.py | |
parent | ebd7e1771c69a056f0456ff2dccac4319806f63b (diff) |
syncdaemon: config revamp #3: implement command line get/set/del interface to configuration
The INI style config file has following type of sections:
- [global]
- [peers <local>]
- [peers <local> <remote>]
Option dispatch to sections is derived from command line (ie., [global]
if no arg given, [peers <local>] with <local> being the only arg,
[peers <local> <remote>] if <local> and <remote> args are provided).
So this all happens under the hood, gsyncd users need not to specify
sections.
New command line options:
- query options:
--config-get-all
--config-get OPT
- modify options:
--config-set OPT VAL
--config-del OPT
Signed-off-by: Csaba Henk <csaba@gluster.com>
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
BUG: 1570 (geosync related changes)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1570
Diffstat (limited to 'configinterface.py')
-rw-r--r-- | configinterface.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/configinterface.py b/configinterface.py new file mode 100644 index 00000000000..7bc1d4731a7 --- /dev/null +++ b/configinterface.py @@ -0,0 +1,50 @@ +import ConfigParser + +DEF_SECT = 'global' + +class GConffile(object): + + def __init__(self, path, peers): + if peers: + self.section = 'peers ' + ' '.join(peers) + else: + self.section = DEF_SECT + self.path = path + self.config = ConfigParser.RawConfigParser({}, dict) + self.config.read(path) + + def update_to(self, dct): + for sect in set([DEF_SECT, self.section]): + if self.config.has_section(sect): + dct.update(self.config._sections[sect]) + + def get(self, opt=None): + d = {} + self.update_to(d) + if opt: + d = {opt: d.get(opt, "")} + for k, v in d.iteritems(): + if k == '__name__': + continue + print("%s: %s" % (k, v)) + + def write(self): + f = None + try: + f = open(self.path, 'wb') + self.config.write(f) + finally: + if f: + f.close() + + def set(self, opt, val): + if not self.config.has_section(self.section): + self.config.add_section(self.section) + self.config.set(self.section, opt, val) + self.write() + + def delete(self, opt): + if not self.config.has_section(self.section): + return + if self.config.remove_option(self.section, opt): + self.write() |