Make it easier to exclude directories for VCSes from resource trees.

This commit is contained in:
Eric S. Raymond 2009-12-21 21:40:51 +00:00
parent 64ad6085c0
commit ee929c7ef2

View file

@ -8,6 +8,7 @@ import sys, os, re, sre_constants, hashlib, glob, gzip
map_extensions = ("map", "mask")
image_extensions = ("png", "jpg", "jpeg")
sound_extensions = ("ogg", "wav")
vc_directories = (".git", ".svn")
resource_extensions = map_extensions + image_extensions + sound_extensions
image_reference = r"[A-Za-z0-9{}.][A-Za-z0-9_/+{}.-]*\.(png|jpg)(?=(~.*)?)"
@ -74,7 +75,7 @@ def parse_attribute(line):
class Forest:
"Return an iterable directory forest object."
def __init__(self, dirpath, exclude=None):
"Get the names of all files under dirpath, ignoring .svn and .git directories."
"Get the names of all files under dirpath, ignoring version-control directories."
self.forest = []
self.dirpath = dirpath
for dir in dirpath:
@ -88,7 +89,9 @@ class Forest:
self.forest.append(subtree)
for i in range(len(self.forest)):
# Ignore version-control subdirectories and Emacs tempfiles
self.forest[i] = filter(lambda x: ".svn" not in x and ".git" not in x and '.#' not in x, self.forest[i])
for dirkind in vc_directories:
self.forest[i] = filter(lambda x: dirkind not in x, self.forest[i])
self.forest[i] = filter(lambda x: '.#' not in x, self.forest[i])
self.forest[i] = filter(lambda x: not os.path.isdir(x), self.forest[i])
if exclude:
self.forest[i] = filter(lambda x: not re.search(exclude, x), self.forest[i])