Mercurial > piecrust2
diff foodtruck/sites.py @ 610:efc1dc916e7c
admin: Configuration changes.
* Move publish targets to site configuration.
* Add direct accessor for the current site.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Thu, 28 Jan 2016 22:17:58 -0800 |
parents | c6bc0ef03f82 |
children | e2e955a3bb25 |
line wrap: on
line diff
--- a/foodtruck/sites.py Thu Jan 28 22:16:47 2016 -0800 +++ b/foodtruck/sites.py Thu Jan 28 22:17:58 2016 -0800 @@ -6,7 +6,7 @@ import threading import subprocess from piecrust.app import PieCrust -from piecrust.configuration import merge_dicts, Configuration +from piecrust.configuration import merge_dicts logger = logging.getLogger(__name__) @@ -24,7 +24,6 @@ def __init__(self, name, root_dir, config): self.name = name self.root_dir = root_dir - self.config = Configuration(values=config.get('sites/%s' % name, {})) self._global_config = config self._piecrust_app = None self._scm = None @@ -43,7 +42,7 @@ def scm(self): if self._scm is None: cfg = copy.deepcopy(self._global_config.get('scm', {})) - merge_dicts(cfg, self.config.get('scm', {})) + merge_dicts(cfg, self.piecrust_app.config.get('scm', {})) if os.path.isdir(os.path.join(self.root_dir, '.hg')): from .scm.mercurial import MercurialSourceControl @@ -66,7 +65,7 @@ return self._publish_thread def publish(self, target): - target_cfg = self.config.get('publish/%s' % target) + target_cfg = self.piecrust_app.config.get('publish/%s' % target) if not target_cfg: raise Exception("No such publish target: %s" % target) @@ -126,7 +125,6 @@ class FoodTruckSites(): def __init__(self, config, current_site): self._sites = {} - self._site_dirs = {} self.config = config self.current_site = current_site if current_site is None: @@ -134,19 +132,11 @@ def get_root_dir(self, name=None): name = name or self.current_site - s = self._site_dirs.get(name) - if s: - return s - - scfg = self.config.get('sites/%s' % name) - if scfg is None: + root_dir = self.config.get('sites/%s' % name) + if root_dir is None: raise InvalidSiteError("No such site: %s" % name) - root_dir = scfg.get('path') - if root_dir is None: - raise InvalidSiteError("Site '%s' has no path defined." % name) if not os.path.isdir(root_dir): raise InvalidSiteError("Site '%s' has an invalid path." % name) - self._site_dirs[name] = root_dir return root_dir def get(self, name=None): @@ -160,3 +150,7 @@ self._sites[name] = s return s + def getall(self): + for name in self.config.get('sites'): + yield self.get(name) +