Mercurial > piecrust2
annotate piecrust/pathutil.py @ 111:208c652551a3
Quick fix for making the server correctly update referenced pages.
Disable the file-system cache for rendered segments when in server mode. We
can bring this optimization back when we're actually using the baking record
in the server too in order to know dependencies.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 16 Oct 2014 17:03:42 -0700 |
parents | 52e4d9a1f917 |
children | 9c074aec60a6 |
rev | line source |
---|---|
38
091f99bfbe44
Fix running `chef` outside of a website. Slightly better error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents:
36
diff
changeset
|
1 import re |
0 | 2 import os |
3 import os.path | |
62
52e4d9a1f917
Simple importer for PieCrust 1 websites.
Ludovic Chabant <ludovic@chabant.com>
parents:
38
diff
changeset
|
4 import fnmatch |
0 | 5 |
6 | |
38
091f99bfbe44
Fix running `chef` outside of a website. Slightly better error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents:
36
diff
changeset
|
7 re_terminal_path = re.compile(r'[/\\]|(\w\:)') |
091f99bfbe44
Fix running `chef` outside of a website. Slightly better error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents:
36
diff
changeset
|
8 |
091f99bfbe44
Fix running `chef` outside of a website. Slightly better error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents:
36
diff
changeset
|
9 |
0 | 10 class SiteNotFoundError(Exception): |
38
091f99bfbe44
Fix running `chef` outside of a website. Slightly better error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents:
36
diff
changeset
|
11 def __init__(self, root=None, msg=None): |
0 | 12 if not root: |
13 root = os.getcwd() | |
38
091f99bfbe44
Fix running `chef` outside of a website. Slightly better error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents:
36
diff
changeset
|
14 full_msg = ("No PieCrust website in '%s' " |
091f99bfbe44
Fix running `chef` outside of a website. Slightly better error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents:
36
diff
changeset
|
15 "('config.yml' not found!)" % |
091f99bfbe44
Fix running `chef` outside of a website. Slightly better error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents:
36
diff
changeset
|
16 root) |
091f99bfbe44
Fix running `chef` outside of a website. Slightly better error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents:
36
diff
changeset
|
17 if msg: |
091f99bfbe44
Fix running `chef` outside of a website. Slightly better error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents:
36
diff
changeset
|
18 full_msg += ": " + msg |
091f99bfbe44
Fix running `chef` outside of a website. Slightly better error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents:
36
diff
changeset
|
19 else: |
091f99bfbe44
Fix running `chef` outside of a website. Slightly better error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents:
36
diff
changeset
|
20 full_msg += "." |
091f99bfbe44
Fix running `chef` outside of a website. Slightly better error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents:
36
diff
changeset
|
21 Exception.__init__(self, full_msg) |
0 | 22 |
23 | |
24 def find_app_root(cwd=None): | |
25 if cwd is None: | |
26 cwd = os.getcwd() | |
27 | |
36
485682a6de50
New site layout support.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
28 while not os.path.isfile(os.path.join(cwd, 'config.yml')): |
0 | 29 cwd = os.path.dirname(cwd) |
38
091f99bfbe44
Fix running `chef` outside of a website. Slightly better error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents:
36
diff
changeset
|
30 if not cwd or re_terminal_path.match(cwd): |
091f99bfbe44
Fix running `chef` outside of a website. Slightly better error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents:
36
diff
changeset
|
31 raise SiteNotFoundError(cwd) |
0 | 32 return cwd |
33 | |
62
52e4d9a1f917
Simple importer for PieCrust 1 websites.
Ludovic Chabant <ludovic@chabant.com>
parents:
38
diff
changeset
|
34 |
52e4d9a1f917
Simple importer for PieCrust 1 websites.
Ludovic Chabant <ludovic@chabant.com>
parents:
38
diff
changeset
|
35 def multi_fnmatch_filter(names, patterns, modifier=None, inverse=True): |
52e4d9a1f917
Simple importer for PieCrust 1 websites.
Ludovic Chabant <ludovic@chabant.com>
parents:
38
diff
changeset
|
36 res = [] |
52e4d9a1f917
Simple importer for PieCrust 1 websites.
Ludovic Chabant <ludovic@chabant.com>
parents:
38
diff
changeset
|
37 for n in names: |
52e4d9a1f917
Simple importer for PieCrust 1 websites.
Ludovic Chabant <ludovic@chabant.com>
parents:
38
diff
changeset
|
38 matches = False |
52e4d9a1f917
Simple importer for PieCrust 1 websites.
Ludovic Chabant <ludovic@chabant.com>
parents:
38
diff
changeset
|
39 test_n = modifier(n) if modifier else n |
52e4d9a1f917
Simple importer for PieCrust 1 websites.
Ludovic Chabant <ludovic@chabant.com>
parents:
38
diff
changeset
|
40 for p in patterns: |
52e4d9a1f917
Simple importer for PieCrust 1 websites.
Ludovic Chabant <ludovic@chabant.com>
parents:
38
diff
changeset
|
41 if fnmatch.fnmatch(test_n, p): |
52e4d9a1f917
Simple importer for PieCrust 1 websites.
Ludovic Chabant <ludovic@chabant.com>
parents:
38
diff
changeset
|
42 matches = True |
52e4d9a1f917
Simple importer for PieCrust 1 websites.
Ludovic Chabant <ludovic@chabant.com>
parents:
38
diff
changeset
|
43 break |
52e4d9a1f917
Simple importer for PieCrust 1 websites.
Ludovic Chabant <ludovic@chabant.com>
parents:
38
diff
changeset
|
44 if matches and not inverse: |
52e4d9a1f917
Simple importer for PieCrust 1 websites.
Ludovic Chabant <ludovic@chabant.com>
parents:
38
diff
changeset
|
45 res.append(n) |
52e4d9a1f917
Simple importer for PieCrust 1 websites.
Ludovic Chabant <ludovic@chabant.com>
parents:
38
diff
changeset
|
46 elif not matches and inverse: |
52e4d9a1f917
Simple importer for PieCrust 1 websites.
Ludovic Chabant <ludovic@chabant.com>
parents:
38
diff
changeset
|
47 res.append(n) |
52e4d9a1f917
Simple importer for PieCrust 1 websites.
Ludovic Chabant <ludovic@chabant.com>
parents:
38
diff
changeset
|
48 return res |
52e4d9a1f917
Simple importer for PieCrust 1 websites.
Ludovic Chabant <ludovic@chabant.com>
parents:
38
diff
changeset
|
49 |