def render_teams_table(teams): teams_table = [["#", "Team"]] for n, team in enumerate(teams): teams_table.append([n + 1, team]) render_table(teams_table)
def render_plan_table(plans_list): plans_table = [["Plan", "CPU Time"]] visible_headers = ["name", "cpu_time_per_day"] for plan in plans_list: plan, cpu_time = [plan[header] for header in visible_headers] plans_table.append([plan, "{} hour{}/day".format(cpu_time, "" if cpu_time < 2 else "s")]) render_table(plans_table)
def handle_data(data: dict, format='json'): if format == 'json': import json print(json.dumps({frappe.local.site: data}, indent=1, sort_keys=True)) else: from frappe.utils.commands import render_table data = [["DocType", "Fields"]] + [[table, ", ".join(columns)] for table, columns in data.items()] render_table(data)
def render_actions_table(): actions_table = [["#", "Action"]] actions = [] for n, action in enumerate(migrator_actions): actions_table.append([n + 1, action["title"]]) actions.append(action["fn"]) render_table(actions_table) return actions
def render_group_table(app_groups): # title row app_groups_table = [["#", "App Group", "Apps"]] # all rows for idx, app_group in enumerate(app_groups): apps_list = ", ".join(["{}:{}".format(app["scrubbed"], app["branch"]) for app in app_group["apps"]]) row = [idx + 1, app_group["name"], apps_list] app_groups_table.append(row) render_table(app_groups_table)
def render_site_table(sites_info): sites_table = [["#", "Site Name", "Status"]] available_sites = [] for n, site_data in enumerate(sites_info): name, status = site_data["name"], site_data["status"] if status in ("Active", "Broken"): sites_table.append([n + 1, name, status]) available_sites.append(name) render_table(sites_table) return available_sites
def show_config(context, format): "Print configuration file to STDOUT in speified format" if not context.sites: raise SiteNotSpecifiedError sites_config = {} sites_path = os.getcwd() from frappe.utils.commands import render_table def transform_config(config, prefix=None): prefix = f"{prefix}." if prefix else "" site_config = [] for conf, value in config.items(): if isinstance(value, dict): site_config += transform_config(value, prefix=f"{prefix}{conf}") else: log_value = json.dumps(value) if isinstance(value, list) else value site_config += [[f"{prefix}{conf}", log_value]] return site_config for site in context.sites: frappe.init(site) if len(context.sites) != 1 and format == "text": if context.sites.index(site) != 0: click.echo() click.secho(f"Site {site}", fg="yellow") configuration = frappe.get_site_config(sites_path=sites_path, site_path=site) if format == "text": data = transform_config(configuration) data.insert(0, ['Config', 'Value']) render_table(data) if format == "json": sites_config[site] = configuration frappe.destroy() if format == "json": click.echo(frappe.as_json(sites_config))
def get_version(output): """Show the versions of all the installed apps.""" from git import Repo from frappe.utils.commands import render_table from frappe.utils.change_log import get_app_branch frappe.init("") data = [] for app in sorted(frappe.get_all_apps()): module = frappe.get_module(app) app_hooks = frappe.get_module(app + ".hooks") repo = Repo(frappe.get_app_path(app, "..")) app_info = frappe._dict() app_info.app = app app_info.branch = get_app_branch(app) app_info.commit = repo.head.object.hexsha[:7] app_info.version = getattr(app_hooks, f"{app_info.branch}_version", None) or module.__version__ data.append(app_info) { "legacy": lambda: [ click.echo(f"{app_info.app} {app_info.version}") for app_info in data ], "plain": lambda: [ click.echo( f"{app_info.app} {app_info.version} {app_info.branch} ({app_info.commit})" ) for app_info in data ], "table": lambda: render_table([["App", "Version", "Branch", "Commit"]] + [[ app_info.app, app_info.version, app_info.branch, app_info.commit ] for app_info in data]), "json": lambda: click.echo(json.dumps(data, indent=4)), }[output]()