diff piecrust/pathutil.py @ 62:52e4d9a1f917

Simple importer for PieCrust 1 websites.
author Ludovic Chabant <ludovic@chabant.com>
date Wed, 27 Aug 2014 17:14:44 -0700
parents 091f99bfbe44
children 9c074aec60a6
line wrap: on
line diff
--- a/piecrust/pathutil.py	Wed Aug 27 10:23:32 2014 -0700
+++ b/piecrust/pathutil.py	Wed Aug 27 17:14:44 2014 -0700
@@ -1,6 +1,7 @@
 import re
 import os
 import os.path
+import fnmatch
 
 
 re_terminal_path = re.compile(r'[/\\]|(\w\:)')
@@ -30,3 +31,19 @@
             raise SiteNotFoundError(cwd)
     return cwd
 
+
+def multi_fnmatch_filter(names, patterns, modifier=None, inverse=True):
+    res = []
+    for n in names:
+        matches = False
+        test_n = modifier(n) if modifier else n
+        for p in patterns:
+            if fnmatch.fnmatch(test_n, p):
+                matches = True
+                break
+        if matches and not inverse:
+            res.append(n)
+        elif not matches and inverse:
+            res.append(n)
+    return res
+