def plugins_list_cmd(ctx, as_json, verbosity): """This returns a list of all currently actively installed plugins in the project. By default it only prints out the plugin IDs and version numbers but the entire information can be returned by increasing verbosity with `-v`. Additionally JSON output can be requested with `--json`. """ ctx.load_plugins() env = ctx.get_env() plugins = sorted(env.plugins.values(), key=lambda x: x.id.lower()) if as_json: echo_json({"plugins": [x.to_json() for x in plugins]}) return if verbosity == 0: for plugin in plugins: click.echo("%s (version %s)" % (plugin.id, plugin.version)) return for idx, plugin in enumerate(plugins): if idx: click.echo() click.echo("%s (%s)" % (plugin.name, plugin.id)) for line in plugin.description.splitlines(): click.echo(" %s" % line) if plugin.path is not None: click.echo(" path: %s" % plugin.path) click.echo(" version: %s" % plugin.version) click.echo(" import-name: %s" % plugin.import_name)
def content_file_info_cmd(ctx, files, as_json): """Given a list of files this returns the information for those files in the context of a project. If the files are from different projects an error is generated. """ project = None def fail(msg): if as_json: echo_json({"success": False, "error": msg}) sys.exit(1) raise click.UsageError("Could not find content file info: %s" % msg) for filename in files: this_project = Project.discover(filename) if this_project is None: fail("no project found") if project is None: project = this_project elif project.project_path != this_project.project_path: fail("multiple projects") if project is None: fail("no file indicated a project") project_files = [] for filename in files: content_path = project.content_path_from_filename(filename) if content_path is not None: project_files.append(content_path) if not project_files: fail("no files resolve in project") if as_json: echo_json( { "success": True, "project": project.to_json(), "paths": project_files, } ) else: click.echo("Project:") click.echo(" Name: %s" % project.name) click.echo(" File: %s" % project.project_file) click.echo(" Tree: %s" % project.tree) click.echo("Paths:") for project_file in project_files: click.echo(" - %s" % project_file)
def project_info_cmd(ctx, as_json, ops): """Prints out information about the project. This is particular useful for script usage or for discovering information about a Lektor project that is not immediately obvious (like the paths to the default output folder). """ project = ctx.get_project() if as_json: echo_json(project.to_json()) return if ops: data = project.to_json() for op in ops: click.echo(data.get(op, "")) else: click.echo("Name: %s" % project.name) click.echo("File: %s" % project.project_file) click.echo("Tree: %s" % project.tree) click.echo("Output: %s" % project.get_output_path())
def fail(msg): if as_json: echo_json({"success": False, "error": msg}) sys.exit(1) raise click.UsageError("Could not find content file info: %s" % msg)