annotate piecrust/pathutil.py @ 56:2d617b889b00

Make template directories properly absolute.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 26 Aug 2014 23:17:20 -0700
parents 091f99bfbe44
children 52e4d9a1f917
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
a212a3f2e3ee Initial commit.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
2 import os
a212a3f2e3ee Initial commit.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
3 import os.path
a212a3f2e3ee Initial commit.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
4
a212a3f2e3ee Initial commit.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
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
a212a3f2e3ee Initial commit.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
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
a212a3f2e3ee Initial commit.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
11 if not root:
a212a3f2e3ee Initial commit.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
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
a212a3f2e3ee Initial commit.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
21
a212a3f2e3ee Initial commit.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
22
a212a3f2e3ee Initial commit.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
23 def find_app_root(cwd=None):
a212a3f2e3ee Initial commit.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
24 if cwd is None:
a212a3f2e3ee Initial commit.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
25 cwd = os.getcwd()
a212a3f2e3ee Initial commit.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
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
a212a3f2e3ee Initial commit.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
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
a212a3f2e3ee Initial commit.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
31 return cwd
a212a3f2e3ee Initial commit.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
32