aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Bachelier <laurent@bachelier.name>2010-03-14 14:55:38 +0100
committerLaurent Bachelier <laurent@bachelier.name>2010-03-14 14:55:38 +0100
commit0107a098c4a5a4b344cf801a53e8923520306ddc (patch)
treeddf9c0ee94ac0514a13a0c8e08ad8286e51bea35
parentUse __file__ instead of argv[0] (diff)
downloadconfman-0107a098c4a5a4b344cf801a53e8923520306ddc.tar.xz
Simplifies API; comments
Only one method for end-users: sync()
-rw-r--r--confman.py13
-rwxr-xr-xexample.py2
2 files changed, 10 insertions, 5 deletions
diff --git a/confman.py b/confman.py
index 43e86f8..7b3e349 100644
--- a/confman.py
+++ b/confman.py
@@ -171,7 +171,13 @@ class ConfigSource(object):
else:
self.options = []
+ def sync(self):
+ "gather files and synchronize them"
+ self.analyze()
+ self.execute()
+
def analyze(self):
+ "gather all files"
def walker(_, path, files):
relpath = os.path.relpath(path, self.source)
for filename in (file for file in files \
@@ -182,6 +188,7 @@ class ConfigSource(object):
os.path.walk(self.source, walker, None)
def add(self, relpath, filename):
+ "add a file if it can be associated to an action"
def get_file_class(filename):
for cls in self.classes:
dest = cls.matches(filename)
@@ -197,15 +204,15 @@ class ConfigSource(object):
raise Exception('Conflict: '+filename+' with '+files[dest])
files[dest] = cls(self, relpath, filename, dest)
- def check(self):
+ def execute(self):
+ "executes all actions if everything is alright"
for file in self:
file.check()
-
- def sync(self):
for file in self:
file.sync()
def __iter__(self):
+ "iterate over all analyzed files"
for files in self.tree.itervalues():
for file in files.itervalues():
yield file
diff --git a/example.py b/example.py
index 7e58dbf..408fb65 100755
--- a/example.py
+++ b/example.py
@@ -11,8 +11,6 @@ from os import path
samples_path = path.join(path.dirname(__file__), 'samples')
c = ConfigSource(samples_path, "/tmp/dotfiles-test", None, options)
-c.analyze()
-c.check()
c.sync()
print