Mercurial > piecrust2
comparison piecrust/app.py @ 67:563ce5dd02af
I don't care what the YAML spec says, ordered maps are the only sane way.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Fri, 29 Aug 2014 16:42:15 -0700 |
parents | 2d617b889b00 |
children | fdb08d986384 |
comparison
equal
deleted
inserted
replaced
66:e4a24512b814 | 67:563ce5dd02af |
---|---|
2 import json | 2 import json |
3 import os.path | 3 import os.path |
4 import codecs | 4 import codecs |
5 import hashlib | 5 import hashlib |
6 import logging | 6 import logging |
7 import collections | |
7 import yaml | 8 import yaml |
8 from werkzeug.utils import cached_property | 9 from werkzeug.utils import cached_property |
9 from piecrust import (APP_VERSION, | 10 from piecrust import (APP_VERSION, |
10 CACHE_DIR, TEMPLATES_DIR, ASSETS_DIR, | 11 CACHE_DIR, TEMPLATES_DIR, ASSETS_DIR, |
11 PLUGINS_DIR, THEME_DIR, | 12 PLUGINS_DIR, THEME_DIR, |
13 DEFAULT_FORMAT, DEFAULT_TEMPLATE_ENGINE, DEFAULT_POSTS_FS, | 14 DEFAULT_FORMAT, DEFAULT_TEMPLATE_ENGINE, DEFAULT_POSTS_FS, |
14 DEFAULT_DATE_FORMAT, DEFAULT_PLUGIN_SOURCE, DEFAULT_THEME_SOURCE) | 15 DEFAULT_DATE_FORMAT, DEFAULT_PLUGIN_SOURCE, DEFAULT_THEME_SOURCE) |
15 from piecrust.cache import ExtensibleCache, NullCache, NullExtensibleCache | 16 from piecrust.cache import ExtensibleCache, NullCache, NullExtensibleCache |
16 from piecrust.plugins.base import PluginLoader | 17 from piecrust.plugins.base import PluginLoader |
17 from piecrust.environment import StandardEnvironment | 18 from piecrust.environment import StandardEnvironment |
18 from piecrust.configuration import Configuration, ConfigurationError, merge_dicts | 19 from piecrust.configuration import (Configuration, ConfigurationError, |
20 OrderedDictYAMLLoader, merge_dicts) | |
19 from piecrust.routing import Route | 21 from piecrust.routing import Route |
20 from piecrust.sources.base import REALM_USER, REALM_THEME | 22 from piecrust.sources.base import REALM_USER, REALM_THEME |
21 from piecrust.taxonomies import Taxonomy | 23 from piecrust.taxonomies import Taxonomy |
22 | 24 |
23 | 25 |
62 APP_VERSION, CACHE_VERSION)).encode('utf8')).hexdigest() | 64 APP_VERSION, CACHE_VERSION)).encode('utf8')).hexdigest() |
63 | 65 |
64 if self.cache.isValid('config.json', path_times): | 66 if self.cache.isValid('config.json', path_times): |
65 logger.debug("Loading configuration from cache...") | 67 logger.debug("Loading configuration from cache...") |
66 config_text = self.cache.read('config.json') | 68 config_text = self.cache.read('config.json') |
67 self._values = json.loads(config_text) | 69 self._values = json.loads(config_text, |
70 object_pairs_hook=collections.OrderedDict) | |
68 | 71 |
69 actual_cache_key = self._values.get('__cache_key') | 72 actual_cache_key = self._values.get('__cache_key') |
70 if actual_cache_key == cache_key: | 73 if actual_cache_key == cache_key: |
71 self._values['__cache_valid'] = True | 74 self._values['__cache_valid'] = True |
72 return | 75 return |
75 | 78 |
76 values = {} | 79 values = {} |
77 logger.debug("Loading configuration from: %s" % self.paths) | 80 logger.debug("Loading configuration from: %s" % self.paths) |
78 for i, p in enumerate(self.paths): | 81 for i, p in enumerate(self.paths): |
79 with codecs.open(p, 'r', 'utf-8') as fp: | 82 with codecs.open(p, 'r', 'utf-8') as fp: |
80 loaded_values = yaml.load(fp.read()) | 83 loaded_values = yaml.load(fp.read(), |
84 Loader=OrderedDictYAMLLoader) | |
81 if loaded_values is None: | 85 if loaded_values is None: |
82 loaded_values = {} | 86 loaded_values = {} |
83 for fixup in self.fixups: | 87 for fixup in self.fixups: |
84 fixup(i, loaded_values) | 88 fixup(i, loaded_values) |
85 merge_dicts(values, loaded_values) | 89 merge_dicts(values, loaded_values) |