Mercurial > piecrust2
comparison foodtruck/sites.py @ 601:effbc78b5528
admin: Better error reporting, general clean-up.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 24 Jan 2016 10:42:33 -0800 |
parents | 3cec8634209a |
children | c6bc0ef03f82 |
comparison
equal
deleted
inserted
replaced
600:c37307a72f79 | 601:effbc78b5528 |
---|---|
4 import shlex | 4 import shlex |
5 import logging | 5 import logging |
6 import threading | 6 import threading |
7 import subprocess | 7 import subprocess |
8 from piecrust.app import PieCrust | 8 from piecrust.app import PieCrust |
9 from piecrust.configuration import merge_dicts | |
9 | 10 |
10 | 11 |
11 logger = logging.getLogger(__name__) | 12 logger = logging.getLogger(__name__) |
12 | 13 |
13 | 14 |
14 class UnauthorizedSiteAccessError(Exception): | 15 class UnauthorizedSiteAccessError(Exception): |
16 pass | |
17 | |
18 | |
19 class InvalidSiteError(Exception): | |
15 pass | 20 pass |
16 | 21 |
17 | 22 |
18 class Site(object): | 23 class Site(object): |
19 def __init__(self, name, root_dir, config): | 24 def __init__(self, name, root_dir, config): |
46 else: | 51 else: |
47 cfg = copy.deepcopy(scm_cfg) | 52 cfg = copy.deepcopy(scm_cfg) |
48 elif global_scm_cfg: | 53 elif global_scm_cfg: |
49 cfg = copy.deepcopy(global_scm_cfg) | 54 cfg = copy.deepcopy(global_scm_cfg) |
50 | 55 |
51 if not cfg or not 'type' in cfg: | 56 if not cfg or 'type' not in cfg: |
52 raise Exception("No SCM available for site: %s" % self.name) | 57 raise Exception("No SCM available for site: %s" % self.name) |
53 | 58 |
54 if cfg['type'] == 'hg': | 59 if cfg['type'] == 'hg': |
55 from .scm.mercurial import MercurialSourceControl | 60 from .scm.mercurial import MercurialSourceControl |
56 self._scm = MercurialSourceControl(self.root_dir, cfg) | 61 self._scm = MercurialSourceControl(self.root_dir, cfg) |
132 if s: | 137 if s: |
133 return s | 138 return s |
134 | 139 |
135 scfg = self.config.get('sites/%s' % name) | 140 scfg = self.config.get('sites/%s' % name) |
136 if scfg is None: | 141 if scfg is None: |
137 raise Exception("No such site: %s" % name) | 142 raise InvalidSiteError("No such site: %s" % name) |
138 root_dir = scfg.get('path') | 143 root_dir = scfg.get('path') |
139 if root_dir is None: | 144 if root_dir is None: |
140 raise Exception("Site '%s' has no path defined." % name) | 145 raise InvalidSiteError("Site '%s' has no path defined." % name) |
141 if not os.path.isdir(root_dir): | 146 if not os.path.isdir(root_dir): |
142 raise Exception("Site '%s' has an invalid path." % name) | 147 raise InvalidSiteError("Site '%s' has an invalid path." % name) |
143 self._site_dirs[name] = root_dir | 148 self._site_dirs[name] = root_dir |
144 return root_dir | 149 return root_dir |
145 | 150 |
146 def get(self, name=None): | 151 def get(self, name=None): |
147 name = name or self.current_site | 152 name = name or self.current_site |