aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Bachelier <laurent@bachelier.name>2012-03-22 17:23:22 +0100
committerLaurent Bachelier <laurent@bachelier.name>2012-03-22 17:45:57 +0100
commite6e9e01177620c5145535803edd2257b7889b41d (patch)
tree49979bfd1713c0012f89176f4d0864f3a4868917
parentAllow directories to act as files (diff)
downloadconfman-e6e9e01177620c5145535803edd2257b7889b41d.tar.xz
Use os.walk, fix directory walk removal
* os.path.walk is deprecated, and os.walk is nicer * don't remove elements from the list we are iterating * don't crash if dest is None in add_dir()
-rw-r--r--confman.py25
1 files changed, 14 insertions, 11 deletions
diff --git a/confman.py b/confman.py
index 49a7077..42a9661 100644
--- a/confman.py
+++ b/confman.py
@@ -365,19 +365,22 @@ class ConfigSource(object):
"""
Gather all files.
"""
- def walker(_, path, files):
+ self.tree = {}
+ for path, dirs, files in os.walk(self.source, topdown=True):
relpath = osp_relpath(path, self.source)
- for filename in files:
- isdir = osp.isdir(osp.join(path, filename))
- if isdir and self.act_as_file.search(filename):
- # this list can be modified in place
- files.remove(filename)
+
+ to_remove = []
+ for filename in dirs:
+ if self.act_as_file.search(filename):
+ to_remove.append(filename)
self.add_dir(relpath, filename)
- elif not isdir:
- self.add(relpath, filename)
+ for filename in to_remove:
+ # this list can be modified in place
+ # but we wust no remove elements when iterating on it!
+ dirs.remove(filename)
- self.tree = {}
- osp.walk(self.source, walker, None)
+ for filename in files:
+ self.add(relpath, filename)
def _get_file_class(self, filename):
"""
@@ -409,8 +412,8 @@ class ConfigSource(object):
The destination will be deduced, and it will check for conflicts.
"""
cls, dest = self._get_file_class(filename)
- dest = self.act_as_file.sub("", dest)
if dest is not None:
+ dest = self.act_as_file.sub("", dest)
return self._add(relpath, filename, cls, dest)
def _add(self, relpath, filename, cls, dest):