annotate piecrust/appconfig.py @ 666:81d9c3a3a0b5

internal: Get rid of the whole "sub cache" business. * Compute cache keys up front, so the cache directory is only chosen once. * Buffer up config variants to apply before loading the config. Makes it possible to cache variant-resulting configs, too. * Make a factory class to reuse the logic that creates the `PieCrust` object correctly for multi-process workers and such. * Add a test.
author Ludovic Chabant <ludovic@chabant.com>
date Thu, 03 Mar 2016 08:22:41 -0800
parents 3ceeca7bb71c
children 3df808b133f8
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', {})
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
173 if (
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
174 ('sources' not in sitec and
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
175 'routes' not in sitec and
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
176 'taxonomies' not in sitec) or
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
177 sitec.get('use_default_content')):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
178 logger.debug("Generating default content model...")
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
179 values = self._generateDefaultContentModel(values)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
180
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
181 # Add a section for our cached information.
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
182 cachec = collections.OrderedDict()
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
183 values['__cache'] = cachec
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
184 cache_writer = _ConfigCacheWriter(cachec)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
185 globs = globals()
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
186
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
187 def _visitor(path, val, parent_val, parent_key):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
188 callback_name = '_validate_' + path.replace('/', '_')
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
189 callback = globs.get(callback_name)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
190 if callback:
585
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
191 try:
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
192 val2 = callback(val, values, cache_writer)
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
193 except Exception as ex:
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
194 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
195 callback_name) from ex
584
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
196 if val2 is None:
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
197 raise Exception("Validator '%s' isn't returning a "
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
198 "coerced value." % callback_name)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
199 parent_val[parent_key] = val2
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
200
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
201 visit_dict(values, _visitor)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
202
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
203 return values
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
204
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
205 def _generateDefaultContentModel(self, values):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
206 dcmcopy = copy.deepcopy(default_content_model_base)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
207 values = merge_dicts(dcmcopy, values)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
208
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
209 blogsc = values['site'].get('blogs')
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
210 if blogsc is None:
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
211 blogsc = ['posts']
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
212 values['site']['blogs'] = blogsc
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
213
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
214 is_only_blog = (len(blogsc) == 1)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
215 for blog_name in blogsc:
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
216 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
217 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
218 theme_site=self.theme_config)
584
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
219 values = merge_dicts(blog_cfg, values)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
220
585
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
221 dcm = get_default_content_model(values)
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
222 values = merge_dicts(dcm, values)
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
223
584
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
224 return values
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
225
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
226
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
227 class _ConfigCacheWriter(object):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
228 def __init__(self, cache_dict):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
229 self._cache_dict = cache_dict
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
230
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
231 def write(self, name, val):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
232 logger.debug("Caching configuration item '%s' = %s" % (name, val))
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
233 self._cache_dict[name] = val
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
234
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
235
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
236 default_configuration = collections.OrderedDict({
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
237 'site': collections.OrderedDict({
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
238 'title': "Untitled PieCrust website",
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
239 'root': '/',
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
240 'default_format': DEFAULT_FORMAT,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
241 'default_template_engine': DEFAULT_TEMPLATE_ENGINE,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
242 'enable_gzip': True,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
243 'pretty_urls': False,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
244 'trailing_slash': False,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
245 'date_format': DEFAULT_DATE_FORMAT,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
246 'auto_formats': collections.OrderedDict([
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
247 ('html', ''),
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
248 ('md', 'markdown'),
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
249 ('textile', 'textile')]),
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
250 'default_auto_format': 'md',
585
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
251 'default_pagination_source': None,
584
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
252 'pagination_suffix': '/%num%',
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
253 'slugify_mode': 'encode',
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
254 'themes_sources': [DEFAULT_THEME_SOURCE],
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
255 'cache_time': 28800,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
256 'enable_debug_info': True,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
257 'show_debug_info': False,
663
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
258 'use_default_content': True,
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
259 'theme_site': False
584
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
260 }),
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
261 'baker': collections.OrderedDict({
585
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
262 'no_bake_setting': 'draft',
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
263 'workers': None,
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
264 'batch_size': None
584
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 })
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
267
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
268
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
269 default_content_model_base = collections.OrderedDict({
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
270 'site': collections.OrderedDict({
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
271 'posts_fs': DEFAULT_POSTS_FS,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
272 'date_format': DEFAULT_DATE_FORMAT,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
273 'default_page_layout': 'default',
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
274 'default_post_layout': 'post',
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
275 'post_url': '%year%/%month%/%day%/%slug%',
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
276 'tag_url': 'tag/%tag%',
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
277 'category_url': '%category%',
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
278 'posts_per_page': 5
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
279 })
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
280 })
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
281
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
282
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
283 def get_default_content_model(values):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
284 default_layout = values['site']['default_page_layout']
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
285 return collections.OrderedDict({
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
286 'site': collections.OrderedDict({
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
287 'sources': collections.OrderedDict({
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
288 'pages': {
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
289 'type': 'default',
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
290 'ignore_missing_dir': True,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
291 'data_endpoint': 'site.pages',
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
292 'default_layout': default_layout,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
293 'item_name': 'page'
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
294 }
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
295 }),
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
296 'routes': [
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 'url': '/%path:slug%',
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
299 'source': 'pages',
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
300 'func': 'pcurl(slug)'
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
301 }
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
302 ],
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
303 'taxonomies': collections.OrderedDict({
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
304 'tags': {
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
305 'multiple': True,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
306 'term': 'tag'
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 'categories': {
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
309 'term': 'category'
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 })
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
312 })
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
313 })
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
314
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
315
663
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
316 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
317 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
318 posts_fs = values['site']['posts_fs']
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
319 blog_cfg = values.get(blog_name, {})
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
320
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
321 if is_only_blog:
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
322 url_prefix = ''
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
323 tax_page_prefix = ''
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
324 fs_endpoint = 'posts'
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
325 data_endpoint = 'blog'
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
326 item_name = 'post'
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
327 else:
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
328 url_prefix = blog_name + '/'
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
329 tax_page_prefix = blog_name + '/'
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
330 fs_endpoint = 'posts/%s' % blog_name
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
331 data_endpoint = blog_name
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
332 item_name = '%s-post' % blog_name
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
333
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
334 items_per_page = blog_cfg.get(
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
335 'posts_per_page', values['site']['posts_per_page'])
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
336 date_format = blog_cfg.get(
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
337 'date_format', values['site']['date_format'])
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
338 default_layout = blog_cfg.get(
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
339 'default_layout', values['site']['default_post_layout'])
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
340
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
341 post_url = '/' + blog_cfg.get(
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
342 'post_url',
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
343 url_prefix + values['site']['post_url']).lstrip('/')
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
344 tag_url = '/' + blog_cfg.get(
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
345 'tag_url',
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
346 url_prefix + values['site']['tag_url']).lstrip('/')
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
347 category_url = '/' + blog_cfg.get(
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
348 'category_url',
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
349 url_prefix + values['site']['category_url']).lstrip('/')
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
350
663
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
351 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
352 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
353 if not theme_site:
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
354 tags_taxonomy += ';theme_pages:_tag.%ext%'
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
355 category_taxonomy += ';theme_pages:_category.%ext%'
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
356
584
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
357 return collections.OrderedDict({
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
358 'site': collections.OrderedDict({
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
359 'sources': collections.OrderedDict({
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
360 blog_name: collections.OrderedDict({
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
361 'type': 'posts/%s' % posts_fs,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
362 'fs_endpoint': fs_endpoint,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
363 'data_endpoint': data_endpoint,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
364 'item_name': item_name,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
365 'ignore_missing_dir': True,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
366 'data_type': 'blog',
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
367 'items_per_page': items_per_page,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
368 'date_format': date_format,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
369 'default_layout': default_layout,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
370 'taxonomy_pages': collections.OrderedDict({
663
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
371 'tags': tags_taxonomy,
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
372 'categories': category_taxonomy
584
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
373 })
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
374 })
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
375 }),
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
376 'routes': [
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
377 {
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
378 'url': post_url,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
379 'source': blog_name,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
380 'func': 'pcposturl(year,month,day,slug)'
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 {
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
383 'url': tag_url,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
384 'source': blog_name,
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
385 'taxonomy': 'tags',
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
386 'func': 'pctagurl(tag)'
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': category_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': 'categories',
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
392 'func': 'pccaturl(category)'
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 })
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
396 })
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
397
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
398
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
399 # Configuration value validators.
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 # Make sure we have basic site stuff.
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
402 def _validate_site(v, values, cache):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
403 sources = v.get('sources')
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
404 if not sources:
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
405 raise ConfigurationError("No sources were defined.")
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
406 routes = v.get('routes')
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
407 if not routes:
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
408 raise ConfigurationError("No routes were defined.")
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
409 taxonomies = v.get('taxonomies')
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
410 if taxonomies is None:
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
411 v['taxonomies'] = {}
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
412 return v
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
413
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
414 # 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
415 def _validate_site_root(v, values, cache):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
416 if not v.startswith('/'):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
417 raise ConfigurationError("The `site/root` setting must start "
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
418 "with a slash.")
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
419 root_url = urllib.parse.quote(v.rstrip('/') + '/')
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
420 return root_url
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
421
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
422
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
423 # 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
424 def _validate_site_auto_formats(v, values, cache):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
425 if not isinstance(v, dict):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
426 raise ConfigurationError("The 'site/auto_formats' setting must be "
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
427 "a dictionary.")
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 v.setdefault('html', values['site']['default_format'])
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
430 auto_formats_re = r"\.(%s)$" % (
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
431 '|'.join(
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
432 [re.escape(i) for i in list(v.keys())]))
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
433 cache.write('auto_formats_re', auto_formats_re)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
434 return v
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
435
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
436
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
437 # Check that the default auto-format is known.
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
438 def _validate_site_default_auto_format(v, values, cache):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
439 if v not in values['site']['auto_formats']:
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
440 raise ConfigurationError(
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
441 "Default auto-format '%s' is not declared." % v)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
442 return v
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
443
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
444
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
445 # Cache pagination suffix regex and format.
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
446 def _validate_site_pagination_suffix(v, values, cache):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
447 if len(v) == 0 or v[0] != '/':
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
448 raise ConfigurationError("The 'site/pagination_suffix' setting "
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
449 "must start with a slash.")
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
450 if '%num%' not in v:
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
451 raise ConfigurationError("The 'site/pagination_suffix' setting "
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
452 "must contain the '%num%' placeholder.")
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
453
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
454 pgn_suffix_fmt = v.replace('%num%', '%(num)d')
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
455 cache.write('pagination_suffix_format', pgn_suffix_fmt)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
456
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
457 pgn_suffix_re = re.escape(v)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
458 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
459 '$')
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
460 cache.write('pagination_suffix_re', pgn_suffix_re)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
461 return v
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
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
464 # Make sure theme sources is a list.
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
465 def _validate_site_theme_sources(v, values, cache):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
466 if not isinstance(v, list):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
467 v = [v]
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
468 return v
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
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
471 def _validate_site_sources(v, values, cache):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
472 # Basic checks.
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
473 if not v:
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
474 raise ConfigurationError("There are no sources defined.")
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
475 if not isinstance(v, dict):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
476 raise ConfigurationError("The 'site/sources' setting must be a "
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
477 "dictionary.")
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
478
663
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
479 theme_site = values['site']['theme_site']
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
480 if not theme_site:
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
481 # Add the theme page source if no sources were defined in the theme
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
482 # configuration itself.
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
483 has_any_theme_source = False
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
484 for sn, sc in v.items():
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
485 if sc.get('realm') == REALM_THEME:
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
486 has_any_theme_source = True
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
487 break
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
488 if not has_any_theme_source:
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
489 v['theme_pages'] = {
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
490 'theme_source': True,
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
491 'fs_endpoint': 'pages',
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
492 'ignore_missing_dir': True,
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
493 'data_endpoint': 'site/pages',
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
494 'item_name': 'page',
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
495 'realm': REALM_THEME}
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
496 values['site']['routes'].append({
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
497 'url': '/%path:slug%',
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
498 'source': 'theme_pages',
3ceeca7bb71c themes: Add support for a `--theme` argument to `chef`.
Ludovic Chabant <ludovic@chabant.com>
parents: 585
diff changeset
499 'func': 'pcurl(slug)'})
584
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
500
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
501 # 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
502 # 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
503 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
504 'assets', 'pagination', 'siblings',
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
505 'family'])
584
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
506 for sn, sc in v.items():
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
507 if not isinstance(sc, dict):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
508 raise ConfigurationError("All sources in 'site/sources' must "
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
509 "be dictionaries.")
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
510 sc.setdefault('type', 'default')
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
511 sc.setdefault('fs_endpoint', sn)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
512 sc.setdefault('ignore_missing_dir', False)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
513 sc.setdefault('data_endpoint', sn)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
514 sc.setdefault('data_type', 'iterator')
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
515 sc.setdefault('item_name', sn)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
516 sc.setdefault('items_per_page', 5)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
517 sc.setdefault('date_format', DEFAULT_DATE_FORMAT)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
518 sc.setdefault('realm', REALM_USER)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
519
585
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
520 # Validate endpoints.
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
521 endpoint = sc['data_endpoint']
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
522 if endpoint in reserved_endpoints:
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
523 raise ConfigurationError(
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
524 "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
525 (sn, endpoint))
25df894f9ab9 internal: Some fixes to the new app configuration.
Ludovic Chabant <ludovic@chabant.com>
parents: 584
diff changeset
526
584
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
527 return v
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
528
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
529
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
530 def _validate_site_routes(v, values, cache):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
531 if not v:
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
532 raise ConfigurationError("There are no routes defined.")
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
533 if not isinstance(v, list):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
534 raise ConfigurationError("The 'site/routes' setting must be a "
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
535 "list.")
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
536
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
537 # Check routes are referencing correct sources, have default
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
538 # values, etc.
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
539 for rc in v:
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
540 if not isinstance(rc, dict):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
541 raise ConfigurationError("All routes in 'site/routes' must be "
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
542 "dictionaries.")
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
543 rc_url = rc.get('url')
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
544 if not rc_url:
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
545 raise ConfigurationError("All routes in 'site/routes' must "
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
546 "have an 'url'.")
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
547 if rc_url[0] != '/':
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
548 raise ConfigurationError("Route URLs must start with '/'.")
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
549 if rc.get('source') is None:
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
550 raise ConfigurationError("Routes must specify a source.")
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
551 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
552 raise ConfigurationError("Route is referencing unknown "
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
553 "source: %s" % rc['source'])
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
554 rc.setdefault('taxonomy', None)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
555 rc.setdefault('page_suffix', '/%num%')
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
556
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
557 return v
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
558
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
559
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
560 def _validate_site_taxonomies(v, values, cache):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
561 for tn, tc in v.items():
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
562 tc.setdefault('multiple', False)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
563 tc.setdefault('term', tn)
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
564 tc.setdefault('page', '_%s.%%ext%%' % tc['term'])
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
565
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
566 return v
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
567
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
568
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
569 def _validate_site_plugins(v, values, cache):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
570 if isinstance(v, str):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
571 v = v.split(',')
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
572 elif not isinstance(v, list):
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
573 raise ConfigurationError(
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
574 "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
575 "comma-separated list.")
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
576 return v
9ccc933ac2c7 internal: Refactor the app configuration class.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
577