Mercurial > piecrust2
comparison piecrust/sources/posts.py @ 516:73bd408caebc
internal: Return `None` instead of raising an exception when finding pages.
This makes the `posts` source behave like the other ones.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Mon, 27 Jul 2015 00:47:55 -0700 |
parents | dd25bd3ce1f9 |
children | bab91fcef741 |
comparison
equal
deleted
inserted
replaced
515:16e705c58cae | 516:73bd408caebc |
---|---|
7 from piecrust.sources.base import ( | 7 from piecrust.sources.base import ( |
8 PageSource, InvalidFileSystemEndpointError, PageFactory, | 8 PageSource, InvalidFileSystemEndpointError, PageFactory, |
9 MODE_CREATING, MODE_PARSING) | 9 MODE_CREATING, MODE_PARSING) |
10 from piecrust.sources.interfaces import IPreparingSource | 10 from piecrust.sources.interfaces import IPreparingSource |
11 from piecrust.sources.mixins import SimplePaginationSourceMixin | 11 from piecrust.sources.mixins import SimplePaginationSourceMixin |
12 from piecrust.sources.pageref import PageNotFoundError | |
13 | 12 |
14 | 13 |
15 logger = logging.getLogger(__name__) | 14 logger = logging.getLogger(__name__) |
16 | 15 |
17 | 16 |
86 if needs_recapture: | 85 if needs_recapture: |
87 if mode == MODE_CREATING: | 86 if mode == MODE_CREATING: |
88 raise ValueError("Not enough information to find a post path.") | 87 raise ValueError("Not enough information to find a post path.") |
89 possible_paths = glob.glob(path) | 88 possible_paths = glob.glob(path) |
90 if len(possible_paths) != 1: | 89 if len(possible_paths) != 1: |
91 raise PageNotFoundError() | 90 return None |
92 path = possible_paths[0] | 91 path = possible_paths[0] |
93 elif mode == MODE_PARSING and not os.path.isfile(path): | 92 elif mode == MODE_PARSING and not os.path.isfile(path): |
94 raise PageNotFoundError(path) | 93 return None |
95 | 94 |
96 rel_path = os.path.relpath(path, self.fs_endpoint_path) | 95 rel_path = os.path.relpath(path, self.fs_endpoint_path) |
97 rel_path = rel_path.replace('\\', '/') | 96 rel_path = rel_path.replace('\\', '/') |
98 fac_metadata = self._parseMetadataFromPath(rel_path) | 97 fac_metadata = self._parseMetadataFromPath(rel_path) |
99 return PageFactory(self, rel_path, fac_metadata) | 98 return PageFactory(self, rel_path, fac_metadata) |