Mercurial > piecrust2
comparison piecrust/baking/single.py @ 430:21e26ed867b6
internal: Create full route metadata in one place.
Instead of combining things at different moments to make up route metadata,
build it once and for all up-front and use that.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sat, 27 Jun 2015 08:27:35 -0700 |
parents | 0e9a94b7fdfa |
children | dc78ade3f320 |
comparison
equal
deleted
inserted
replaced
429:ca5a3c970263 | 430:21e26ed867b6 |
---|---|
12 | 12 |
13 | 13 |
14 logger = logging.getLogger(__name__) | 14 logger = logging.getLogger(__name__) |
15 | 15 |
16 | 16 |
17 def copy_public_page_config(config): | |
18 res = config.getDeepcopy() | |
19 for k in list(res.keys()): | |
20 if k.startswith('__'): | |
21 del res[k] | |
22 return res | |
23 | |
24 | |
25 class BakingError(Exception): | 17 class BakingError(Exception): |
26 pass | 18 pass |
27 | 19 |
28 | 20 |
29 class PageBaker(object): | 21 class PageBaker(object): |
48 else: | 40 else: |
49 bake_path.append(decoded_uri) | 41 bake_path.append(decoded_uri) |
50 | 42 |
51 return os.path.normpath(os.path.join(*bake_path)) | 43 return os.path.normpath(os.path.join(*bake_path)) |
52 | 44 |
53 def bake(self, factory, route, route_metadata, prev_entry, | 45 def bake(self, qualified_page, prev_entry, dirty_source_names, |
54 dirty_source_names, tax_info=None): | 46 tax_info=None): |
55 # Get the page. | |
56 page = factory.buildPage() | |
57 | |
58 # Start baking the sub-pages. | 47 # Start baking the sub-pages. |
59 cur_sub = 1 | 48 cur_sub = 1 |
60 has_more_subs = True | 49 has_more_subs = True |
61 sub_entries = [] | 50 sub_entries = [] |
62 | 51 |
63 while has_more_subs: | 52 while has_more_subs: |
64 # Get the URL and path for this sub-page. | 53 # Get the URL and path for this sub-page. |
65 sub_uri = route.getUri(route_metadata, sub_num=cur_sub, | 54 sub_uri = qualified_page.getUri(cur_sub) |
66 provider=page) | |
67 logger.debug("Baking '%s' [%d]..." % (sub_uri, cur_sub)) | 55 logger.debug("Baking '%s' [%d]..." % (sub_uri, cur_sub)) |
68 out_path = self.getOutputPath(sub_uri) | 56 out_path = self.getOutputPath(sub_uri) |
69 | 57 |
70 # Create the sub-entry for the bake record. | 58 # Create the sub-entry for the bake record. |
71 sub_entry = SubPageBakeInfo(sub_uri, out_path) | 59 sub_entry = SubPageBakeInfo(sub_uri, out_path) |
86 | 74 |
87 # Check for up-to-date outputs. | 75 # Check for up-to-date outputs. |
88 do_bake = True | 76 do_bake = True |
89 if not force_this_sub: | 77 if not force_this_sub: |
90 try: | 78 try: |
91 in_path_time = page.path_mtime | 79 in_path_time = qualified_page.path_mtime |
92 out_path_time = os.path.getmtime(out_path) | 80 out_path_time = os.path.getmtime(out_path) |
93 if out_path_time >= in_path_time: | 81 if out_path_time >= in_path_time: |
94 do_bake = False | 82 do_bake = False |
95 except OSError: | 83 except OSError: |
96 # File doesn't exist, we'll need to bake. | 84 # File doesn't exist, we'll need to bake. |
120 cache_key) | 108 cache_key) |
121 sub_entry.flags |= \ | 109 sub_entry.flags |= \ |
122 SubPageBakeInfo.FLAG_FORMATTING_INVALIDATED | 110 SubPageBakeInfo.FLAG_FORMATTING_INVALIDATED |
123 | 111 |
124 logger.debug(" p%d -> %s" % (cur_sub, out_path)) | 112 logger.debug(" p%d -> %s" % (cur_sub, out_path)) |
125 qp = QualifiedPage(page, route, route_metadata) | 113 rp = self._bakeSingle(qualified_page, cur_sub, out_path, |
126 rp = self._bakeSingle(qp, cur_sub, out_path, tax_info) | 114 tax_info) |
127 except Exception as ex: | 115 except Exception as ex: |
128 page_rel_path = os.path.relpath(page.path, self.app.root_dir) | 116 page_rel_path = os.path.relpath(qualified_page.path, |
117 self.app.root_dir) | |
129 raise BakingError("%s: error baking '%s'." % | 118 raise BakingError("%s: error baking '%s'." % |
130 (page_rel_path, sub_uri)) from ex | 119 (page_rel_path, sub_uri)) from ex |
131 | 120 |
132 # Record what we did. | 121 # Record what we did. |
133 sub_entry.flags |= SubPageBakeInfo.FLAG_BAKED | 122 sub_entry.flags |= SubPageBakeInfo.FLAG_BAKED |
145 out_assets_dir += out_name_noext | 134 out_assets_dir += out_name_noext |
146 | 135 |
147 logger.debug("Copying page assets to: %s" % out_assets_dir) | 136 logger.debug("Copying page assets to: %s" % out_assets_dir) |
148 _ensure_dir_exists(out_assets_dir) | 137 _ensure_dir_exists(out_assets_dir) |
149 | 138 |
150 page_dirname = os.path.dirname(page.path) | 139 page_dirname = os.path.dirname(qualified_page.path) |
151 page_pathname, _ = os.path.splitext(page.path) | 140 page_pathname, _ = os.path.splitext(qualified_page.path) |
152 in_assets_dir = page_pathname + ASSET_DIR_SUFFIX | 141 in_assets_dir = page_pathname + ASSET_DIR_SUFFIX |
153 for fn in os.listdir(in_assets_dir): | 142 for fn in os.listdir(in_assets_dir): |
154 full_fn = os.path.join(page_dirname, fn) | 143 full_fn = os.path.join(page_dirname, fn) |
155 if os.path.isfile(full_fn): | 144 if os.path.isfile(full_fn): |
156 dest_ap = os.path.join(out_assets_dir, fn) | 145 dest_ap = os.path.join(out_assets_dir, fn) |