Permalink
Browse files

fix premature joining of root and path in readers.py:ignored

  • Loading branch information...
posativ committed Sep 26, 2012
1 parent 595c86e commit 2ff0920949d8139caba739f0913f6515f3a348a8
Showing with 20 additions and 9 deletions.
  1. +7 −8 acrylamid/readers.py
  2. +13 −1 specs/test_reader.py
View
@@ -64,21 +64,21 @@ def load(conf):
return (sorted(entrylist, key=lambda k: k.date, reverse=True), pages)
-def ignored(cwd, path, patterns, dest):
+def ignored(cwd, path, patterns, directory):
"""Test wether a path is excluded by the user. The ignore syntax is
similar to Git: a path with a leading slash means absolute position
(relative to output root), path with trailing slash marks a directory
and everything else is just relative fnmatch.
- :param cwd: current directory
+ :param cwd: current directory (root from :py:func:`os.walk`)
:param path: current path
- :param excl_files: a list of patterns
- :param dest: destination directory
+ :param patterns: a list of patterns
+ :param directory: destination directory
"""
for pattern in patterns:
if pattern.startswith('/'):
- if fnmatch(join(cwd, path), join(dest, pattern[1:])):
+ if fnmatch(join(cwd, path), join(directory, pattern[1:])):
return True
elif fnmatch(path, pattern):
return True
@@ -91,10 +91,9 @@ def filelist(directory, patterns=[]):
this generator won't raise any (IOError, OSError)."""
for root, dirs, files in os.walk(directory):
- for f in files:
- path = os.path.join(root, f)
+ for path in files:
if not ignored(root, path, patterns, directory):
- yield path
+ yield os.path.join(root, path)
# don't visit excluded dirs
for dir in dirs[:]:
View
@@ -14,7 +14,7 @@
except ImportError:
docutils = None # NOQA
-from acrylamid.readers import reststyle, markdownstyle, distinguish
+from acrylamid.readers import reststyle, markdownstyle, distinguish, ignored
class TestStyles(unittest.TestCase):
@@ -78,3 +78,15 @@ def testQuotes():
assert distinguish('"Foo Bar"') == 'Foo Bar'
assert distinguish("\"'bout \" and '\"") == "'bout \" and '"
+
+
+def testIgnored():
+
+ assert ignored('/path/', 'foo', ['foo', 'fo*', '/foo'], '/path/')
+ assert ignored('/path/', 'dir/', ['dir', 'dir/'], '/path/')
+ assert not ignored('/path/to/', 'baz/', ['/baz/', '/baz'], '/path/')
+
+ assert ignored('/', '.git/info/refs', ['.git*'], '/')
+ assert ignored('/', '.gitignore', ['.git*'], '/')
+
+ assert ignored('/', '.DS_Store', ['.DS_Store'], '/')

0 comments on commit 2ff0920

Please sign in to comment.