Mercurial > piecrust2
comparison piecrust/pathutil.py @ 38:091f99bfbe44
Fix running `chef` outside of a website. Slightly better error reporting.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 21 Aug 2014 10:56:17 -0700 |
parents | 485682a6de50 |
children | 52e4d9a1f917 |
comparison
equal
deleted
inserted
replaced
37:afcfecd3bf92 | 38:091f99bfbe44 |
---|---|
1 import re | |
1 import os | 2 import os |
2 import os.path | 3 import os.path |
3 | 4 |
4 | 5 |
6 re_terminal_path = re.compile(r'[/\\]|(\w\:)') | |
7 | |
8 | |
5 class SiteNotFoundError(Exception): | 9 class SiteNotFoundError(Exception): |
6 def __init__(self, root=None): | 10 def __init__(self, root=None, msg=None): |
7 if not root: | 11 if not root: |
8 root = os.getcwd() | 12 root = os.getcwd() |
9 Exception.__init__(self, | 13 full_msg = ("No PieCrust website in '%s' " |
10 "No PieCrust website in '%s' " | 14 "('config.yml' not found!)" % |
11 "('config.yml' not found!)." % root) | 15 root) |
16 if msg: | |
17 full_msg += ": " + msg | |
18 else: | |
19 full_msg += "." | |
20 Exception.__init__(self, full_msg) | |
12 | 21 |
13 | 22 |
14 def find_app_root(cwd=None): | 23 def find_app_root(cwd=None): |
15 if cwd is None: | 24 if cwd is None: |
16 cwd = os.getcwd() | 25 cwd = os.getcwd() |
17 | 26 |
18 while not os.path.isfile(os.path.join(cwd, 'config.yml')): | 27 while not os.path.isfile(os.path.join(cwd, 'config.yml')): |
19 cwd = os.path.dirname(cwd) | 28 cwd = os.path.dirname(cwd) |
20 if not cwd or cwd == '/': | 29 if not cwd or re_terminal_path.match(cwd): |
21 return None | 30 raise SiteNotFoundError(cwd) |
22 return cwd | 31 return cwd |
23 | 32 |