Ignore hidden files in directories
authorFlavio Percoco <flaper87@gmail.com>
Fri, 13 Jan 2017 13:09:00 +0000 (14:09 +0100)
committerFlavio Percoco <flaper87@gmail.com>
Mon, 23 Jan 2017 13:01:08 +0000 (14:01 +0100)
Don't walk through hidden files. This avoids going through the .git,
.tox and other hidden directories that we don't care about.

Change-Id: I34b83229775d221299c8b572a7049175debac99d

tools/process-templates.py

index 9a06812..381214b 100755 (executable)
@@ -78,6 +78,18 @@ def process_templates(template_path, role_data_path, overwrite):
 
     if os.path.isdir(template_path):
         for subdir, dirs, files in os.walk(template_path):
+
+            # NOTE(flaper87): Ignore hidden dirs as we don't
+            # generate templates for those.
+            # Note the slice assigment for `dirs` is necessary
+            # because we need to modify the *elements* in the
+            # dirs list rather than the reference to the list.
+            # This way we'll make sure os.walk will iterate over
+            # the shrunk list. os.walk doesn't have an API for
+            # filtering dirs at this point.
+            dirs[:] = [d for d in dirs if not d[0] == '.']
+            files = [f for f in files if not f[0] == '.']
+
             for f in files:
                 file_path = os.path.join(subdir, f)
                 # We do two templating passes here: