예제 #1
0
async def _generate(app: App) -> None:
    logger = logging.getLogger()
    await app.assets.copytree(join('public', 'static'),
                              app.configuration.www_directory_path)
    await app.renderer.render_tree(app.configuration.www_directory_path)
    for locale, locale_configuration in app.configuration.locales.items():
        async with app.with_locale(locale) as app:
            if app.configuration.multilingual:
                www_directory_path = join(app.configuration.www_directory_path,
                                          locale_configuration.alias)
            else:
                www_directory_path = app.configuration.www_directory_path

            await app.assets.copytree(join('public', 'localized'),
                                      www_directory_path)
            await app.renderer.render_tree(www_directory_path)

            locale_label = Locale.parse(locale, '-').get_display_name()
            await _generate_entity_type(www_directory_path,
                                        app.ancestry.files.values(), 'file',
                                        app, locale, app.jinja2_environment)
            logger.info('Generated pages for %d files in %s.' %
                        (len(app.ancestry.files), locale_label))
            await _generate_entity_type(www_directory_path,
                                        app.ancestry.people.values(), 'person',
                                        app, locale, app.jinja2_environment)
            logger.info('Generated pages for %d people in %s.' %
                        (len(app.ancestry.people), locale_label))
            await _generate_entity_type(www_directory_path,
                                        app.ancestry.places.values(), 'place',
                                        app, locale, app.jinja2_environment)
            logger.info('Generated pages for %d places in %s.' %
                        (len(app.ancestry.places), locale_label))
            await _generate_entity_type(www_directory_path,
                                        app.ancestry.events.values(), 'event',
                                        app, locale, app.jinja2_environment)
            logger.info('Generated pages for %d events in %s.' %
                        (len(app.ancestry.events), locale_label))
            await _generate_entity_type(www_directory_path,
                                        app.ancestry.citations.values(),
                                        'citation', app, locale,
                                        app.jinja2_environment)
            logger.info('Generated pages for %d citations in %s.' %
                        (len(app.ancestry.citations), locale_label))
            await _generate_entity_type(www_directory_path,
                                        app.ancestry.sources.values(),
                                        'source', app, locale,
                                        app.jinja2_environment)
            logger.info('Generated pages for %d sources in %s.' %
                        (len(app.ancestry.sources), locale_label))
            _generate_entity_type_list_json(www_directory_path,
                                            app.ancestry.notes.values(),
                                            'note', app)
            for note in app.ancestry.notes.values():
                _generate_entity_json(www_directory_path, note, 'note', app,
                                      locale)
            logger.info('Generated pages for %d notes in %s.' %
                        (len(app.ancestry.notes), locale_label))
            _generate_openapi(www_directory_path, app)
            logger.info('Generated OpenAPI documentation in %s.', locale_label)
    chmod(app.configuration.www_directory_path, 0o755)
    for directory_path, subdirectory_names, file_names in os.walk(
            app.configuration.www_directory_path):
        for subdirectory_name in subdirectory_names:
            chmod(join(directory_path, subdirectory_name), 0o755)
        for file_name in file_names:
            chmod(join(directory_path, file_name), 0o644)
예제 #2
0
async def _generate(app: App) -> None:
    logger = getLogger()
    await app.assets.copytree(
        Path('public') / 'static', app.configuration.www_directory_path)
    await app.renderer.render_tree(app.configuration.www_directory_path)
    for locale_configuration in app.configuration.locales:
        locale = locale_configuration.locale
        async with app.with_locale(locale):
            if app.configuration.multilingual:
                www_directory_path = app.configuration.www_directory_path / locale_configuration.alias
            else:
                www_directory_path = app.configuration.www_directory_path

            await app.assets.copytree(
                Path('public') / 'localized', www_directory_path)
            await app.renderer.render_tree(www_directory_path)

            coroutines = [
                *[
                    coroutine for entities, entity_type_name in [
                        (app.ancestry.entities[File], 'file'),
                        (app.ancestry.entities[Person], 'person'),
                        (app.ancestry.entities[Place], 'place'),
                        (app.ancestry.entities[Event], 'event'),
                        (app.ancestry.entities[Citation], 'citation'),
                        (app.ancestry.entities[Source], 'source'),
                    ] async for coroutine in _generate_entity_type(
                        www_directory_path, entities, entity_type_name, app,
                        locale, app.jinja2_environment)
                ],
                _generate_entity_type_list_json(www_directory_path,
                                                app.ancestry.entities[Note],
                                                'note', app),
                *[
                    _generate_entity_json(www_directory_path, note, 'note',
                                          app, locale)
                    for note in app.ancestry.entities[Note]
                ],
                _generate_openapi(www_directory_path, app)
            ]
            # Batch all coroutines to reduce the risk of "too many open files" errors.
            for i in range(0, len(coroutines), _GENERATE_CONCURRENCY):
                await asyncio.gather(*coroutines[i:i + _GENERATE_CONCURRENCY])
            locale_label = Locale.parse(locale, '-').get_display_name()
            logger.info(
                f'Generated pages for {len(app.ancestry.entities[File])} files in {locale_label}.'
            )
            logger.info(
                f'Generated pages for {len(app.ancestry.entities[Person])} people in {locale_label}.'
            )
            logger.info(
                f'Generated pages for {len(app.ancestry.entities[Place])} places in {locale_label}.'
            )
            logger.info(
                f'Generated pages for {len(app.ancestry.entities[Event])} events in {locale_label}.'
            )
            logger.info(
                f'Generated pages for {len(app.ancestry.entities[Citation])} citations in {locale_label}.'
            )
            logger.info(
                f'Generated pages for {len(app.ancestry.entities[Source])} sources in {locale_label}.'
            )
            logger.info(
                f'Generated pages for {len(app.ancestry.entities[Note])} notes in {locale_label}.'
            )
            logger.info(f'Generated OpenAPI documentation in {locale_label}.')