comparison piecrust/app.py @ 39:2f717f961996

Better error reporting and cache validation. Fix the processor pipeline in the preview server. Move the `pages` route to first position.
author Ludovic Chabant <ludovic@chabant.com>
date Thu, 21 Aug 2014 22:28:22 -0700
parents 485682a6de50
children 2d617b889b00
comparison
equal deleted inserted replaced
38:091f99bfbe44 39:2f717f961996
22 22
23 23
24 logger = logging.getLogger(__name__) 24 logger = logging.getLogger(__name__)
25 25
26 26
27 CACHE_VERSION = 12 27 CACHE_VERSION = 13
28 28
29 29
30 class VariantNotFoundError(Exception): 30 class VariantNotFoundError(Exception):
31 def __init__(self, variant_path, message=None): 31 def __init__(self, variant_path, message=None):
32 super(VariantNotFoundError, self).__init__( 32 super(VariantNotFoundError, self).__init__(
66 config_text = self.cache.read('config.json') 66 config_text = self.cache.read('config.json')
67 self._values = json.loads(config_text) 67 self._values = json.loads(config_text)
68 68
69 actual_cache_key = self._values.get('__cache_key') 69 actual_cache_key = self._values.get('__cache_key')
70 if actual_cache_key == cache_key: 70 if actual_cache_key == cache_key:
71 self._values['__cache_valid'] = True
71 return 72 return
72 logger.debug("Outdated cache key '%s' (expected '%s')." % ( 73 logger.debug("Outdated cache key '%s' (expected '%s')." % (
73 actual_cache_key, cache_key)) 74 actual_cache_key, cache_key))
74 75
75 values = {} 76 values = {}
90 91
91 logger.debug("Caching configuration...") 92 logger.debug("Caching configuration...")
92 self._values['__cache_key'] = cache_key 93 self._values['__cache_key'] = cache_key
93 config_text = json.dumps(self._values) 94 config_text = json.dumps(self._values)
94 self.cache.write('config.json', config_text) 95 self.cache.write('config.json', config_text)
96 self._values['__cache_valid'] = False
95 97
96 def _validateAll(self, values): 98 def _validateAll(self, values):
97 # Put all the defaults in the `site` section. 99 # Put all the defaults in the `site` section.
98 default_sitec = { 100 default_sitec = {
99 'title': "Untitled PieCrust website", 101 'title': "Untitled PieCrust website",
179 'data_endpoint': 'site/pages', 181 'data_endpoint': 'site/pages',
180 'item_name': 'page'} 182 'item_name': 'page'}
181 sitec['sources'] = sourcesc 183 sitec['sources'] = sourcesc
182 184
183 routesc = [] 185 routesc = []
186 routesc.append({
187 'url': '/%path:path%',
188 'source': 'pages',
189 'func': 'pcurl(path)'})
184 sitec['routes'] = routesc 190 sitec['routes'] = routesc
185 191
186 taxonomiesc = {} 192 taxonomiesc = {}
187 taxonomiesc['tags'] = { 193 taxonomiesc['tags'] = {
188 'multiple': True, 194 'multiple': True,
236 'func': 'pctagurl(tag)'}) 242 'func': 'pctagurl(tag)'})
237 routesc.append({'url': category_url, 'source': blog_name, 243 routesc.append({'url': category_url, 'source': blog_name,
238 'taxonomy': 'categories', 244 'taxonomy': 'categories',
239 'func': 'pccaturl(category)'}) 245 'func': 'pccaturl(category)'})
240 246
241 routesc.append({'url': '/%path:path%', 'source': 'pages',
242 'func': 'pcurl(path)'})
243
244 # Validate sources/routes. 247 # Validate sources/routes.
245 sourcesc = sitec.get('sources') 248 sourcesc = sitec.get('sources')
246 routesc = sitec.get('routes') 249 routesc = sitec.get('routes')
247 if not sourcesc: 250 if not sourcesc:
248 raise ConfigurationError("There are no sources defined.") 251 raise ConfigurationError("There are no sources defined.")