comparison piecrust/sources/default.py @ 576:0c74a6c4533d

sources: Add code to support "interactive" metadata acquisition.
author Ludovic Chabant <ludovic@chabant.com>
date Sat, 19 Dec 2015 18:07:21 -0800
parents bab91fcef741
children ff404adfcf45
comparison
equal deleted inserted replaced
575:657384f08ca3 576:0c74a6c4533d
2 import logging 2 import logging
3 from piecrust import osutil 3 from piecrust import osutil
4 from piecrust.sources.base import ( 4 from piecrust.sources.base import (
5 PageFactory, PageSource, InvalidFileSystemEndpointError, 5 PageFactory, PageSource, InvalidFileSystemEndpointError,
6 MODE_CREATING) 6 MODE_CREATING)
7 from piecrust.sources.interfaces import IListableSource, IPreparingSource 7 from piecrust.sources.interfaces import (
8 IListableSource, IPreparingSource, IInteractiveSource,
9 InteractiveField)
8 from piecrust.sources.mixins import SimplePaginationSourceMixin 10 from piecrust.sources.mixins import SimplePaginationSourceMixin
9 11
10 12
11 logger = logging.getLogger(__name__) 13 logger = logging.getLogger(__name__)
12 14
19 return (f[0] != '.' and # .DS_store and other crap 21 return (f[0] != '.' and # .DS_store and other crap
20 f[-1] != '~' and # Vim temp files and what-not 22 f[-1] != '~' and # Vim temp files and what-not
21 f not in ['Thumbs.db']) # Windows bullshit 23 f not in ['Thumbs.db']) # Windows bullshit
22 24
23 25
24 class DefaultPageSource(PageSource, IListableSource, IPreparingSource, 26 class DefaultPageSource(PageSource,
27 IListableSource, IPreparingSource, IInteractiveSource,
25 SimplePaginationSourceMixin): 28 SimplePaginationSourceMixin):
26 SOURCE_NAME = 'default' 29 SOURCE_NAME = 'default'
27 30
28 def __init__(self, app, name, config): 31 def __init__(self, app, name, config):
29 super(DefaultPageSource, self).__init__(app, name, config) 32 super(DefaultPageSource, self).__init__(app, name, config)
132 parser.add_argument('uri', help='The URI for the new page.') 135 parser.add_argument('uri', help='The URI for the new page.')
133 136
134 def buildMetadata(self, args): 137 def buildMetadata(self, args):
135 return {'slug': args.uri} 138 return {'slug': args.uri}
136 139
140 def getInteractiveFields(self):
141 return [
142 InteractiveField('slug', InteractiveField.TYPE_STRING,
143 'new-page')]
144
137 def _makeSlug(self, rel_path): 145 def _makeSlug(self, rel_path):
138 slug, ext = os.path.splitext(rel_path) 146 slug, ext = os.path.splitext(rel_path)
139 slug = slug.replace('\\', '/') 147 slug = slug.replace('\\', '/')
140 if ext.lstrip('.') not in self.supported_extensions: 148 if ext.lstrip('.') not in self.supported_extensions:
141 slug += ext 149 slug += ext