Mercurial > piecrust2
comparison piecrust/app.py @ 257:e6ae65212c32
cosmetic: PEP8 compliance.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 22 Feb 2015 22:02:28 -0800 |
parents | da5e6e00fb41 |
children | 07b4b8484c0a |
comparison
equal
deleted
inserted
replaced
256:da5e6e00fb41 | 257:e6ae65212c32 |
---|---|
134 cachec = collections.OrderedDict() | 134 cachec = collections.OrderedDict() |
135 values['__cache'] = cachec | 135 values['__cache'] = cachec |
136 | 136 |
137 # Cache auto-format regexes. | 137 # Cache auto-format regexes. |
138 if not isinstance(sitec['auto_formats'], dict): | 138 if not isinstance(sitec['auto_formats'], dict): |
139 raise ConfigurationError("The 'site/auto_formats' setting must be a dictionary.") | 139 raise ConfigurationError("The 'site/auto_formats' setting must be " |
140 "a dictionary.") | |
140 html_auto_format = sitec['auto_formats'] | 141 html_auto_format = sitec['auto_formats'] |
141 if not html_auto_format: | 142 if not html_auto_format: |
142 sitec['auto_formats']['html'] = sitec['default_format'] | 143 sitec['auto_formats']['html'] = sitec['default_format'] |
143 cachec['auto_formats_re'] = r"\.(%s)$" % ( | 144 cachec['auto_formats_re'] = r"\.(%s)$" % ( |
144 '|'.join( | 145 '|'.join( |
145 [re.escape(i) for i in list(sitec['auto_formats'].keys())])) | 146 [re.escape(i) for i in |
147 list(sitec['auto_formats'].keys())])) | |
146 if sitec['default_auto_format'] not in sitec['auto_formats']: | 148 if sitec['default_auto_format'] not in sitec['auto_formats']: |
147 raise ConfigurationError("Default auto-format '%s' is not declared." % sitec['default_auto_format']) | 149 raise ConfigurationError("Default auto-format '%s' is not " |
150 "declared." % | |
151 sitec['default_auto_format']) | |
148 | 152 |
149 # Cache pagination suffix regex and format. | 153 # Cache pagination suffix regex and format. |
150 pgn_suffix = sitec['pagination_suffix'] | 154 pgn_suffix = sitec['pagination_suffix'] |
151 if len(pgn_suffix) == 0 or pgn_suffix[0] != '/': | 155 if len(pgn_suffix) == 0 or pgn_suffix[0] != '/': |
152 raise ConfigurationError("The 'site/pagination_suffix' setting " | 156 raise ConfigurationError("The 'site/pagination_suffix' setting " |
290 if not sourcesc: | 294 if not sourcesc: |
291 raise ConfigurationError("There are no sources defined.") | 295 raise ConfigurationError("There are no sources defined.") |
292 if not routesc: | 296 if not routesc: |
293 raise ConfigurationError("There are no routes defined.") | 297 raise ConfigurationError("There are no routes defined.") |
294 if not isinstance(sourcesc, dict): | 298 if not isinstance(sourcesc, dict): |
295 raise ConfigurationError("The 'site/sources' setting must be a dictionary.") | 299 raise ConfigurationError("The 'site/sources' setting must be a " |
300 "dictionary.") | |
296 if not isinstance(routesc, list): | 301 if not isinstance(routesc, list): |
297 raise ConfigurationError("The 'site/routes' setting must be a list.") | 302 raise ConfigurationError("The 'site/routes' setting must be a " |
303 "list.") | |
298 | 304 |
299 # Add the theme page source if no sources were defined in the theme | 305 # Add the theme page source if no sources were defined in the theme |
300 # configuration itself. | 306 # configuration itself. |
301 has_any_theme_source = False | 307 has_any_theme_source = False |
302 for sn, sc in sourcesc.items(): | 308 for sn, sc in sourcesc.items(): |
317 | 323 |
318 # Sources have the `default` scanner by default, duh. Also, a bunch | 324 # Sources have the `default` scanner by default, duh. Also, a bunch |
319 # of other default values for other configuration stuff. | 325 # of other default values for other configuration stuff. |
320 for sn, sc in sourcesc.items(): | 326 for sn, sc in sourcesc.items(): |
321 if not isinstance(sc, dict): | 327 if not isinstance(sc, dict): |
322 raise ConfigurationError("All sources in 'site/sources' must be dictionaries.") | 328 raise ConfigurationError("All sources in 'site/sources' must " |
329 "be dictionaries.") | |
323 sc.setdefault('type', 'default') | 330 sc.setdefault('type', 'default') |
324 sc.setdefault('fs_endpoint', sn) | 331 sc.setdefault('fs_endpoint', sn) |
325 sc.setdefault('ignore_missing_dir', False) | 332 sc.setdefault('ignore_missing_dir', False) |
326 sc.setdefault('data_endpoint', sn) | 333 sc.setdefault('data_endpoint', sn) |
327 sc.setdefault('data_type', 'iterator') | 334 sc.setdefault('data_type', 'iterator') |
332 | 339 |
333 # Check routes are referencing correct routes, have default | 340 # Check routes are referencing correct routes, have default |
334 # values, etc. | 341 # values, etc. |
335 for rc in routesc: | 342 for rc in routesc: |
336 if not isinstance(rc, dict): | 343 if not isinstance(rc, dict): |
337 raise ConfigurationError("All routes in 'site/routes' must be dictionaries.") | 344 raise ConfigurationError("All routes in 'site/routes' must be " |
345 "dictionaries.") | |
338 rc_url = rc.get('url') | 346 rc_url = rc.get('url') |
339 if not rc_url: | 347 if not rc_url: |
340 raise ConfigurationError("All routes in 'site/routes' must have an 'url'.") | 348 raise ConfigurationError("All routes in 'site/routes' must " |
349 "have an 'url'.") | |
341 if rc_url[0] != '/': | 350 if rc_url[0] != '/': |
342 raise ConfigurationError("Route URLs must start with '/'.") | 351 raise ConfigurationError("Route URLs must start with '/'.") |
343 if rc.get('source') is None: | 352 if rc.get('source') is None: |
344 raise ConfigurationError("Routes must specify a source.") | 353 raise ConfigurationError("Routes must specify a source.") |
345 if rc['source'] not in list(sourcesc.keys()): | 354 if rc['source'] not in list(sourcesc.keys()): |
346 raise ConfigurationError("Route is referencing unknown source: %s" % | 355 raise ConfigurationError("Route is referencing unknown " |
347 rc['source']) | 356 "source: %s" % rc['source']) |
348 rc.setdefault('taxonomy', None) | 357 rc.setdefault('taxonomy', None) |
349 rc.setdefault('page_suffix', '/%num%') | 358 rc.setdefault('page_suffix', '/%num%') |
350 | 359 |
351 # Validate taxonomies. | 360 # Validate taxonomies. |
352 sitec.setdefault('taxonomies', {}) | 361 sitec.setdefault('taxonomies', {}) |
364 endpoint = src['data_endpoint'] | 373 endpoint = src['data_endpoint'] |
365 if endpoint in reserved_endpoints: | 374 if endpoint in reserved_endpoints: |
366 raise ConfigurationError( | 375 raise ConfigurationError( |
367 "Source '%s' is using a reserved endpoint name: %s" % | 376 "Source '%s' is using a reserved endpoint name: %s" % |
368 (name, endpoint)) | 377 (name, endpoint)) |
369 | |
370 | 378 |
371 # Done validating! | 379 # Done validating! |
372 return values | 380 return values |
373 | 381 |
374 | 382 |