comparison piecrust/sources/base.py @ 5:474c9882decf

Upgrade to Python 3.
author Ludovic Chabant <ludovic@chabant.com>
date Mon, 11 Aug 2014 22:36:47 -0700
parents f485ba500df3
children f5ca5c5bed85
comparison
equal deleted inserted replaced
4:7dc71c2dc9a8 5:474c9882decf
101 def __init__(self, app, page_ref): 101 def __init__(self, app, page_ref):
102 self.app = app 102 self.app = app
103 self._page_ref = page_ref 103 self._page_ref = page_ref
104 self._paths = None 104 self._paths = None
105 self._first_valid_path_index = -2 105 self._first_valid_path_index = -2
106 self._exts = app.config.get('site/auto_formats').keys() 106 self._exts = list(app.config.get('site/auto_formats').keys())
107 107
108 @property 108 @property
109 def exists(self): 109 def exists(self):
110 try: 110 try:
111 self._checkPaths() 111 self._checkPaths()
264 class SimplePageSource(PageSource): 264 class SimplePageSource(PageSource):
265 def __init__(self, app, name, config): 265 def __init__(self, app, name, config):
266 super(SimplePageSource, self).__init__(app, name, config) 266 super(SimplePageSource, self).__init__(app, name, config)
267 self.fs_endpoint = config.get('fs_endpoint', name) 267 self.fs_endpoint = config.get('fs_endpoint', name)
268 self.fs_endpoint_path = os.path.join(self.root_dir, CONTENT_DIR, self.fs_endpoint) 268 self.fs_endpoint_path = os.path.join(self.root_dir, CONTENT_DIR, self.fs_endpoint)
269 self.supported_extensions = app.config.get('site/auto_formats').keys() 269 self.supported_extensions = list(app.config.get('site/auto_formats').keys())
270 270
271 def buildPageFactories(self): 271 def buildPageFactories(self):
272 logger.debug("Scanning for pages in: %s" % self.fs_endpoint_path) 272 logger.debug("Scanning for pages in: %s" % self.fs_endpoint_path)
273 if not os.path.isdir(self.fs_endpoint_path): 273 if not os.path.isdir(self.fs_endpoint_path):
274 raise InvalidFileSystemEndpointError(self.name, self.fs_endpoint_path) 274 raise InvalidFileSystemEndpointError(self.name, self.fs_endpoint_path)
275 275
276 for dirpath, dirnames, filenames in os.walk(self.fs_endpoint_path): 276 for dirpath, dirnames, filenames in os.walk(self.fs_endpoint_path):
277 rel_dirpath = os.path.relpath(dirpath, self.fs_endpoint_path) 277 rel_dirpath = os.path.relpath(dirpath, self.fs_endpoint_path)
278 dirnames[:] = filter(self._filterPageDirname, dirnames) 278 dirnames[:] = list(filter(self._filterPageDirname, dirnames))
279 for f in filter(self._filterPageFilename, filenames): 279 for f in filter(self._filterPageFilename, filenames):
280 slug, ext = os.path.splitext(os.path.join(rel_dirpath, f)) 280 slug, ext = os.path.splitext(os.path.join(rel_dirpath, f))
281 if slug.startswith('./') or slug.startswith('.\\'): 281 if slug.startswith('./') or slug.startswith('.\\'):
282 slug = slug[2:] 282 slug = slug[2:]
283 if slug == '_index': 283 if slug == '_index':