summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCsaba Henk <csaba@gluster.com>2011-02-07 20:42:22 +0000
committerAnand V. Avati <avati@dev.gluster.com>2011-02-10 22:17:42 -0800
commitd6363c595ace12a1bf9060dcd76a9e88e58d3db0 (patch)
treed790521dd6f4e456fdcb640b41e1566e06eda861
parent71888401e2b959db316a9a296580d1e1c0c3a882 (diff)
syncdaemon: config revamp #1: drop simplecfg, switch to stdlib's ConfigParser
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
-rw-r--r--xlators/features/marker/utils/syncdaemon/gsyncd.py30
-rw-r--r--xlators/features/marker/utils/syncdaemon/simplecfg.py77
2 files changed, 13 insertions, 94 deletions
diff --git a/xlators/features/marker/utils/syncdaemon/gsyncd.py b/xlators/features/marker/utils/syncdaemon/gsyncd.py
index 4d8b9f96dab..d02b05d0c31 100644
--- a/xlators/features/marker/utils/syncdaemon/gsyncd.py
+++ b/xlators/features/marker/utils/syncdaemon/gsyncd.py
@@ -8,6 +8,7 @@ import logging
import signal
import select
import shutil
+import ConfigParser
import optparse
from optparse import OptionParser, SUPPRESS_HELP
from logging import Logger
@@ -15,7 +16,6 @@ from errno import EEXIST, ENOENT
from gconf import gconf
import resource
-from simplecfg import SimpleCfg
class GLogger(Logger):
@@ -188,27 +188,23 @@ def main_i():
sys.stderr.write(op.get_usage() + "\n")
sys.exit(1)
- gconf.__dict__.update(defaults.__dict__)
- # XXX add global config support
- if not 'config_file' in rconf:
- rconf['config_file'] = os.path.join(os.path.dirname(sys.argv[0]), "conf/gsyncd.conf")
- try:
- cfg = SimpleCfg()
- cfg.read(rconf['config_file'])
- gconf.__dict__.update(cfg)
- except IOError:
- ex = sys.exc_info()[1]
- if ex.errno != ENOENT:
- raise
- gconf.__dict__.update(opts.__dict__)
-
local = resource.parse_url(args[0])
remote = None
if len(args) > 1:
remote = resource.parse_url(args[1])
-
if not local.can_connect_to(remote):
raise RuntimeError("%s cannot work with %s" % (local.path, remote and remote.path))
+ peers = [x.url for x in [local, remote] if x]
+
+ gconf.__dict__.update(defaults.__dict__)
+ if not 'config_file' in rconf:
+ rconf['config_file'] = os.path.join(os.path.dirname(sys.argv[0]), "conf/gsyncd.conf")
+ cfg = ConfigParser.RawConfigParser({}, dict)
+ cfg.read(rconf['config_file'])
+ for sect in ('global', 'peers ' + ' '.join(peers)):
+ if cfg.has_section(sect):
+ gconf.__dict__.update(cfg._sections[sect])
+ gconf.__dict__.update(opts.__dict__)
go_daemon = rconf['go_daemon']
@@ -219,7 +215,7 @@ def main_i():
log_file = gconf.log_file
startup(go_daemon=go_daemon, log_file=log_file, slave=(not remote))
- logging.info("syncing: %s" % " -> ".join([x.url for x in [local, remote] if x]))
+ logging.info("syncing: %s" % " -> ".join(peers))
if remote:
go_daemon = remote.connect_remote(go_daemon=go_daemon)
if go_daemon:
diff --git a/xlators/features/marker/utils/syncdaemon/simplecfg.py b/xlators/features/marker/utils/syncdaemon/simplecfg.py
deleted file mode 100644
index fc3863ef4e7..00000000000
--- a/xlators/features/marker/utils/syncdaemon/simplecfg.py
+++ /dev/null
@@ -1,77 +0,0 @@
-import re
-import tempfile
-import os
-
-CommentRe = re.compile('\s*(#|$)')
-ParseRe = re.compile('\s*(\S+):\s+(.*\S)\s+$')
-
-class SimpleCfgError(Exception):
- pass
-
-class SimpleCfg(dict):
- """
- Read/write support for a simple config file format.
- Entries can be of the form "key: value".
- "#" comments are supported. Whitespace-only lines are ignored.
- """
-
- def __init__(self, *a, **kw):
- dict.__init__(self, *a, **kw)
- self.klist = dict.keys(self)
-
- def __setitem__(self, k, v):
- k = k.replace('-', '_')
- if not k in self:
- self.klist.append(k)
- dict.__setitem__(self, k, v)
-
- def __iter__(self):
- return self.klist.__iter__()
-
- def keys(self):
- return self.klist
-
- def pop(self, key, *a):
- e = dict.pop(self, key, *a)
- self.klist.remove(key)
- return e
-
- def readstream(self, s):
- while True:
- l = s.readline()
- if not l:
- break
- m = ParseRe.match(l)
- if m:
- k, v = m.groups()
- self[k] = v
- elif not CommentRe.match(l):
- raise SimpleCfgError('syntax error')
-
- def writestream(self, s):
- for k in self:
- s.write('%s: %s\n' % (k, self[k]))
-
- def read(self, file):
- f = None
- try:
- f = open(file)
- self.readstream(f)
- finally:
- if f:
- f.close()
-
- def write(self, file):
- tfd = None
- tfil = None
- try:
- tfd, tname = tempfile.mkstemp(dir=os.path.dirname(file))
- tfil, tfd = os.fdopen(tfd, 'w'), None
- self.writestream(tfil)
- os.fsync(tfil.fileno())
- os.rename(tname, file)
- finally:
- if tfd != None:
- os.close(tfd)
- if tfil != None:
- tfil.close()