comparison piecrust/pathutil.py @ 663:3ceeca7bb71c

themes: Add support for a `--theme` argument to `chef`.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 01 Mar 2016 22:27:28 -0800
parents 9c074aec60a6
children 8af2ea1f5c34
comparison
equal deleted inserted replaced
662:cbd5cdec0695 663:3ceeca7bb71c
1 import re 1 import re
2 import os 2 import os
3 import os.path 3 import os.path
4 import fnmatch 4 import fnmatch
5 from piecrust import CONFIG_PATH, THEME_CONFIG_PATH
5 6
6 7
7 re_terminal_path = re.compile(r'^(\w\:)?[/\\]$') 8 re_terminal_path = re.compile(r'^(\w\:)?[/\\]$')
8 9
9 10
10 class SiteNotFoundError(Exception): 11 class SiteNotFoundError(Exception):
11 def __init__(self, root=None, msg=None): 12 def __init__(self, root=None, msg=None, theme=False):
12 if not root: 13 if not root:
13 root = os.getcwd() 14 root = os.getcwd()
15
16 cfg_name = CONFIG_PATH
17 if theme:
18 cfg_name = THEME_CONFIG_PATH
19
14 full_msg = ("No PieCrust website in '%s' " 20 full_msg = ("No PieCrust website in '%s' "
15 "('config.yml' not found!)" % 21 "('%s' not found!)" % (root, cfg_name))
16 root)
17 if msg: 22 if msg:
18 full_msg += ": " + msg 23 full_msg += ": " + msg
19 else: 24 else:
20 full_msg += "." 25 full_msg += "."
21 Exception.__init__(self, full_msg) 26 Exception.__init__(self, full_msg)
22 27
23 28
24 def find_app_root(cwd=None): 29 def find_app_root(cwd=None, theme=False):
25 if cwd is None: 30 if cwd is None:
26 cwd = os.getcwd() 31 cwd = os.getcwd()
27 32
28 while not os.path.isfile(os.path.join(cwd, 'config.yml')): 33 cfg_name = CONFIG_PATH
34 if theme:
35 cfg_name = THEME_CONFIG_PATH
36
37 while not os.path.isfile(os.path.join(cwd, cfg_name)):
29 cwd = os.path.dirname(cwd) 38 cwd = os.path.dirname(cwd)
30 if not cwd or re_terminal_path.match(cwd): 39 if not cwd or re_terminal_path.match(cwd):
31 raise SiteNotFoundError(cwd) 40 raise SiteNotFoundError(cwd, theme=theme)
32 return cwd 41 return cwd
33 42
34 43
35 def multi_fnmatch_filter(names, patterns, modifier=None, inverse=True): 44 def multi_fnmatch_filter(names, patterns, modifier=None, inverse=True):
36 res = [] 45 res = []