aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Bachelier <laurent@bachelier.name>2011-05-05 20:51:42 +0200
committerLaurent Bachelier <laurent@bachelier.name>2011-05-05 20:51:42 +0200
commitf8a911be9a086bdcd050dc9cd7a029dc8ba73d00 (patch)
tree85c952cfce765c35c1ae1394826682ffc99bb795
parentChanged + to % for building strings (diff)
downloadconfman-f8a911be9a086bdcd050dc9cd7a029dc8ba73d00.tar.xz
PEP8 fixes
-rw-r--r--confman.py45
1 files changed, 27 insertions, 18 deletions
diff --git a/confman.py b/confman.py
index 59828db..fc27c38 100644
--- a/confman.py
+++ b/confman.py
@@ -21,7 +21,7 @@ except ImportError:
# Work out how much of the filepath is shared by start and path.
i = len(osp.commonprefix([start_list, path_list]))
- rel_list = [osp.pardir] * (len(start_list)-i) + path_list[i:]
+ rel_list = [osp.pardir] * (len(start_list) - i) + path_list[i:]
if not rel_list:
return osp.curdir
return osp.join(*rel_list)
@@ -33,13 +33,14 @@ class ConfmanException(Exception):
"""
pass
+
class ActionException(ConfmanException):
def __init__(self, action, value):
self.action = action
- super(self.__class__, self).__init__(value)
+ ConfmanException.__init__(self, value)
def __str__(self):
- return "%s (%s)" % (super(self.__class__, self).__str__(), repr(self.action))
+ return "%s (%s)" % (ConfmanException.__str__(self), repr(self.action))
class Action(object):
@@ -60,7 +61,8 @@ class Action(object):
self.dest = dest
def __repr__(self):
- return "%s: %s => %s" % (self.__class__.__name__, osp.join(self.relpath, self.source), self.dest)
+ return "%s: %s => %s" % (self.__class__.__name__,
+ osp.join(self.relpath, self.source), self.dest)
def check(self):
raise NotImplementedError()
@@ -95,7 +97,8 @@ class SymlinkAction(Action):
dest = self.dest_path()
if osp.lexists(dest):
if not osp.islink(dest):
- raise ActionException(self, "Destination exists and is not a link")
+ raise ActionException(self,
+ "Destination exists and is not a link")
def sync(self):
source = self.source_path()
@@ -113,7 +116,8 @@ class SymlinkAction(Action):
else:
self._makedirs()
- relsource = osp.normpath(osp_relpath(source, osp.join(self.config.dest, self.relpath)))
+ relsource = osp.normpath(osp_relpath(source,
+ osp.join(self.config.dest, self.relpath)))
os.symlink(relsource, dest)
print "Created new link: %s => %s" % (dest, source)
@@ -217,12 +221,14 @@ class SymlinkForwarder(Forwarder):
self.filename = filename
def get_proxy(self, parent):
- return SymlinkAction(parent.config, parent.relpath, self.filename, parent.dest)
+ return SymlinkAction(parent.config, parent.relpath,
+ self.filename, parent.dest)
class EmptyForwarder(Forwarder):
def get_proxy(self, parent):
- return EmptyAction(parent.config, parent.relpath, None, parent.dest)
+ return EmptyAction(parent.config, parent.relpath,
+ None, parent.dest)
class TextForwarder(Forwarder):
@@ -231,7 +237,8 @@ class TextForwarder(Forwarder):
def get_proxy(self, parent):
# The text is passed as source
- return TextAction(parent.config, parent.relpath, self.text, parent.dest)
+ return TextAction(parent.config, parent.relpath,
+ self.text, parent.dest)
class IgnoreForwarder(Forwarder):
@@ -265,12 +272,12 @@ class ProgrammableAction(Action):
raise IgnoreForwarder()
class ConfmanTemplate(Template):
- def render(self, _strict = True, _warning = True, **kws):
- if _warning and not kws.has_key("warning"):
- kws["warning"] = "WARNING: Do not edit this file, edit the template instead."
+ def render(self, _strict=True, _warning=True, **kwargs):
+ if _warning and "warning" not in kwargs:
+ kwargs["warning"] = "WARNING: Do not edit this file, edit the template instead."
if _strict:
- raise TextForwarder(self.substitute(kws))
- raise TextForwarder(self.safe_substitute(kws))
+ raise TextForwarder(self.substitute(kwargs))
+ raise TextForwarder(self.safe_substitute(kwargs))
def template(name):
source = osp.join(osp.dirname(self.source_path()), "_%s" % name)
@@ -302,7 +309,8 @@ class ProgrammableAction(Action):
return self.proxy.sync()
def __repr__(self):
- return "%s: %s => PROXY %s" % (self.__class__.__name__, self.source, repr(self.proxy))
+ return "%s: %s => PROXY %s" % (self.__class__.__name__,
+ self.source, repr(self.proxy))
class IgnoreAction(Action):
@@ -317,6 +325,7 @@ class IgnoreAction(Action):
def __repr__(self):
return "%s: %s => IGNORED" % (self.__class__.__name__, self.source)
+
DEFAULT_CLASSES = [
ProgrammableAction,
IgnoreAction,
@@ -326,8 +335,9 @@ DEFAULT_CLASSES = [
SymlinkAction,
]
+
class ConfigSource(object):
- def __init__(self, source, dest, classes = None, options = None):
+ def __init__(self, source, dest, classes=None, options=None):
# handle '~'
self.source = osp.expanduser(source)
self.dest = osp.expanduser(dest)
@@ -376,7 +386,7 @@ class ConfigSource(object):
if dest is not None:
files = self.tree.setdefault(relpath, {})
- if files.has_key(dest):
+ if dest in files:
raise ConfmanException("Conflict: %s with %s" % (filename, files[dest]))
files[dest] = cls(self, relpath, filename, dest)
@@ -400,4 +410,3 @@ class ConfigSource(object):
def __repr__(self):
return "\n".join(\
("%s: %s" % (action.relpath, repr(action)) for action in self))
-