comparison piecrust/sources/fs.py @ 862:fddaf43424e2

refactor: Get the page assets to work again in the server.
author Ludovic Chabant <ludovic@chabant.com>
date Thu, 08 Jun 2017 23:09:34 -0700
parents 448710d84121
children d9059257743c
comparison
equal deleted inserted replaced
861:d214918d4d2c 862:fddaf43424e2
5 import logging 5 import logging
6 from piecrust import osutil 6 from piecrust import osutil
7 from piecrust.routing import RouteParameter 7 from piecrust.routing import RouteParameter
8 from piecrust.sources.base import ( 8 from piecrust.sources.base import (
9 ContentItem, ContentGroup, ContentSource, 9 ContentItem, ContentGroup, ContentSource,
10 REL_PARENT_GROUP, REL_LOGICAL_PARENT_ITEM, REL_LOGICAl_CHILD_GROUP) 10 REL_LOGICAL_PARENT_ITEM, REL_LOGICAl_CHILD_GROUP)
11 11
12 12
13 logger = logging.getLogger(__name__) 13 logger = logging.getLogger(__name__)
14 14
15 15
108 metadata = self._createItemMetadata(path) 108 metadata = self._createItemMetadata(path)
109 items.append(ContentItem(path, metadata)) 109 items.append(ContentItem(path, metadata))
110 self._finalizeContent(group, items, groups) 110 self._finalizeContent(group, items, groups)
111 return items + groups 111 return items + groups
112 112
113 def getParentGroup(self, item):
114 parent_dir = os.path.dirname(item.spec)
115 if len(parent_dir) >= len(self.fs_endpoint_path):
116 metadata = self._createGroupMetadata(parent_dir)
117 return ContentGroup(parent_dir, metadata)
118
119 # Don't return a group for paths that are outside of our
120 # endpoint directory.
121 return None
122
113 def _filterIgnored(self, path): 123 def _filterIgnored(self, path):
114 rel_path = os.path.relpath(path, self.fs_endpoint_path) 124 rel_path = os.path.relpath(path, self.fs_endpoint_path)
115 for g in self._ignore_globs: 125 for g in self._ignore_globs:
116 if fnmatch.fnmatch(rel_path, g): 126 if fnmatch.fnmatch(rel_path, g):
117 return True 127 return True
128 138
129 def _finalizeContent(self, parent_group, items, groups): 139 def _finalizeContent(self, parent_group, items, groups):
130 pass 140 pass
131 141
132 def getRelatedContents(self, item, relationship): 142 def getRelatedContents(self, item, relationship):
133 if relationship == REL_PARENT_GROUP:
134 parent_dir = os.path.dirname(item.spec)
135 if len(parent_dir) >= len(self.fs_endpoint_path):
136 metadata = self._createGroupMetadata(parent_dir)
137 return ContentGroup(parent_dir, metadata)
138
139 # Don't return a group for paths that are outside of our
140 # endpoint directory.
141 return None
142
143 if relationship == REL_LOGICAL_PARENT_ITEM: 143 if relationship == REL_LOGICAL_PARENT_ITEM:
144 # If we want the logical parent item of a folder, we find a 144 # If we want the logical parent item of a folder, we find a
145 # page file with the same name as the folder. 145 # page file with the same name as the folder.
146 if not item.is_group: 146 if not item.is_group:
147 raise ValueError() 147 raise ValueError()