def _loadRealmPages(self, record, pool, factories): def _handler(res): # Create the record entry for this page. # This will also update the `dirty_source_names` for the record # as we add page files whose last modification times are later # than the last bake. record_entry = BakeRecordEntry(res['source_name'], res['path']) record_entry.config = res['config'] if res['errors']: record_entry.errors += res['errors'] record.current.success = False self._logErrors(res['path'], res['errors']) record.addEntry(record_entry) logger.debug("Loading %d realm pages..." % len(factories)) with format_timed_scope(logger, "loaded %d pages" % len(factories), level=logging.DEBUG, colored=False, timer_env=self.app.env, timer_category='LoadJob'): jobs = [] for fac in factories: job = {'type': JOB_LOAD, 'job': save_factory(fac)} jobs.append(job) ar = pool.queueJobs(jobs, handler=_handler) ar.wait()
def _loadRealmPages(self, record, pool, factories): def _handler(res): # Create the record entry for this page. # This will also update the `dirty_source_names` for the record # as we add page files whose last modification times are later # than the last bake. record_entry = BakeRecordEntry(res['source_name'], res['path']) record_entry.config = res['config'] if res['errors']: record_entry.errors += res['errors'] record.current.success = False self._logErrors(res['path'], res['errors']) record.addEntry(record_entry) logger.debug("Loading %d realm pages..." % len(factories)) with format_timed_scope(logger, "loaded %d pages" % len(factories), level=logging.DEBUG, colored=False, timer_env=self.app.env, timer_category='LoadJob'): jobs = [] for fac in factories: job = { 'type': JOB_LOAD, 'job': save_factory(fac)} jobs.append(job) ar = pool.queueJobs(jobs, handler=_handler) ar.wait()
def _makeBakeJob(self, record, fac, tax_info=None): # Get the previous (if any) and current entry for this page. pair = record.getPreviousAndCurrentEntries(fac.path, tax_info) assert pair is not None prev_entry, cur_entry = pair assert cur_entry is not None # Ignore if there were errors in the previous passes. if cur_entry.errors: logger.debug("Ignoring %s because it had previous " "errors." % fac.ref_spec) return None # Build the route metadata and find the appropriate route. page = fac.buildPage() route_metadata = create_route_metadata(page) if tax_info is not None: tax = self.app.getTaxonomy(tax_info.taxonomy_name) route = self.app.getTaxonomyRoute(tax_info.taxonomy_name, tax_info.source_name) slugified_term = route.slugifyTaxonomyTerm(tax_info.term) route_metadata[tax.term_name] = slugified_term else: route = self.app.getRoute(fac.source.name, route_metadata, skip_taxonomies=True) assert route is not None # Figure out if this page is overriden by another previously # baked page. This happens for example when the user has # made a page that has the same page/URL as a theme page. uri = route.getUri(route_metadata) override_entry = record.getOverrideEntry(page.path, uri) if override_entry is not None: override_source = self.app.getSource( override_entry.source_name) if override_source.realm == fac.source.realm: cur_entry.errors.append( "Page '%s' maps to URL '%s' but is overriden " "by page '%s'." % (fac.ref_spec, uri, override_entry.path)) logger.error(cur_entry.errors[-1]) cur_entry.flags |= BakeRecordEntry.FLAG_OVERRIDEN return None job = { 'type': JOB_BAKE, 'job': { 'factory_info': save_factory(fac), 'taxonomy_info': tax_info, 'route_metadata': route_metadata, 'dirty_source_names': record.dirty_source_names } } return job
def _makeBakeJob(self, record, fac, tax_info=None): # Get the previous (if any) and current entry for this page. pair = record.getPreviousAndCurrentEntries(fac.path, tax_info) assert pair is not None prev_entry, cur_entry = pair assert cur_entry is not None # Ignore if there were errors in the previous passes. if cur_entry.errors: logger.debug("Ignoring %s because it had previous " "errors." % fac.ref_spec) return None # Build the route metadata and find the appropriate route. page = fac.buildPage() route_metadata = create_route_metadata(page) if tax_info is not None: tax = self.app.getTaxonomy(tax_info.taxonomy_name) route = self.app.getTaxonomyRoute(tax_info.taxonomy_name, tax_info.source_name) slugified_term = route.slugifyTaxonomyTerm(tax_info.term) route_metadata[tax.term_name] = slugified_term else: route = self.app.getRoute(fac.source.name, route_metadata, skip_taxonomies=True) assert route is not None # Figure out if this page is overriden by another previously # baked page. This happens for example when the user has # made a page that has the same page/URL as a theme page. uri = route.getUri(route_metadata) override_entry = record.getOverrideEntry(page.path, uri) if override_entry is not None: override_source = self.app.getSource(override_entry.source_name) if override_source.realm == fac.source.realm: cur_entry.errors.append( "Page '%s' maps to URL '%s' but is overriden " "by page '%s'." % (fac.ref_spec, uri, override_entry.path)) logger.error(cur_entry.errors[-1]) cur_entry.flags |= BakeRecordEntry.FLAG_OVERRIDEN return None job = { 'type': JOB_BAKE, 'job': { 'factory_info': save_factory(fac), 'taxonomy_info': tax_info, 'route_metadata': route_metadata, 'dirty_source_names': record.dirty_source_names } } return job
def _renderRealmPages(self, record, pool, factories): def _handler(res): entry = record.getCurrentEntry(res['path']) if res['errors']: entry.errors += res['errors'] record.current.success = False self._logErrors(res['path'], res['errors']) logger.debug("Rendering %d realm pages..." % len(factories)) with format_timed_scope(logger, "prepared %d pages" % len(factories), level=logging.DEBUG, colored=False, timer_env=self.app.env, timer_category='RenderFirstSubJob'): jobs = [] for fac in factories: record_entry = record.getCurrentEntry(fac.path) if record_entry.errors: logger.debug("Ignoring %s because it had previous " "errors." % fac.ref_spec) continue # Make sure the source and the route exist for this page, # otherwise we add errors to the record entry and we'll skip # this page for the rest of the bake. source = self.app.getSource(fac.source.name) if source is None: record_entry.errors.append( "Can't get source for page: %s" % fac.ref_spec) logger.error(record_entry.errors[-1]) continue route = self.app.getRoute(fac.source.name, fac.metadata, skip_taxonomies=True) if route is None: record_entry.errors.append("Can't get route for page: %s" % fac.ref_spec) logger.error(record_entry.errors[-1]) continue # All good, queue the job. job = {'type': JOB_RENDER_FIRST, 'job': save_factory(fac)} jobs.append(job) ar = pool.queueJobs(jobs, handler=_handler) ar.wait()
def _renderRealmPages(self, record, pool, factories): def _handler(res): entry = record.getCurrentEntry(res['path']) if res['errors']: entry.errors += res['errors'] record.current.success = False self._logErrors(res['path'], res['errors']) logger.debug("Rendering %d realm pages..." % len(factories)) with format_timed_scope(logger, "prepared %d pages" % len(factories), level=logging.DEBUG, colored=False, timer_env=self.app.env, timer_category='RenderFirstSubJob'): jobs = [] for fac in factories: record_entry = record.getCurrentEntry(fac.path) if record_entry.errors: logger.debug("Ignoring %s because it had previous " "errors." % fac.ref_spec) continue # Make sure the source and the route exist for this page, # otherwise we add errors to the record entry and we'll skip # this page for the rest of the bake. source = self.app.getSource(fac.source.name) if source is None: record_entry.errors.append( "Can't get source for page: %s" % fac.ref_spec) logger.error(record_entry.errors[-1]) continue route = self.app.getRoute(fac.source.name, fac.metadata, skip_taxonomies=True) if route is None: record_entry.errors.append( "Can't get route for page: %s" % fac.ref_spec) logger.error(record_entry.errors[-1]) continue # All good, queue the job. job = { 'type': JOB_RENDER_FIRST, 'job': save_factory(fac)} jobs.append(job) ar = pool.queueJobs(jobs, handler=_handler) ar.wait()
def queueBakeJob(self, page_fac, route, extra_route_metadata, seed): if self._is_running: raise Exception("The job queue is running.") extra_key = self.getRecordExtraKey(seed) entry = BakeRecordEntry( page_fac.source.name, page_fac.path, extra_key) self._record.addEntry(entry) page = page_fac.buildPage() route_metadata = create_route_metadata(page) route_metadata.update(extra_route_metadata) uri = route.getUri(route_metadata) override_entry = self._record.getOverrideEntry(page.path, uri) if override_entry is not None: override_source = self.app.getSource( override_entry.source_name) if override_source.realm == fac.source.realm: cur_entry.errors.append( "Page '%s' maps to URL '%s' but is overriden " "by page '%s'." % (fac.ref_spec, uri, override_entry.path)) logger.error(cur_entry.errors[-1]) cur_entry.flags |= BakeRecordEntry.FLAG_OVERRIDEN return route_index = self._app.routes.index(route) job = { 'type': JOB_BAKE, 'job': { 'factory_info': save_factory(page_fac), 'generator_name': self._generator.name, 'generator_record_key': extra_key, 'route_index': route_index, 'route_metadata': route_metadata, 'dirty_source_names': self._record.dirty_source_names, 'needs_config': True } } self._job_queue.append(job)