annotate piecrust/appconfig.py @ 679:15b6ffadc95f

cm: It's fun to send typos to Travis-CI.
author Ludovic Chabant <ludovic@chabant.com>
date Mon, 07 Mar 2016 00:03:13 -0800
parents 3df808b133f8
children 894d286b348f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
584
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1 import re
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
2 import os.path
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
3 import copy
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
4 import json
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
5 import urllib
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
6 import logging
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
7 import hashlib
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
8 import collections
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
9 import yaml
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
10 from piecrust import (
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
11 APP_VERSION, CACHE_VERSION,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
12 DEFAULT_FORMAT, DEFAULT_TEMPLATE_ENGINE, DEFAULT_POSTS_FS,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
13 DEFAULT_DATE_FORMAT, DEFAULT_THEME_SOURCE)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
14 from piecrust.cache import NullCache
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
15 from piecrust.configuration import (
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
16 Configuration, ConfigurationError, ConfigurationLoader,
666
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
17 get_dict_value, set_dict_value, merge_dicts, visit_dict)
584
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
18 from piecrust.sources.base import REALM_USER, REALM_THEME
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
19
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
20
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
21 logger = logging.getLogger(__name__)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
22
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
23
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
24 class VariantNotFoundError(Exception):
666
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
25 def __init__(self, variant_name, message=None):
584
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
26 super(VariantNotFoundError, self).__init__(
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
27 message or ("No such configuration variant: %s" %
666
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
28 variant_name))
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
29
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
30
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
31 def _make_variant_fixup(variant_name, raise_if_not_found):
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
32 def _variant_fixup(index, config):
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
33 if index != -1:
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
34 return
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
35 try:
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
36 try:
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
37 v = get_dict_value(config, 'variants/%s' % variant_name)
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
38 except KeyError:
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
39 raise VariantNotFoundError(variant_name)
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
40 if not isinstance(v, dict):
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
41 raise VariantNotFoundError(
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
42 variant_name,
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
43 "Configuration variant '%s' is not an array. "
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
44 "Check your configuration file." % variant_name)
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
45 merge_dicts(config, v)
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
46 except VariantNotFoundError:
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
47 if raise_if_not_found:
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
48 raise
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
49
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
50 return _variant_fixup
584
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
51
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
52
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
53 class PieCrustConfiguration(Configuration):
663
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
54 def __init__(self, paths=None, cache=None, values=None, validate=True,
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
55 theme_config=False):
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
56 super(PieCrustConfiguration, self).__init__()
666
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
57 self._paths = paths
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
58 self._cache = cache or NullCache()
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
59 self._fixups = []
663
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
60 self.theme_config = theme_config
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
61 # Set the values after we set the rest, since our validation needs
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
62 # our attributes.
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
63 if values:
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
64 self.setAll(values, validate=validate)
584
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
65
666
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
66 def addFixup(self, f):
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
67 self._ensureNotLoaded()
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
68 self._fixups.append(f)
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
69
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
70 def addPath(self, p, first=False):
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
71 self._ensureNotLoaded()
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
72 if not first:
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
73 self._paths.append(p)
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
74 else:
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
75 self._paths.insert(0, p)
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
76
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
77 def addVariant(self, variant_path, raise_if_not_found=True):
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
78 self._ensureNotLoaded()
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
79 if os.path.isfile(variant_path):
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
80 self.addPath(variant_path)
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
81 else:
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
82 name, _ = os.path.splitext(os.path.basename(variant_path))
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
83 fixup = _make_variant_fixup(name, raise_if_not_found)
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
84 self.addFixup(fixup)
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
85
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
86 logger.warning(
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
87 "Configuration variants should now be `.yml` files located "
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
88 "in the `configs/` directory of your website.")
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
89 logger.warning(
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
90 "Variants defined in the site configuration will be "
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
91 "deprecated in a future version of PieCrust.")
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
92
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
93 def addVariantValue(self, path, value):
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
94 def _fixup(index, config):
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
95 set_dict_value(config, path, value)
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
96 self.addFixup(_fixup)
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
97
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
98 def _ensureNotLoaded(self):
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
99 if self._values is not None:
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
100 raise Exception("The configurations has been loaded.")
584
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
101
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
102 def _load(self):
666
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
103 if self._paths is None:
584
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
104 self._values = self._validateAll({})
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
105 return
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
106
666
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
107 path_times = [os.path.getmtime(p) for p in self._paths]
584
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
108
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
109 cache_key_hash = hashlib.md5(
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
110 ("version=%s&cache=%d" % (
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
111 APP_VERSION, CACHE_VERSION)).encode('utf8'))
666
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
112 for p in self._paths:
584
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
113 cache_key_hash.update(("&path=%s" % p).encode('utf8'))
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
114 cache_key = cache_key_hash.hexdigest()
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
115
666
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
116 if self._cache.isValid('config.json', path_times):
584
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
117 logger.debug("Loading configuration from cache...")
666
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
118 config_text = self._cache.read('config.json')
584
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
119 self._values = json.loads(
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
120 config_text,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
121 object_pairs_hook=collections.OrderedDict)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
122
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
123 actual_cache_key = self._values.get('__cache_key')
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
124 if actual_cache_key == cache_key:
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
125 self._values['__cache_valid'] = True
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
126 return
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
127 logger.debug("Outdated cache key '%s' (expected '%s')." % (
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
128 actual_cache_key, cache_key))
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
129
666
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
130 logger.debug("Loading configuration from: %s" % self._paths)
584
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
131 values = {}
585
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
132 try:
666
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
133 for i, p in enumerate(self._paths):
585
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
134 with open(p, 'r', encoding='utf-8') as fp:
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
135 loaded_values = yaml.load(
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
136 fp.read(),
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
137 Loader=ConfigurationLoader)
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
138 if loaded_values is None:
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
139 loaded_values = {}
666
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
140 for fixup in self._fixups:
585
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
141 fixup(i, loaded_values)
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
142 merge_dicts(values, loaded_values)
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
143
666
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
144 for fixup in self._fixups:
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
145 fixup(-1, values)
584
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
146
585
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
147 self._values = self._validateAll(values)
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
148 except Exception as ex:
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
149 raise Exception("Error loading configuration from: %s" %
666
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
150 ', '.join(self._paths)) from ex
584
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
151
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
152 logger.debug("Caching configuration...")
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
153 self._values['__cache_key'] = cache_key
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
154 config_text = json.dumps(self._values)
666
81d9c3a3a0b5 internal: Get rid of the whole "sub cache" business.
Ludovic Chabant <ludovic@chabant.com>
parents: 663
diff changeset
155 self._cache.write('config.json', config_text)
584
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
156
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
157 self._values['__cache_valid'] = False
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
158
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
159 def _validateAll(self, values):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
160 if values is None:
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
161 values = {}
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
162
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
163 # Add the loaded values to the default configuration.
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
164 values = merge_dicts(copy.deepcopy(default_configuration), values)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
165
663
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
166 # Set the theme site flag.
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
167 if self.theme_config:
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
168 values['site']['theme_site'] = True
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
169
584
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
170 # Figure out if we need to generate the configuration for the
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
171 # default content model.
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
172 sitec = values.setdefault('site', {})
675
3df808b133f8 internal: Improve how theme configuration is validated and merged.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
173 gen_default_model = bool(sitec.get('use_default_content'))
3df808b133f8 internal: Improve how theme configuration is validated and merged.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
174 if gen_default_model:
584
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
175 logger.debug("Generating default content model...")
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
176 values = self._generateDefaultContentModel(values)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
177
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
178 # Add a section for our cached information.
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
179 cachec = collections.OrderedDict()
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
180 values['__cache'] = cachec
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
181 cache_writer = _ConfigCacheWriter(cachec)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
182 globs = globals()
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
183
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
184 def _visitor(path, val, parent_val, parent_key):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
185 callback_name = '_validate_' + path.replace('/', '_')
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
186 callback = globs.get(callback_name)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
187 if callback:
585
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
188 try:
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
189 val2 = callback(val, values, cache_writer)
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
190 except Exception as ex:
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
191 raise Exception("Error raised in validator '%s'." %
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
192 callback_name) from ex
584
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
193 if val2 is None:
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
194 raise Exception("Validator '%s' isn't returning a "
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
195 "coerced value." % callback_name)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
196 parent_val[parent_key] = val2
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
197
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
198 visit_dict(values, _visitor)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
199
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
200 return values
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
201
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
202 def _generateDefaultContentModel(self, values):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
203 dcmcopy = copy.deepcopy(default_content_model_base)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
204 values = merge_dicts(dcmcopy, values)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
205
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
206 blogsc = values['site'].get('blogs')
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
207 if blogsc is None:
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
208 blogsc = ['posts']
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
209 values['site']['blogs'] = blogsc
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
210
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
211 is_only_blog = (len(blogsc) == 1)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
212 for blog_name in blogsc:
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
213 blog_cfg = get_default_content_model_for_blog(
663
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
214 blog_name, is_only_blog, values,
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
215 theme_site=self.theme_config)
584
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
216 values = merge_dicts(blog_cfg, values)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
217
585
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
218 dcm = get_default_content_model(values)
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
219 values = merge_dicts(dcm, values)
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
220
584
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
221 return values
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
222
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
223
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
224 class _ConfigCacheWriter(object):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
225 def __init__(self, cache_dict):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
226 self._cache_dict = cache_dict
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
227
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
228 def write(self, name, val):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
229 logger.debug("Caching configuration item '%s' = %s" % (name, val))
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
230 self._cache_dict[name] = val
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
231
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
232
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
233 default_configuration = collections.OrderedDict({
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
234 'site': collections.OrderedDict({
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
235 'title': "Untitled PieCrust website",
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
236 'root': '/',
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
237 'default_format': DEFAULT_FORMAT,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
238 'default_template_engine': DEFAULT_TEMPLATE_ENGINE,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
239 'enable_gzip': True,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
240 'pretty_urls': False,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
241 'trailing_slash': False,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
242 'date_format': DEFAULT_DATE_FORMAT,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
243 'auto_formats': collections.OrderedDict([
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
244 ('html', ''),
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
245 ('md', 'markdown'),
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
246 ('textile', 'textile')]),
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
247 'default_auto_format': 'md',
585
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
248 'default_pagination_source': None,
584
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
249 'pagination_suffix': '/%num%',
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
250 'slugify_mode': 'encode',
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
251 'themes_sources': [DEFAULT_THEME_SOURCE],
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
252 'cache_time': 28800,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
253 'enable_debug_info': True,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
254 'show_debug_info': False,
663
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
255 'use_default_content': True,
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
256 'theme_site': False
584
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
257 }),
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
258 'baker': collections.OrderedDict({
585
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
259 'no_bake_setting': 'draft',
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
260 'workers': None,
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
261 'batch_size': None
584
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
262 })
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
263 })
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
264
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
265
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
266 default_content_model_base = collections.OrderedDict({
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
267 'site': collections.OrderedDict({
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
268 'posts_fs': DEFAULT_POSTS_FS,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
269 'default_page_layout': 'default',
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
270 'default_post_layout': 'post',
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
271 'post_url': '%year%/%month%/%day%/%slug%',
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
272 'tag_url': 'tag/%tag%',
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
273 'category_url': '%category%',
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
274 'posts_per_page': 5
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
275 })
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
276 })
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
277
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
278
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
279 def get_default_content_model(values):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
280 default_layout = values['site']['default_page_layout']
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
281 return collections.OrderedDict({
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
282 'site': collections.OrderedDict({
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
283 'sources': collections.OrderedDict({
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
284 'pages': {
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
285 'type': 'default',
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
286 'ignore_missing_dir': True,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
287 'data_endpoint': 'site.pages',
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
288 'default_layout': default_layout,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
289 'item_name': 'page'
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
290 }
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
291 }),
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
292 'routes': [
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
293 {
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
294 'url': '/%path:slug%',
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
295 'source': 'pages',
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
296 'func': 'pcurl(slug)'
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
297 }
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
298 ],
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
299 'taxonomies': collections.OrderedDict({
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
300 'tags': {
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
301 'multiple': True,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
302 'term': 'tag'
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
303 },
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
304 'categories': {
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
305 'term': 'category'
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
306 }
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
307 })
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
308 })
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
309 })
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
310
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
311
663
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
312 def get_default_content_model_for_blog(
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
313 blog_name, is_only_blog, values, theme_site=False):
584
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
314 posts_fs = values['site']['posts_fs']
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
315 blog_cfg = values.get(blog_name, {})
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
316
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
317 if is_only_blog:
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
318 url_prefix = ''
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
319 tax_page_prefix = ''
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
320 fs_endpoint = 'posts'
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
321 data_endpoint = 'blog'
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
322 item_name = 'post'
675
3df808b133f8 internal: Improve how theme configuration is validated and merged.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
323
3df808b133f8 internal: Improve how theme configuration is validated and merged.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
324 if theme_site:
3df808b133f8 internal: Improve how theme configuration is validated and merged.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
325 # If this is a theme site, show posts from a `sample` directory
3df808b133f8 internal: Improve how theme configuration is validated and merged.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
326 # so it's clearer that those won't show up when the theme is
3df808b133f8 internal: Improve how theme configuration is validated and merged.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
327 # actually applied to a normal site.
3df808b133f8 internal: Improve how theme configuration is validated and merged.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
328 fs_endpoint = 'sample/posts'
584
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
329 else:
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
330 url_prefix = blog_name + '/'
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
331 tax_page_prefix = blog_name + '/'
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
332 fs_endpoint = 'posts/%s' % blog_name
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
333 data_endpoint = blog_name
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
334 item_name = '%s-post' % blog_name
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
335
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
336 items_per_page = blog_cfg.get(
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
337 'posts_per_page', values['site']['posts_per_page'])
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
338 date_format = blog_cfg.get(
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
339 'date_format', values['site']['date_format'])
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
340 default_layout = blog_cfg.get(
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
341 'default_layout', values['site']['default_post_layout'])
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
342
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
343 post_url = '/' + blog_cfg.get(
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
344 'post_url',
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
345 url_prefix + values['site']['post_url']).lstrip('/')
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
346 tag_url = '/' + blog_cfg.get(
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
347 'tag_url',
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
348 url_prefix + values['site']['tag_url']).lstrip('/')
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
349 category_url = '/' + blog_cfg.get(
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
350 'category_url',
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
351 url_prefix + values['site']['category_url']).lstrip('/')
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
352
663
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
353 tags_taxonomy = 'pages:%s_tag.%%ext%%' % tax_page_prefix
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
354 category_taxonomy = 'pages:%s_category.%%ext%%' % tax_page_prefix
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
355 if not theme_site:
675
3df808b133f8 internal: Improve how theme configuration is validated and merged.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
356 theme_tag_page = values['site'].get('theme_tag_page')
3df808b133f8 internal: Improve how theme configuration is validated and merged.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
357 if theme_tag_page:
3df808b133f8 internal: Improve how theme configuration is validated and merged.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
358 tags_taxonomy += ';' + theme_tag_page
3df808b133f8 internal: Improve how theme configuration is validated and merged.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
359 theme_category_page = values['site'].get('theme_category_page')
3df808b133f8 internal: Improve how theme configuration is validated and merged.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
360 if theme_category_page:
3df808b133f8 internal: Improve how theme configuration is validated and merged.
Ludovic Chabant <ludovic@chabant.com>
parents: 666
diff changeset
361 category_taxonomy += ';' + theme_category_page
663
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
362
584
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
363 return collections.OrderedDict({
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
364 'site': collections.OrderedDict({
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
365 'sources': collections.OrderedDict({
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
366 blog_name: collections.OrderedDict({
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
367 'type': 'posts/%s' % posts_fs,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
368 'fs_endpoint': fs_endpoint,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
369 'data_endpoint': data_endpoint,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
370 'item_name': item_name,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
371 'ignore_missing_dir': True,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
372 'data_type': 'blog',
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
373 'items_per_page': items_per_page,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
374 'date_format': date_format,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
375 'default_layout': default_layout,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
376 'taxonomy_pages': collections.OrderedDict({
663
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
377 'tags': tags_taxonomy,
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
378 'categories': category_taxonomy
584
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
379 })
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
380 })
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
381 }),
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
382 'routes': [
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
383 {
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
384 'url': post_url,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
385 'source': blog_name,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
386 'func': 'pcposturl(year,month,day,slug)'
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
387 },
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
388 {
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
389 'url': tag_url,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
390 'source': blog_name,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
391 'taxonomy': 'tags',
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
392 'func': 'pctagurl(tag)'
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
393 },
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
394 {
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
395 'url': category_url,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
396 'source': blog_name,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
397 'taxonomy': 'categories',
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
398 'func': 'pccaturl(category)'
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
399 }
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
400 ]
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
401 })
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
402 })
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
403
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
404
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
405 # Configuration value validators.
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
406 #
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
407 # Make sure we have basic site stuff.
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
408 def _validate_site(v, values, cache):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
409 sources = v.get('sources')
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
410 if not sources:
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
411 raise ConfigurationError("No sources were defined.")
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
412 routes = v.get('routes')
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
413 if not routes:
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
414 raise ConfigurationError("No routes were defined.")
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
415 taxonomies = v.get('taxonomies')
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
416 if taxonomies is None:
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
417 v['taxonomies'] = {}
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
418 return v
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
419
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
420 # Make sure the site root starts and ends with a slash.
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
421 def _validate_site_root(v, values, cache):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
422 if not v.startswith('/'):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
423 raise ConfigurationError("The `site/root` setting must start "
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
424 "with a slash.")
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
425 root_url = urllib.parse.quote(v.rstrip('/') + '/')
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
426 return root_url
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
427
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
428
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
429 # Cache auto-format regexes, check that `.html` is in there.
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
430 def _validate_site_auto_formats(v, values, cache):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
431 if not isinstance(v, dict):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
432 raise ConfigurationError("The 'site/auto_formats' setting must be "
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
433 "a dictionary.")
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
434
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
435 v.setdefault('html', values['site']['default_format'])
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
436 auto_formats_re = r"\.(%s)$" % (
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
437 '|'.join(
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
438 [re.escape(i) for i in list(v.keys())]))
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
439 cache.write('auto_formats_re', auto_formats_re)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
440 return v
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
441
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
442
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
443 # Check that the default auto-format is known.
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
444 def _validate_site_default_auto_format(v, values, cache):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
445 if v not in values['site']['auto_formats']:
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
446 raise ConfigurationError(
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
447 "Default auto-format '%s' is not declared." % v)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
448 return v
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
449
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
450
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
451 # Cache pagination suffix regex and format.
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
452 def _validate_site_pagination_suffix(v, values, cache):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
453 if len(v) == 0 or v[0] != '/':
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
454 raise ConfigurationError("The 'site/pagination_suffix' setting "
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
455 "must start with a slash.")
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
456 if '%num%' not in v:
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
457 raise ConfigurationError("The 'site/pagination_suffix' setting "
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
458 "must contain the '%num%' placeholder.")
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
459
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
460 pgn_suffix_fmt = v.replace('%num%', '%(num)d')
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
461 cache.write('pagination_suffix_format', pgn_suffix_fmt)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
462
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
463 pgn_suffix_re = re.escape(v)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
464 pgn_suffix_re = (pgn_suffix_re.replace("\\%num\\%", "(?P<num>\\d+)") +
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
465 '$')
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
466 cache.write('pagination_suffix_re', pgn_suffix_re)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
467 return v
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
468
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
469
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
470 # Make sure theme sources is a list.
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
471 def _validate_site_theme_sources(v, values, cache):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
472 if not isinstance(v, list):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
473 v = [v]
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
474 return v
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
475
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
476
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
477 def _validate_site_sources(v, values, cache):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
478 # Basic checks.
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
479 if not v:
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
480 raise ConfigurationError("There are no sources defined.")
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
481 if not isinstance(v, dict):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
482 raise ConfigurationError("The 'site/sources' setting must be a "
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
483 "dictionary.")
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
484
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
485 # Sources have the `default` scanner by default, duh. Also, a bunch
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
486 # of other default values for other configuration stuff.
585
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
487 reserved_endpoints = set(['piecrust', 'site', 'page', 'route',
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
488 'assets', 'pagination', 'siblings',
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
489 'family'])
584
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
490 for sn, sc in v.items():
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
491 if not isinstance(sc, dict):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
492 raise ConfigurationError("All sources in 'site/sources' must "
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
493 "be dictionaries.")
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
494 sc.setdefault('type', 'default')
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
495 sc.setdefault('fs_endpoint', sn)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
496 sc.setdefault('ignore_missing_dir', False)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
497 sc.setdefault('data_endpoint', sn)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
498 sc.setdefault('data_type', 'iterator')
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
499 sc.setdefault('item_name', sn)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
500 sc.setdefault('items_per_page', 5)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
501 sc.setdefault('date_format', DEFAULT_DATE_FORMAT)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
502 sc.setdefault('realm', REALM_USER)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
503
585
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
504 # Validate endpoints.
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
505 endpoint = sc['data_endpoint']
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
506 if endpoint in reserved_endpoints:
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
507 raise ConfigurationError(
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
508 "Source '%s' is using a reserved endpoint name: %s" %
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
509 (sn, endpoint))
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
510
584
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
511 return v
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
512
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
513
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
514 def _validate_site_routes(v, values, cache):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
515 if not v:
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
516 raise ConfigurationError("There are no routes defined.")
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
517 if not isinstance(v, list):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
518 raise ConfigurationError("The 'site/routes' setting must be a "
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
519 "list.")
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
520
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
521 # Check routes are referencing correct sources, have default
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
522 # values, etc.
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
523 for rc in v:
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
524 if not isinstance(rc, dict):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
525 raise ConfigurationError("All routes in 'site/routes' must be "
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
526 "dictionaries.")
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
527 rc_url = rc.get('url')
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
528 if not rc_url:
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
529 raise ConfigurationError("All routes in 'site/routes' must "
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
530 "have an 'url'.")
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
531 if rc_url[0] != '/':
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
532 raise ConfigurationError("Route URLs must start with '/'.")
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
533 if rc.get('source') is None:
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
534 raise ConfigurationError("Routes must specify a source.")
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
535 if rc['source'] not in list(values['site']['sources'].keys()):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
536 raise ConfigurationError("Route is referencing unknown "
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
537 "source: %s" % rc['source'])
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
538 rc.setdefault('taxonomy', None)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
539 rc.setdefault('page_suffix', '/%num%')
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
540
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
541 return v
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
542
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
543
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
544 def _validate_site_taxonomies(v, values, cache):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
545 for tn, tc in v.items():
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
546 tc.setdefault('multiple', False)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
547 tc.setdefault('term', tn)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
548 tc.setdefault('page', '_%s.%%ext%%' % tc['term'])
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
549
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
550 return v
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
551
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
552
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
553 def _validate_site_plugins(v, values, cache):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
554 if isinstance(v, str):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
555 v = v.split(',')
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
556 elif not isinstance(v, list):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
557 raise ConfigurationError(
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
558 "The 'site/plugins' setting must be an array, or a "
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
559 "comma-separated list.")
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
560 return v
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
561