Mercurial > piecrust2
annotate piecrust/pathutil.py @ 52:e52241394791
Don't use file-system caching for rendered segments yet.
TODO: need some bake scheduler first!
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Mon, 25 Aug 2014 08:45:16 -0700 |
parents | 091f99bfbe44 |
children | 52e4d9a1f917 |
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 | |
4 | |
5 | |
38
091f99bfbe44
Fix running `chef` outside of a website. Slightly better error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents:
36
diff
changeset
|
6 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
|
7 |
091f99bfbe44
Fix running `chef` outside of a website. Slightly better error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents:
36
diff
changeset
|
8 |
0 | 9 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
|
10 def __init__(self, root=None, msg=None): |
0 | 11 if not root: |
12 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
|
13 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
|
14 "('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
|
15 root) |
091f99bfbe44
Fix running `chef` outside of a website. Slightly better error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents:
36
diff
changeset
|
16 if msg: |
091f99bfbe44
Fix running `chef` outside of a website. Slightly better error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents:
36
diff
changeset
|
17 full_msg += ": " + msg |
091f99bfbe44
Fix running `chef` outside of a website. Slightly better error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents:
36
diff
changeset
|
18 else: |
091f99bfbe44
Fix running `chef` outside of a website. Slightly better error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents:
36
diff
changeset
|
19 full_msg += "." |
091f99bfbe44
Fix running `chef` outside of a website. Slightly better error reporting.
Ludovic Chabant <ludovic@chabant.com>
parents:
36
diff
changeset
|
20 Exception.__init__(self, full_msg) |
0 | 21 |
22 | |
23 def find_app_root(cwd=None): | |
24 if cwd is None: | |
25 cwd = os.getcwd() | |
26 | |
36
485682a6de50
New site layout support.
Ludovic Chabant <ludovic@chabant.com>
parents:
1
diff
changeset
|
27 while not os.path.isfile(os.path.join(cwd, 'config.yml')): |
0 | 28 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
|
29 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
|
30 raise SiteNotFoundError(cwd) |
0 | 31 return cwd |
32 |