Mercurial > piecrust2
view piecrust/admin/configuration.py @ 853:f070a4fc033c
core: Continue PieCrust3 refactor, simplify pages.
The asset pipeline is still the only function pipeline at this point.
* No more `QualifiedPage`, and several other pieces of code deleted.
* Data providers are simpler and more focused. For instance, the page iterator
doesn't try to support other types of items.
* Route parameters are proper known source metadata to remove the confusion
between the two.
* Make the baker and pipeline more correctly manage records and record
histories.
* Add support for record collapsing and deleting stale outputs in the asset
pipeline.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 21 May 2017 00:06:59 -0700 |
parents | 82509bce94ca |
children |
line wrap: on
line source
import os.path import copy import logging import yaml from piecrust.configuration import ( Configuration, ConfigurationError, ConfigurationLoader, merge_dicts) logger = logging.getLogger(__name__) def get_foodtruck_config(dirname=None, fallback_config=None): dirname = dirname or os.getcwd() cfg_path = os.path.join(dirname, 'foodtruck.yml') return FoodTruckConfiguration(cfg_path, fallback_config) class FoodTruckConfigNotFoundError(Exception): pass class FoodTruckConfiguration(Configuration): def __init__(self, cfg_path, fallback_config=None): super(FoodTruckConfiguration, self).__init__() self.cfg_path = cfg_path self.fallback_config = fallback_config def _load(self): try: with open(self.cfg_path, 'r', encoding='utf-8') as fp: values = yaml.load( fp.read(), Loader=ConfigurationLoader) self._values = self._validateAll(values) except OSError: if self.fallback_config is None: raise FoodTruckConfigNotFoundError() logger.debug("No FoodTruck configuration found, using fallback " "configuration.") self._values = copy.deepcopy(self.fallback_config) except Exception as ex: raise ConfigurationError( "Error loading configuration from: %s" % self.cfg_path) from ex def _validateAll(self, values): if values is None: values = {} values = merge_dicts(copy.deepcopy(default_configuration), values) return values def save(self): with open(self.cfg_path, 'w', encoding='utf8') as fp: self.cfg.write(fp) default_configuration = { 'triggers': { 'bake': 'chef bake' }, 'scm': { 'type': 'hg' }, 'security': { 'username': '', 'password': '' } }