diff options
author | Aravinda VK <avishwan@redhat.com> | 2014-03-21 12:33:10 +0530 |
---|---|---|
committer | Vijay Bellur <vbellur@redhat.com> | 2014-04-07 21:56:55 -0700 |
commit | 238d101e55e067e5afcd43c728884e9ab8d36549 (patch) | |
tree | 60498b107335c0ae526bfa034bd56303406710ab /geo-replication/syncdaemon/configinterface.py | |
parent | 0c20b17c09b2eca82f3c79013fd3fe1c72a957fd (diff) |
geo-rep: code pep8/flake8 fixes
pep8 is a style guide for python.
http://legacy.python.org/dev/peps/pep-0008/
pep8 can be installed using, `pip install pep8`
Usage: `pep8 <python file>`, For example, `pep8 master.py`
will display all the coding standard errors.
flake8 is used to identify unused imports and other issues
in code.
pip install flake8
cd $GLUSTER_REPO/geo-replication/
flake8 syncdaemon
Updated license headers to each source file.
Change-Id: I01c7d0a6091d21bfa48720e9fb5624b77fa3db4a
Signed-off-by: Aravinda VK <avishwan@redhat.com>
Reviewed-on: http://review.gluster.org/7311
Reviewed-by: Kotresh HR <khiremat@redhat.com>
Reviewed-by: Prashanth Pai <ppai@redhat.com>
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Diffstat (limited to 'geo-replication/syncdaemon/configinterface.py')
-rw-r--r-- | geo-replication/syncdaemon/configinterface.py | 57 |
1 files changed, 43 insertions, 14 deletions
diff --git a/geo-replication/syncdaemon/configinterface.py b/geo-replication/syncdaemon/configinterface.py index 35f754c98c9..c4d47b5dbda 100644 --- a/geo-replication/syncdaemon/configinterface.py +++ b/geo-replication/syncdaemon/configinterface.py @@ -1,3 +1,13 @@ +# +# Copyright (c) 2011-2014 Red Hat, Inc. <http://www.redhat.com> +# This file is part of GlusterFS. + +# This file is licensed to you under your choice of the GNU Lesser +# General Public License, version 3 or any later version (LGPLv3 or +# later), or the GNU General Public License, version 2 (GPLv2), in all +# cases as published by the Free Software Foundation. +# + try: import ConfigParser except ImportError: @@ -21,14 +31,25 @@ config_version = 2.0 re_type = type(re.compile('')) - # (SECTION, OPTION, OLD VALUE, NEW VALUE) CONFIGS = ( - ("peersrx . .", "georep_session_working_dir", "", "/var/lib/glusterd/geo-replication/${mastervol}_${remotehost}_${slavevol}/"), - ("peersrx .", "gluster_params", "aux-gfid-mount xlator-option=\*-dht.assert-no-child-down=true", "aux-gfid-mount"), - ("peersrx . .", "ssh_command_tar", "", "ssh -oPasswordAuthentication=no -oStrictHostKeyChecking=no -i /var/lib/glusterd/geo-replication/tar_ssh.pem"), + ("peersrx . .", + "georep_session_working_dir", + "", + "/var/lib/glusterd/geo-replication/${mastervol}_${remotehost}_" + "${slavevol}/"), + ("peersrx .", + "gluster_params", + "aux-gfid-mount xlator-option=\*-dht.assert-no-child-down=true", + "aux-gfid-mount"), + ("peersrx . .", + "ssh_command_tar", + "", + "ssh -oPasswordAuthentication=no -oStrictHostKeyChecking=no " + "-i /var/lib/glusterd/geo-replication/tar_ssh.pem"), ) + def upgrade_config_file(path): config_change = False config = ConfigParser.RawConfigParser() @@ -72,7 +93,9 @@ def upgrade_config_file(path): class MultiDict(object): - """a virtual dict-like class which functions as the union of underlying dicts""" + + """a virtual dict-like class which functions as the union + of underlying dicts""" def __init__(self, *dd): self.dicts = dd @@ -80,14 +103,15 @@ class MultiDict(object): def __getitem__(self, key): val = None for d in self.dicts: - if d.get(key) != None: + if d.get(key) is not None: val = d[key] - if val == None: + if val is None: raise KeyError(key) return val class GConffile(object): + """A high-level interface to ConfigParser which flattens the two-tiered config layout by implenting automatic section dispatch based on initial parameters. @@ -155,7 +179,8 @@ class GConffile(object): return self.get(opt, printValue=False) def section(self, rx=False): - """get the section name of the section representing .peers in .config""" + """get the section name of the section representing .peers + in .config""" peers = self.peers if not peers: peers = ['.', '.'] @@ -209,6 +234,7 @@ class GConffile(object): continue so2[s] = tv tv += 1 + def scmp(x, y): return cmp(*(so2[s] for s in (x, y))) ss.sort(scmp) @@ -218,12 +244,13 @@ class GConffile(object): """update @dct from key/values of ours. key/values are collected from .config by filtering the regexp sections - according to match, and from .section. The values are treated as templates, - which are substituted from .auxdicts and (in case of regexp sections) - match groups. + according to match, and from .section. The values are treated as + templates, which are substituted from .auxdicts and (in case of regexp + sections) match groups. """ if not self.peers: raise GsyncdError('no peers given, cannot select matching options') + def update_from_sect(sect, mud): for k, v in self.config._sections[sect].items(): if k == '__name__': @@ -243,7 +270,7 @@ class GConffile(object): match = False break for j in range(len(m.groups())): - mad['match%d_%d' % (i+1, j+1)] = m.groups()[j] + mad['match%d_%d' % (i + 1, j + 1)] = m.groups()[j] if match: update_from_sect(sect, MultiDict(dct, mad, *self.auxdicts)) if self.config.has_section(self.section()): @@ -255,7 +282,7 @@ class GConffile(object): logic described in .update_to) """ d = {} - self.update_to(d, allow_unresolved = True) + self.update_to(d, allow_unresolved=True) if opt: opt = norm(opt) v = d.get(opt) @@ -283,6 +310,7 @@ class GConffile(object): self.config.add_section(SECT_META) self.config.set(SECT_META, 'version', config_version) return trfn(norm(opt), *a, **kw) + def updateconf(f): self.config.write(f) update_file(self.path, updateconf, mergeconf) @@ -295,7 +323,8 @@ class GConffile(object): # regarding SECT_ORD, cf. ord_sections if not self.config.has_section(SECT_ORD): self.config.add_section(SECT_ORD) - self.config.set(SECT_ORD, sect, len(self.config._sections[SECT_ORD])) + self.config.set( + SECT_ORD, sect, len(self.config._sections[SECT_ORD])) self.config.set(sect, opt, val) return True |