コード例 #1
0
ファイル: worker.py プロジェクト: germanschnyder/PieCrust2
class BakeJobHandler(JobHandler):
    def __init__(self, ctx):
        super(BakeJobHandler, self).__init__(ctx)
        self.page_baker = PageBaker(ctx.app, ctx.out_dir, ctx.force)

    def shutdown(self):
        self.page_baker.shutdown()

    def handleJob(self, job):
        # Actually bake the page and all its sub-pages to the output folder.
        fac = load_factory(self.app, job['factory_info'])
        self.app.env.addManifestEntry('BakeJobs', fac.ref_spec)

        route_index = job['route_index']
        route_metadata = job['route_metadata']
        route = self.app.routes[route_index]

        gen_name = job['generator_name']
        gen_key = job['generator_record_key']
        dirty_source_names = job['dirty_source_names']

        page = fac.buildPage()
        qp = QualifiedPage(page, route, route_metadata)

        result = {
                'path': fac.path,
                'generator_name': gen_name,
                'generator_record_key': gen_key,
                'sub_entries': None,
                'errors': None}

        if job.get('needs_config', False):
            result['config'] = page.config.getAll()

        previous_entry = None
        if self.ctx.previous_record_index is not None:
            key = _get_transition_key(fac.path, gen_key)
            previous_entry = self.ctx.previous_record_index.get(key)

        logger.debug("Baking page: %s" % fac.ref_spec)
        logger.debug("With route metadata: %s" % route_metadata)
        try:
            sub_entries = self.page_baker.bake(
                    qp, previous_entry, dirty_source_names, gen_name)
            result['sub_entries'] = sub_entries

        except BakingError as ex:
            logger.debug("Got baking error. Sending it to master.")
            result['errors'] = _get_errors(ex)
            if self.ctx.app.debug:
                logger.exception(ex)

        return result
コード例 #2
0
def test_get_output_path(uri, pretty, expected):
    app = get_mock_app()
    if pretty:
        app.config.set('site/pretty_urls', True)
    assert app.config.get('site/pretty_urls') == pretty

    for site_root in ['/', '/whatever/', '/~johndoe/']:
        app.config.set('site/root', urllib.parse.quote(site_root))
        baker = PageBaker(app, '/destination')
        try:
            path = baker.getOutputPath(urllib.parse.quote(site_root) + uri)
            expected = os.path.normpath(
                    os.path.join('/destination', expected))
            assert expected == path
        finally:
            baker.shutdown()