Mercurial > piecrust2
annotate piecrust/pathutil.py @ 369:4b1019bb2533
serve: Giant refactor to change how we handle data when serving pages.
* We need a distinction between source metadata and route metadata. In most
cases they're the same, but in cases like taxonomy pages, route metadata
contains more things that can't be in source metadata if we want to re-use
cached pages.
* Create a new `QualifiedPage` type which is a page with a specific route
and route metadata. Pass this around in many places.
* Instead of passing an URL around, use the route in the `QualifiedPage` to
generate URLs. This is better since it removes the guess-work from trying
to generate URLs for sub-pages.
* Deep-copy app and page configurations before passing them around to things
that could modify them, like data builders and such.
* Exclude taxonomy pages from iterator data providers.
* Properly nest iterator data providers for when the theme and user page
sources are merged inside `site.pages`.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 03 May 2015 18:47:10 -0700 |
parents | 9c074aec60a6 |
children | 3ceeca7bb71c |
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 | |
115
9c074aec60a6
Fix search for root folder. Must have been drunk when I wrote this originally.
Ludovic Chabant <ludovic@chabant.com>
parents:
62
diff
changeset
|
7 re_terminal_path = re.compile(r'^(\w\:)?[/\\]$') |
38
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 |