comparison piecrust/admin/configuration.py @ 812:82509bce94ca

internal: PEP8 fixup for admin panel code.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 20 Dec 2016 22:20:18 -0800
parents 5e91bc0e3b4d
children
comparison
equal deleted inserted replaced
811:c7393ce2dde7 812:82509bce94ca
1 import os.path 1 import os.path
2 import copy 2 import copy
3 import logging 3 import logging
4 import yaml 4 import yaml
5 from piecrust.configuration import ( 5 from piecrust.configuration import (
6 Configuration, ConfigurationError, ConfigurationLoader, 6 Configuration, ConfigurationError, ConfigurationLoader,
7 merge_dicts) 7 merge_dicts)
8 8
9 9
10 logger = logging.getLogger(__name__) 10 logger = logging.getLogger(__name__)
11 11
12 12
28 28
29 def _load(self): 29 def _load(self):
30 try: 30 try:
31 with open(self.cfg_path, 'r', encoding='utf-8') as fp: 31 with open(self.cfg_path, 'r', encoding='utf-8') as fp:
32 values = yaml.load( 32 values = yaml.load(
33 fp.read(), 33 fp.read(),
34 Loader=ConfigurationLoader) 34 Loader=ConfigurationLoader)
35 35
36 self._values = self._validateAll(values) 36 self._values = self._validateAll(values)
37 except OSError: 37 except OSError:
38 if self.fallback_config is None: 38 if self.fallback_config is None:
39 raise FoodTruckConfigNotFoundError() 39 raise FoodTruckConfigNotFoundError()
41 logger.debug("No FoodTruck configuration found, using fallback " 41 logger.debug("No FoodTruck configuration found, using fallback "
42 "configuration.") 42 "configuration.")
43 self._values = copy.deepcopy(self.fallback_config) 43 self._values = copy.deepcopy(self.fallback_config)
44 except Exception as ex: 44 except Exception as ex:
45 raise ConfigurationError( 45 raise ConfigurationError(
46 "Error loading configuration from: %s" % 46 "Error loading configuration from: %s" %
47 self.cfg_path) from ex 47 self.cfg_path) from ex
48 48
49 def _validateAll(self, values): 49 def _validateAll(self, values):
50 if values is None: 50 if values is None:
51 values = {} 51 values = {}
52 52
58 with open(self.cfg_path, 'w', encoding='utf8') as fp: 58 with open(self.cfg_path, 'w', encoding='utf8') as fp:
59 self.cfg.write(fp) 59 self.cfg.write(fp)
60 60
61 61
62 default_configuration = { 62 default_configuration = {
63 'triggers': { 63 'triggers': {
64 'bake': 'chef bake' 64 'bake': 'chef bake'
65 }, 65 },
66 'scm': { 66 'scm': {
67 'type': 'hg' 67 'type': 'hg'
68 }, 68 },
69 'security': { 69 'security': {
70 'username': '', 70 'username': '',
71 'password': '' 71 'password': ''
72 } 72 }
73 } 73 }
74 74