comparison piecrust/sources/posts.py @ 84:b3ce11b2cf36

Don't complain about missing `pages` or `posts` directories by default.
author Ludovic Chabant <ludovic@chabant.com>
date Wed, 03 Sep 2014 17:26:38 -0700
parents 838a9dd0e23c
children cb6eadea0845
comparison
equal deleted inserted replaced
82:ae90caf26224 84:b3ce11b2cf36
135 year, month, day = dt.year, dt.month, dt.day 135 year, month, day = dt.year, dt.month, dt.day
136 return {'year': year, 'month': month, 'day': day, 'slug': args.slug} 136 return {'year': year, 'month': month, 'day': day, 'slug': args.slug}
137 137
138 def _checkFsEndpointPath(self): 138 def _checkFsEndpointPath(self):
139 if not os.path.isdir(self.fs_endpoint_path): 139 if not os.path.isdir(self.fs_endpoint_path):
140 if self.ignore_missing_dir:
141 return False
140 raise InvalidFileSystemEndpointError(self.name, self.fs_endpoint_path) 142 raise InvalidFileSystemEndpointError(self.name, self.fs_endpoint_path)
143 return True
141 144
142 def _makeFactory(self, path, slug, year, month, day): 145 def _makeFactory(self, path, slug, year, month, day):
143 path = path.replace('\\', '/') 146 path = path.replace('\\', '/')
144 timestamp = datetime.date(year, month, day) 147 timestamp = datetime.date(year, month, day)
145 metadata = { 148 metadata = {
157 160
158 def __init__(self, app, name, config): 161 def __init__(self, app, name, config):
159 super(FlatPostsSource, self).__init__(app, name, config) 162 super(FlatPostsSource, self).__init__(app, name, config)
160 163
161 def buildPageFactories(self): 164 def buildPageFactories(self):
165 if not self._checkFsEndpointPath():
166 return
162 logger.debug("Scanning for posts (flat) in: %s" % self.fs_endpoint_path) 167 logger.debug("Scanning for posts (flat) in: %s" % self.fs_endpoint_path)
163 pattern = re.compile(r'(\d{4})-(\d{2})-(\d{2})_(.*)\.(\w+)$') 168 pattern = re.compile(r'(\d{4})-(\d{2})-(\d{2})_(.*)\.(\w+)$')
164 _, __, filenames = next(os.walk(self.fs_endpoint_path)) 169 _, __, filenames = next(os.walk(self.fs_endpoint_path))
165 for f in filenames: 170 for f in filenames:
166 match = pattern.match(f) 171 match = pattern.match(f)
183 188
184 def __init__(self, app, name, config): 189 def __init__(self, app, name, config):
185 super(ShallowPostsSource, self).__init__(app, name, config) 190 super(ShallowPostsSource, self).__init__(app, name, config)
186 191
187 def buildPageFactories(self): 192 def buildPageFactories(self):
193 if not self._checkFsEndpointPath():
194 return
188 logger.debug("Scanning for posts (shallow) in: %s" % self.fs_endpoint_path) 195 logger.debug("Scanning for posts (shallow) in: %s" % self.fs_endpoint_path)
189 year_pattern = re.compile(r'(\d{4})$') 196 year_pattern = re.compile(r'(\d{4})$')
190 file_pattern = re.compile(r'(\d{2})-(\d{2})_(.*)\.(\w+)$') 197 file_pattern = re.compile(r'(\d{2})-(\d{2})_(.*)\.(\w+)$')
191 _, year_dirs, __ = next(os.walk(self.fs_endpoint_path)) 198 _, year_dirs, __ = next(os.walk(self.fs_endpoint_path))
192 year_dirs = [d for d in year_dirs if year_pattern.match(d)] 199 year_dirs = [d for d in year_dirs if year_pattern.match(d)]
220 227
221 def __init__(self, app, name, config): 228 def __init__(self, app, name, config):
222 super(HierarchyPostsSource, self).__init__(app, name, config) 229 super(HierarchyPostsSource, self).__init__(app, name, config)
223 230
224 def buildPageFactories(self): 231 def buildPageFactories(self):
232 if not self._checkFsEndpointPath():
233 return
225 logger.debug("Scanning for posts (hierarchy) in: %s" % self.fs_endpoint_path) 234 logger.debug("Scanning for posts (hierarchy) in: %s" % self.fs_endpoint_path)
226 year_pattern = re.compile(r'(\d{4})$') 235 year_pattern = re.compile(r'(\d{4})$')
227 month_pattern = re.compile(r'(\d{2})$') 236 month_pattern = re.compile(r'(\d{2})$')
228 file_pattern = re.compile(r'(\d{2})_(.*)\.(\w+)$') 237 file_pattern = re.compile(r'(\d{2})_(.*)\.(\w+)$')
229 _, year_dirs, __ = next(os.walk(self.fs_endpoint_path)) 238 _, year_dirs, __ = next(os.walk(self.fs_endpoint_path))