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
def _test_deploy(self, repo_url): pod = testing.create_pod() pod.write_yaml('/podspec.yaml', { 'deployments': { 'git': { 'destination': 'git', 'repo': repo_url, 'branch': 'gh-pages', }, }, }) pod.write_yaml('/content/pages/_blueprint.yaml', {}) pod.write_yaml('/content/pages/page.yaml', { '$path': '/{base}/', '$view': '/views/base.html', }) pod.write_file('/views/base.html', str(random.randint(0, 999))) deployment = pod.get_deployment('git') paths = [] for rendered_doc in deployment.dump(pod): paths.append(rendered_doc.path) repo = utils.get_git_repo(pod.root) stats_obj = stats.Stats(pod, paths=paths) deployment.deploy(deployment.dump(pod), stats=stats_obj, repo=repo, confirm=False, test=False)
def deploy(context, deployment_name, pod_path, preprocess, confirm, test, test_only, auth): """Deploys a pod to a destination.""" if auth: text = ('--auth must now be specified before deploy. Usage:' ' grow [email protected] deploy') raise click.ClickException(text) auth = context.parent.params.get('auth') root = os.path.abspath(os.path.join(os.getcwd(), pod_path)) try: pod = pods.Pod(root, storage=storage.FileStorage) deployment = pod.get_deployment(deployment_name) if auth: deployment.login(auth) if preprocess: pod.preprocess() if test_only: deployment.test() return paths_to_contents = deployment.dump(pod) repo = utils.get_git_repo(pod.root) stats_obj = stats.Stats(pod, paths_to_contents=paths_to_contents) deployment.deploy(paths_to_contents, stats=stats_obj, repo=repo, confirm=confirm, test=test) except base.Error as e: raise click.ClickException(str(e)) except pods.Error as e: raise click.ClickException(str(e))
def stage(context, pod_path, remote, preprocess, subdomain, api_key, force_untranslated): """Stages a build on a WebReview server.""" root = os.path.abspath(os.path.join(os.getcwd(), pod_path)) auth = context.parent.params.get('auth') try: pod = pods.Pod(root, storage=storage.FileStorage) with pod.profile.timer('grow_stage'): deployment = _get_deployment(pod, remote, subdomain, api_key) # use the deployment's environment for preprocessing and later # steps. pod.set_env(deployment.config.env) require_translations = pod.podspec.localization.get( 'require_translations', False) require_translations = require_translations and not force_untranslated if auth: deployment.login(auth) if preprocess: pod.preprocess() content_generator = deployment.dump(pod) repo = utils.get_git_repo(pod.root) paths, _ = pod.determine_paths_to_build() stats_obj = stats.Stats(pod, paths=paths) deployment.deploy(content_generator, stats=stats_obj, repo=repo, confirm=False, test=False, require_translations=require_translations) except base.Error as err: raise click.ClickException(str(err)) except pods.Error as err: raise click.ClickException(str(err)) return pod
def stage(context, pod_path, remote, preprocess, subdomain, api_key, force_untranslated, threaded, work_dir, routes_file): """Stages a build on a WebReview server.""" root = os.path.abspath(os.path.join(os.getcwd(), pod_path)) auth = context.parent.params.get('auth') try: pod = pods.Pod(root, storage=storage.FileStorage) with pod.profile.timer('grow_stage'): deployment = _get_deployment(pod, remote, subdomain, api_key) # use the deployment's environment for preprocessing and later # steps. pod.set_env(deployment.get_env()) # Always clear the cache when building. pod.podcache.reset() require_translations = \ pod.podspec.localization \ and pod.podspec.localization.get('require_translations', False) require_translations = require_translations \ and not force_untranslated if auth: deployment.login(auth) if preprocess: pod.preprocess() repo = utils.get_git_repo(pod.root) pod.router.use_simple() if routes_file: pod.router.from_data(pod.read_json(routes_file)) else: pod.router.add_all() 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 stats_obj = stats.Stats(pod, paths=paths) content_generator = deployment.dump(pod, source_dir=work_dir, use_threading=threaded) content_generator = hooks.generator_wrapper( pod, 'pre_deploy', content_generator, 'stage') deployment.deploy(content_generator, stats=stats_obj, repo=repo, confirm=False, test=False, require_translations=require_translations) 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 base.Error as err: # raise click.ClickException(str(err)) except pods.Error as err: raise click.ClickException(str(err)) return pod
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
def stats(pod_path, full): """Displays statistics about the pod.""" root = os.path.abspath(os.path.join(os.getcwd(), pod_path)) pod = pods.Pod(root, storage=storage.FileStorage) try: stats = stats_lib.Stats(pod, full=full) click.echo_via_pager('\n\n'.join(stats.to_tables())) except pods.Error as e: raise click.ClickException(str(e))
def inspect_stats(pod_path, full): """Displays statistics about the pod.""" root = os.path.abspath(os.path.join(os.getcwd(), pod_path)) pod = pods.Pod(root, storage=storage.FileStorage) try: with pod.profile.timer('grow_inspect_stats'): pod_stats = stats_lib.Stats(pod, full=full) click.echo_via_pager('\n\n'.join(pod_stats.to_tables())) except pods.Error as err: raise click.ClickException(str(err)) return pod
def deploy(context, deployment_name, pod_path, preprocess, confirm, test, test_only, auth, force_untranslated, use_reroute, threaded): """Deploys a pod to a destination.""" if auth: text = ('--auth must now be specified before deploy. Usage:' ' grow [email protected] deploy') raise click.ClickException(text) auth = context.parent.params.get('auth') root = os.path.abspath(os.path.join(os.getcwd(), pod_path)) try: pod = pods.Pod(root, storage=storage.FileStorage, use_reroute=use_reroute) with pod.profile.timer('grow_deploy'): # Always clear the cache when building. pod.podcache.reset() deployment = pod.get_deployment(deployment_name) # use the deployment's environment for preprocessing and later # steps. if deployment.config.env: pod.set_env(deployment.config.env) require_translations = pod.podspec.localization.get( 'require_translations', False) require_translations = require_translations and not force_untranslated if auth: deployment.login(auth) if preprocess: pod.preprocess() if test_only: deployment.test() return content_generator = deployment.dump(pod, use_threading=threaded) repo = utils.get_git_repo(pod.root) if use_reroute: pod.router.use_simple() pod.router.add_all() paths = pod.router.routes.paths else: paths, _ = pod.determine_paths_to_build() stats_obj = stats.Stats(pod, paths=paths) deployment.deploy( content_generator, stats=stats_obj, repo=repo, confirm=confirm, test=test, require_translations=require_translations) pod.podcache.write() except base.Error as err: raise click.ClickException(str(err)) except pods.Error as err: raise click.ClickException(str(err)) return pod
def build(pod_path, out_dir, preprocess): """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 preprocess: pod.preprocess() try: config = local_destination.Config(out_dir=out_dir) destination = local_destination.LocalDestination(config) paths_to_contents = destination.dump(pod) repo = utils.get_git_repo(pod.root) stats_obj = stats.Stats(pod, paths_to_contents=paths_to_contents) destination.deploy(paths_to_contents, stats=stats_obj, repo=repo, confirm=False, test=False) except pods.Error as e: raise click.ClickException(str(e))
def stage(context, pod_path, remote, preprocess, subdomain, api_key): """Stages a build on a WebReview server.""" root = os.path.abspath(os.path.join(os.getcwd(), pod_path)) auth = context.parent.params.get('auth') try: pod = pods.Pod(root, storage=storage.FileStorage) deployment = _get_deployment(pod, remote, subdomain, api_key) if auth: deployment.login(auth) if preprocess: pod.preprocess() repo = utils.get_git_repo(pod.root) paths_to_contents = deployment.dump(pod) stats_obj = stats.Stats(pod, paths_to_contents=paths_to_contents) deployment.deploy(paths_to_contents, stats=stats_obj, repo=repo, confirm=False, test=False) except base.Error as e: raise click.ClickException(str(e)) except pods.Error as e: raise click.ClickException(str(e))
def stage(context, pod_path, remote, preprocess, subdomain, api_key, force_untranslated, threaded): """Stages a build on a WebReview server.""" root = os.path.abspath(os.path.join(os.getcwd(), pod_path)) auth = context.parent.params.get('auth') try: pod = pods.Pod(root, storage=storage.FileStorage) with pod.profile.timer('grow_stage'): deployment = _get_deployment(pod, remote, subdomain, api_key) # use the deployment's environment for preprocessing and later # steps. pod.set_env(deployment.get_env()) # Always clear the cache when building. pod.podcache.reset() require_translations = \ pod.podspec.localization \ and pod.podspec.localization.get('require_translations', False) require_translations = require_translations \ and not force_untranslated if auth: deployment.login(auth) if preprocess: pod.preprocess() content_generator = deployment.dump(pod, use_threading=threaded) repo = utils.get_git_repo(pod.root) pod.router.use_simple() pod.router.add_all() paths = pod.router.routes.paths stats_obj = stats.Stats(pod, paths=paths) deployment.deploy(content_generator, stats=stats_obj, repo=repo, confirm=False, test=False, require_translations=require_translations) pod.podcache.write() except base.Error as err: raise click.ClickException(str(err)) except pods.Error as err: raise click.ClickException(str(err)) return pod
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
def deploy(context, deployment_name, pod_path, preprocess, confirm, test, test_only, auth, force_untranslated, threaded, shards, shard, work_dir, routes_file): """Deploys a pod to a destination.""" if auth: text = ('--auth must now be specified before deploy. Usage:' ' grow [email protected] deploy') raise click.ClickException(text) auth = context.parent.params.get('auth') root = os.path.abspath(os.path.join(os.getcwd(), pod_path)) try: pod = pods.Pod(root, storage=storage.FileStorage) with pod.profile.timer('grow_deploy'): # Always clear the cache when building. pod.podcache.reset() deployment = pod.get_deployment(deployment_name) # use the deployment's environment for preprocessing and later # steps. if deployment.config.env: pod.set_env(deployment.config.env) require_translations = pod.podspec.localization.get( 'require_translations', False) require_translations = require_translations and not force_untranslated if auth: deployment.login(auth) if preprocess: pod.preprocess() if test_only: deployment.test() return repo = utils.get_git_repo(pod.root) pod.router.use_simple() if routes_file: pod.router.from_data(pod.read_json(routes_file)) else: pod.router.add_all() is_partial = False # Filter routes based on deployment config. for build_filter in deployment.filters: is_partial = True pod.router.filter( build_filter.type, collection_paths=build_filter.collections, paths=build_filter.paths, locales=build_filter.locales) # 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 stats_obj = stats.Stats(pod, paths=paths) content_generator = deployment.dump( pod, source_dir=work_dir, use_threading=threaded) content_generator = hooks.generator_wrapper( pod, 'pre_deploy', content_generator, 'deploy') deployment.deploy( content_generator, stats=stats_obj, repo=repo, confirm=confirm, test=test, require_translations=require_translations, 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 base.Error as err: raise click.ClickException(str(err)) except pods.Error as err: raise click.ClickException(str(err)) return pod