summaryrefslogtreecommitdiffstats
path: root/xlators/features/marker/utils/syncdaemon/configinterface.py
diff options
context:
space:
mode:
authorCsaba Henk <csaba@gluster.com>2011-04-02 19:40:48 +0000
committerVijay Bellur <vijay@dev.gluster.com>2011-04-04 08:02:22 -0700
commite77c35248e8ce796bc5b108c10013089a0c65bde (patch)
tree10e7eda370a3bb9c35ed3f965e84c2063ca47195 /xlators/features/marker/utils/syncdaemon/configinterface.py
parentcfb9c834f96dc57c47dac8d27da4266d0dab1f3f (diff)
syncdaemon: provide transactional semantics to config file writing
So updating the config file from multiple contexts won't mess it up. This prepares the next commit where we'll set options internaly (which lacks the serial nature of user actions). Signed-off-by: Csaba Henk <csaba@gluster.com> Signed-off-by: Vijay Bellur <vijay@dev.gluster.com> BUG: 2537 (gsync autorestart) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2537
Diffstat (limited to 'xlators/features/marker/utils/syncdaemon/configinterface.py')
-rw-r--r--xlators/features/marker/utils/syncdaemon/configinterface.py31
1 files changed, 18 insertions, 13 deletions
diff --git a/xlators/features/marker/utils/syncdaemon/configinterface.py b/xlators/features/marker/utils/syncdaemon/configinterface.py
index cda7da7eb..a1079d803 100644
--- a/xlators/features/marker/utils/syncdaemon/configinterface.py
+++ b/xlators/features/marker/utils/syncdaemon/configinterface.py
@@ -109,19 +109,19 @@ class GConffile(object):
continue
print("%s: %s" % (k, v))
- def write(self):
- if not self.config.has_section(SECT_META):
- self.config.add_section(SECT_META)
- self.config.set(SECT_META, 'version', config_version)
- f = None
- try:
- f = open(self.path, 'wb')
+ def write(self, trfn, *a, **kw):
+ def mergeconf(f):
+ self.config = ConfigParser.RawConfigParser()
+ self.config.readfp(f)
+ def updateconf(f):
+ if not self.config.has_section(SECT_META):
+ self.config.add_section(SECT_META)
+ self.config.set(SECT_META, 'version', config_version)
+ trfn(*a, **kw)
self.config.write(f)
- finally:
- if f:
- f.close()
+ syncdutils.update_file(self.path, updateconf, mergeconf)
- def set(self, opt, val, rx=False):
+ def _set(self, opt, val, rx=False):
sect = self.section(rx)
if not self.config.has_section(sect):
self.config.add_section(sect)
@@ -130,11 +130,16 @@ class GConffile(object):
self.config.add_section(SECT_ORD)
self.config.set(SECT_ORD, sect, len(self.config._sections[SECT_ORD]))
self.config.set(sect, opt, val)
- self.write()
- def delete(self, opt, rx=False):
+ def set(self, *a, **kw):
+ self.write(self._set, *a, **kw)
+
+ def _delete(self, opt, rx=False):
sect = self.section(rx)
if not self.config.has_section(sect):
return
if self.config.remove_option(sect, opt):
self.write()
+
+ def delete(self, *a, **kw):
+ self.write(self._delete, *a, **kw)