Пример #1
0
def build(pod_path, out_dir, preprocess, clear_cache, pod_paths,
          locate_untranslated, deployment, threaded, locale):
    """Generates static files and dumps them to a local destination."""
    root = os.path.abspath(os.path.join(os.getcwd(), pod_path))
    out_dir = out_dir or os.path.join(root, 'build')

    pod = pods.Pod(root, storage=storage.FileStorage)
    if not pod_paths or clear_cache:
        # Clear the cache when building all, only force if the flag is used.
        pod.podcache.reset(force=clear_cache)
    deployment_obj = None
    if deployment:
        deployment_obj = pod.get_deployment(deployment)
        pod.set_env(deployment_obj.config.env)
    if preprocess:
        with pod.profile.timer('grow_preprocess'):
            pod.preprocess()
    if locate_untranslated:
        pod.enable(pod.FEATURE_TRANSLATION_STATS)
    try:
        with pod.profile.timer('grow_build'):
            config = local_destination.Config(out_dir=out_dir)
            # When using a specific deployment env need to also copy over.
            if deployment_obj:
                config.env = deployment_obj.config.env
            destination = local_destination.LocalDestination(config)
            destination.pod = pod
            repo = utils.get_git_repo(pod.root)
            pod.router.use_simple()
            if pod_paths:
                pod.router.add_pod_paths(pod_paths)
            else:
                pod.router.add_all()
            if locale:
                pod.router.filter(locales=list(locale))
            paths = pod.router.routes.paths
            content_generator = renderer.Renderer.rendered_docs(
                pod, pod.router.routes, use_threading=threaded)
            stats_obj = stats.Stats(pod, paths=paths)
            is_partial = bool(pod_paths) or bool(locale)
            destination.deploy(content_generator,
                               stats=stats_obj,
                               repo=repo,
                               confirm=False,
                               test=False,
                               is_partial=is_partial)

            pod.podcache.write()
    except renderer.RenderErrors as err:
        # Ignore the build error since it outputs the errors.
        raise click.ClickException(str(err))
    except pods.Error as err:
        raise click.ClickException(str(err))
    if locate_untranslated:
        pod.translation_stats.pretty_print()
        destination.export_untranslated_catalogs()
    return pod
Пример #2
0
def process_subcommands(pod, profile, **_):
    """Handle flags that need to process after the sub command."""

    if not pod:
        return

    if profile:
        destination = local_destination.LocalDestination(
            local_destination.Config())
        destination.pod = pod
        destination.export_profile_report()
Пример #3
0
def build(pod_path, out_dir, preprocess, clear_cache, pod_paths,
          locate_untranslated, deployment, use_reroute):
    """Generates static files and dumps them to a local destination."""
    root = os.path.abspath(os.path.join(os.getcwd(), pod_path))
    out_dir = out_dir or os.path.join(root, 'build')

    pod = pods.Pod(root, storage=storage.FileStorage, use_reroute=use_reroute)
    if not pod_paths or clear_cache:
        # Clear the cache when building all, only force if the flag is used.
        pod.podcache.reset(force=clear_cache)
    if deployment:
        deployment_obj = pod.get_deployment(deployment)
        pod.set_env(deployment_obj.config.env)
    if preprocess:
        with pod.profile.timer('grow_preprocess'):
            pod.preprocess()
    if locate_untranslated:
        pod.enable(pod.FEATURE_TRANSLATION_STATS)
    try:
        with pod.profile.timer('grow_build'):
            config = local_destination.Config(out_dir=out_dir)
            destination = local_destination.LocalDestination(config)
            destination.pod = pod
            repo = utils.get_git_repo(pod.root)
            if use_reroute:
                pod.router.use_simple()
                if pod_paths:
                    pod.router.add_pod_paths(pod_paths)
                else:
                    pod.router.add_all()
                routes = pod.router.routes
                stats_obj = stats.Stats(pod, paths=routes.paths)
                rendered_docs = renderer.Renderer.rendered_docs(pod, routes)
                destination.deploy(
                    rendered_docs, stats=stats_obj, repo=repo,
                    confirm=False, test=False, is_partial=bool(pod_paths))
            else:
                paths, _ = pod.determine_paths_to_build(pod_paths=pod_paths)
                stats_obj = stats.Stats(pod, paths=paths)
                content_generator = destination.dump(pod, pod_paths=pod_paths)
                destination.deploy(
                    content_generator, stats=stats_obj, repo=repo, confirm=False,
                    test=False, is_partial=bool(pod_paths))

            pod.podcache.write()
    except pods.Error as err:
        raise click.ClickException(str(err))
    if locate_untranslated:
        pod.translation_stats.pretty_print()
        destination.export_untranslated_catalogs()
    return pod
Пример #4
0
def process_subcommands(pods, profile, **_):
    """Handle flags that need to process after the sub command."""

    if not pods:
        return

    pod = pods[0]

    if profile:
        report = profile_report.ProfileReport(pod.profile)
        # report.pretty_print()
        destination = local_destination.LocalDestination(
            local_destination.Config())
        destination.pod = pod
        destination.export_profile_report()
Пример #5
0
def build(pod_path, out_dir):
    """Generates static files and dumps them to a local destination."""
    root = os.path.abspath(os.path.join(os.getcwd(), pod_path))
    out_dir = out_dir or os.path.join(root, 'build')
    pod = pods.Pod(root, storage=storage.FileStorage)
    pod.preprocess()
    try:
        paths_to_contents = pod.dump()
        repo = utils.get_git_repo(pod.root)
        config = local_destination.Config(out_dir=out_dir)
        stats_obj = stats.Stats(pod, paths_to_contents=paths_to_contents)
        destination = local_destination.LocalDestination(config)
        destination.deploy(paths_to_contents,
                           stats=stats_obj,
                           repo=repo,
                           confirm=False,
                           test=False)
    except pods.Error as e:
        raise click.ClickException(str(e))
Пример #6
0
def build(pod_path, out_dir, preprocess, clear_cache, pod_paths,
          locate_untranslated, deployment, threaded, locale, shards, shard,
          work_dir, routes_file):
    """Generates static files and dumps them to a local destination."""
    root = os.path.abspath(os.path.join(os.getcwd(), pod_path))
    out_dir = out_dir or os.path.join(root, 'build')

    pod = pods.Pod(root, storage=storage.FileStorage)
    if not pod_paths or clear_cache:
        # Clear the cache when building all, only force if the flag is used.
        pod.podcache.reset(force=clear_cache)
    deployment_obj = None
    if deployment:
        deployment_obj = pod.get_deployment(deployment)
        pod.set_env(deployment_obj.config.env)
    if preprocess:
        with pod.profile.timer('grow_preprocess'):
            pod.preprocess()
    if locate_untranslated:
        pod.enable(pod.FEATURE_TRANSLATION_STATS)
    try:
        with pod.profile.timer('grow_build'):
            config = local_destination.Config(out_dir=out_dir)
            # When using a specific deployment env need to also copy over.
            if deployment_obj:
                config.env = deployment_obj.config.env
            destination = local_destination.LocalDestination(config)
            destination.pod = pod
            repo = utils.get_git_repo(pod.root)
            pod.router.use_simple()
            is_partial = bool(pod_paths) or bool(locale)
            if pod_paths:
                pod_paths = [pod.clean_pod_path(path) for path in pod_paths]
                pod.router.add_pod_paths(pod_paths)
            elif routes_file:
                pod.router.from_data(pod.read_json(routes_file))
            else:
                pod.router.add_all()
            if locale:
                pod.router.filter('whitelist', locales=list(locale))

            # Shard the routes when using sharding.
            if shards and shard:
                is_partial = True
                pod.router.shard(shards, shard)

            if not work_dir:
                # Preload the documents used by the paths after filtering.
                docs_loader.DocsLoader.load_from_routes(pod, pod.router.routes)

            paths = pod.router.routes.paths
            content_generator = renderer.Renderer.rendered_docs(
                pod,
                pod.router.routes,
                source_dir=work_dir,
                use_threading=threaded)
            content_generator = hooks.generator_wrapper(
                pod, 'pre_deploy', content_generator, 'build')
            stats_obj = stats.Stats(pod, paths=paths)
            destination.deploy(content_generator,
                               stats=stats_obj,
                               repo=repo,
                               confirm=False,
                               test=False,
                               is_partial=is_partial)
            pod.podcache.write()
    except bulk_errors.BulkErrors as err:
        # Write the podcache files even when there are rendering errors.
        pod.podcache.write()
        bulk_errors.display_bulk_errors(err)
        raise click.Abort()
    except pods.Error as err:
        raise click.ClickException(str(err))
    if locate_untranslated:
        pod.translation_stats.pretty_print()
        destination.export_untranslated_catalogs()
    return pod