Mercurial > piecrust2
diff 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 |
line wrap: on
line diff
--- a/piecrust/pathutil.py Wed Aug 20 23:24:04 2014 -0700 +++ b/piecrust/pathutil.py Thu Aug 21 10:56:17 2014 -0700 @@ -1,14 +1,23 @@ +import re import os import os.path +re_terminal_path = re.compile(r'[/\\]|(\w\:)') + + class SiteNotFoundError(Exception): - def __init__(self, root=None): + def __init__(self, root=None, msg=None): if not root: root = os.getcwd() - Exception.__init__(self, - "No PieCrust website in '%s' " - "('config.yml' not found!)." % root) + full_msg = ("No PieCrust website in '%s' " + "('config.yml' not found!)" % + root) + if msg: + full_msg += ": " + msg + else: + full_msg += "." + Exception.__init__(self, full_msg) def find_app_root(cwd=None): @@ -17,7 +26,7 @@ while not os.path.isfile(os.path.join(cwd, 'config.yml')): cwd = os.path.dirname(cwd) - if not cwd or cwd == '/': - return None + if not cwd or re_terminal_path.match(cwd): + raise SiteNotFoundError(cwd) return cwd