diff options
author | Laurent Bachelier <laurent@bachelier.name> | 2010-03-14 14:55:38 +0100 |
---|---|---|
committer | Laurent Bachelier <laurent@bachelier.name> | 2010-03-14 14:55:38 +0100 |
commit | 0107a098c4a5a4b344cf801a53e8923520306ddc (patch) | |
tree | ddf9c0ee94ac0514a13a0c8e08ad8286e51bea35 | |
parent | Use __file__ instead of argv[0] (diff) | |
download | confman-0107a098c4a5a4b344cf801a53e8923520306ddc.tar.xz |
Simplifies API; comments
Only one method for end-users: sync()
-rw-r--r-- | confman.py | 13 | ||||
-rwxr-xr-x | example.py | 2 |
2 files changed, 10 insertions, 5 deletions
@@ -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 @@ -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 |