comparison 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
comparison
equal deleted inserted replaced
61:64f37c4cce68 62:52e4d9a1f917
1 import re 1 import re
2 import os 2 import os
3 import os.path 3 import os.path
4 import fnmatch
4 5
5 6
6 re_terminal_path = re.compile(r'[/\\]|(\w\:)') 7 re_terminal_path = re.compile(r'[/\\]|(\w\:)')
7 8
8 9
28 cwd = os.path.dirname(cwd) 29 cwd = os.path.dirname(cwd)
29 if not cwd or re_terminal_path.match(cwd): 30 if not cwd or re_terminal_path.match(cwd):
30 raise SiteNotFoundError(cwd) 31 raise SiteNotFoundError(cwd)
31 return cwd 32 return cwd
32 33
34
35 def multi_fnmatch_filter(names, patterns, modifier=None, inverse=True):
36 res = []
37 for n in names:
38 matches = False
39 test_n = modifier(n) if modifier else n
40 for p in patterns:
41 if fnmatch.fnmatch(test_n, p):
42 matches = True
43 break
44 if matches and not inverse:
45 res.append(n)
46 elif not matches and inverse:
47 res.append(n)
48 return res
49