comparison piecrust/sources/prose.py @ 853:f070a4fc033c

core: Continue PieCrust3 refactor, simplify pages. The asset pipeline is still the only function pipeline at this point. * No more `QualifiedPage`, and several other pieces of code deleted. * Data providers are simpler and more focused. For instance, the page iterator doesn't try to support other types of items. * Route parameters are proper known source metadata to remove the confusion between the two. * Make the baker and pipeline more correctly manage records and record histories. * Add support for record collapsing and deleting stale outputs in the asset pipeline.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 21 May 2017 00:06:59 -0700
parents 4850f8c21b6e
children d9059257743c
comparison
equal deleted inserted replaced
852:4850f8c21b6e 853:f070a4fc033c
1 import os
2 import os.path
3 import copy 1 import copy
4 import logging 2 import logging
5 from piecrust.sources.default import DefaultContentSource 3 from piecrust.sources.default import DefaultContentSource
6 4
7 5
10 8
11 class ProseSource(DefaultContentSource): 9 class ProseSource(DefaultContentSource):
12 SOURCE_NAME = 'prose' 10 SOURCE_NAME = 'prose'
13 11
14 def __init__(self, app, name, config): 12 def __init__(self, app, name, config):
15 super(ProseSource, self).__init__(app, name, config) 13 super().__init__(app, name, config)
16 self.config_recipe = config.get('config', {}) 14 self.config_recipe = config.get('config', {})
17 15
18 def _populateMetadata(self, rel_path, metadata, mode=None): 16 def _doCreateItemMetadata(self, path):
19 metadata['config'] = self._makeConfig(rel_path, mode) 17 metadata = super()._doCreateItemMetadata(path)
18 config = metadata.setdefault('config', {})
19 config.update(self._makeConfig(path))
20 return config
20 21
21 def _makeConfig(self, rel_path, mode): 22 def _makeConfig(self, path):
22 c = copy.deepcopy(self.config_recipe) 23 c = copy.deepcopy(self.config_recipe)
23 if c.get('title') == '%first_line%' and mode != MODE_CREATING: 24 if c.get('title') == '%first_line%':
24 path = os.path.join(self.fs_endpoint_path, rel_path) 25 c['title'] = get_first_line(path)
25 try:
26 c['title'] = get_first_line(path)
27 except IOError:
28 if mode == MODE_PARSING:
29 raise
30 return c 26 return c
31 27
32 28
33 def get_first_line(path): 29 def get_first_line(path):
34 with open(path, 'r') as f: 30 with open(path, 'r') as f: