summaryrefslogtreecommitdiff
path: root/sphinx/util
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2010-01-07 16:39:59 +0100
committerGeorg Brandl <georg@python.org>2010-01-07 16:39:59 +0100
commit6aaac900333341f58ca319ee0850e20af4214093 (patch)
tree76a1fa6c492b3063bde201ab4a967b2727c6b001 /sphinx/util
parent34d2bc8c08362196e90716156255b408da3caee6 (diff)
downloadsphinx-6aaac900333341f58ca319ee0850e20af4214093.tar.gz
Apply static path exclusion patterns again.
Refactor exclusion stuff a bit, so that matchers only have to be compiled once.
Diffstat (limited to 'sphinx/util')
-rw-r--r--sphinx/util/__init__.py29
1 files changed, 18 insertions, 11 deletions
diff --git a/sphinx/util/__init__.py b/sphinx/util/__init__.py
index 2dbec72f..ab277f4a 100644
--- a/sphinx/util/__init__.py
+++ b/sphinx/util/__init__.py
@@ -24,6 +24,8 @@ import traceback
from os import path
import docutils
+from docutils.utils import relative_path
+
import sphinx
# Errnos that we need.
@@ -101,19 +103,16 @@ def walk(top, topdown=True, followlinks=False):
yield top, dirs, nondirs
-def get_matching_files(dirname, exclude_patterns=()):
+def get_matching_files(dirname, exclude_matchers=()):
"""
Get all file names in a directory, recursively.
- Exclude files and dirs matching a pattern in *exclude_patterns*.
+ Exclude files and dirs matching some matcher in *exclude_matchers*.
"""
# dirname is a normalized absolute path.
dirname = path.normpath(path.abspath(dirname))
dirlen = len(dirname) + 1 # exclude final os.path.sep
- matchers = [re.compile(_translate_pattern(pat)).match
- for pat in exclude_patterns]
-
for root, dirs, files in walk(dirname, followlinks=True):
relativeroot = root[dirlen:]
@@ -121,7 +120,7 @@ def get_matching_files(dirname, exclude_patterns=()):
for dn in dirs)
qfiles = enumerate(path.join(relativeroot, fn).replace(os.path.sep, SEP)
for fn in files)
- for matcher in matchers:
+ for matcher in exclude_matchers:
qdirs = [entry for entry in qdirs if not matcher(entry[1])]
qfiles = [entry for entry in qfiles if not matcher(entry[1])]
@@ -131,7 +130,7 @@ def get_matching_files(dirname, exclude_patterns=()):
yield filename
-def get_matching_docs(dirname, suffix, exclude_patterns=()):
+def get_matching_docs(dirname, suffix, exclude_matchers=()):
"""
Get all file names (without suffix) matching a suffix in a
directory, recursively.
@@ -139,7 +138,7 @@ def get_matching_docs(dirname, suffix, exclude_patterns=()):
Exclude files and dirs matching a pattern in *exclude_patterns*.
"""
suffixpattern = '*' + suffix
- for filename in get_matching_files(dirname, exclude_patterns):
+ for filename in get_matching_files(dirname, exclude_matchers):
if not fnmatch.fnmatch(filename, suffixpattern):
continue
yield filename[:-len(suffix)]
@@ -280,6 +279,9 @@ def _translate_pattern(pat):
res += re.escape(c)
return res + '$'
+def compile_matchers(patterns):
+ return [re.compile(_translate_pattern(pat)).match for pat in patterns]
+
_pat_cache = {}
@@ -433,8 +435,12 @@ def copyfile(source, dest):
def copy_static_entry(source, targetdir, builder, context={},
- exclude=True, level=0):
- # XXX: exclusion
+ exclude_matchers=(), level=0):
+ if exclude_matchers:
+ relpath = relative_path(builder.srcdir, source)
+ for matcher in exclude_matchers:
+ if matcher(relpath):
+ return
if path.isfile(source):
target = path.join(targetdir, path.basename(source))
if source.lower().endswith('_t') and builder.templates:
@@ -452,7 +458,8 @@ def copy_static_entry(source, targetdir, builder, context={},
if entry.startswith('.'):
continue
copy_static_entry(path.join(source, entry), targetdir,
- builder, context, level=1)
+ builder, context, level=1,
+ exclude_matchers=exclude_matchers)
else:
target = path.join(targetdir, path.basename(source))
if path.exists(target):