def get_logs_description_table(logs, color=True): table = [] table.append([ "#", "Log name", "rc", "description", "bag size", "hash bag", "date", "length", "vehicle name", "filename", "valid", "topics", ]) for i, (_, log) in enumerate(logs.items()): row = [] row.append(i) row.append(log.log_name) row.append(len(log.resources)) # row.append(log.map_name) row.append(log.description) dtr = DTR.from_yaml(log.resources["bag"]) bag_size_mb = f"{dtr.size / (1024.0 * 1024):8.1f} MB" row.append(bag_size_mb) row.append(f"{dtr.name} {bag_size_mb} \n{dtr.hash['sha1']}") row.append(log.date) if log.length is not None: l = f"{log.length:5.1f} s" else: l = "(none)" row.append(l) row.append(log.vehicle) try: filename = get_local_bag_file(log) row.append(dtu.friendly_path(filename)) except NotAvailableLocally: row.append("not local") if log.valid: sr = "Yes." else: sr = log.error_if_invalid row.append(sr) if log.bag_info is not None: info = yaml.dump(log.bag_info["topics"]) else: info = "(none)" if color and not log.valid: row = dtu.make_row_red(row) row.append(info) table.append(row) return table
def format_families(families: List[EasyAlgoFamily], colorize: bool = True, verbose: bool = True): if not families: s = "No algorithm families found." return s else: table = [[ "Family name", "interface", "pattern", "# found", "valid", "filename", "description", ]] for family in families: assert isinstance(family, EasyAlgoFamily) row = [ family.family_name, family.interface, family.instances_pattern ] if not family.instances: row.append("\n(none)") else: n_valid = len( [_ for _ in list(family.instances.values()) if _.valid]) n_invalid = len(family.instances) - n_valid ss = f"{len(family.instances)}" if n_invalid: ss += dtu.make_red(f" ({n_invalid} invalid)") row.append(ss) if family.valid: ss = "yes" else: ss = "no: " + family.error_if_invalid row.append(ss) row.append(dtu.friendly_path(family.filename)) if (not family.valid) and colorize: row = dtu.make_row_red(row) row.append(family.description.strip()) table.append(row) if not verbose: dtu.remove_table_field(table, "filename") s = f"Found {len(families)} algorithm families:\n\n" s += dtu.indent(dtu.format_table_plus(table, colspacing=4), " ") return s
def user_config_summary() -> str: db = get_config_db() # def apply_to_lines(f, x): # return "\n".join(f(_) for _ in x.split('\n')) # # def red(s): # red_ = lambda _: termcolor.colored(_, 'red') # return apply_to_lines(red_, s) red = lambda x: x table = [] table.append([ "package name", "node name", "config_name", "effective", "extends", "valid", "error", "description", "filename", ]) for c in db.configs: assert isinstance(c, ConfigInfo) d = dtu.truncate_string_right(c.description.replace("\n", " "), 40) date = c.date_effective.strftime("%Y-%m-%d") if c.valid is None: valid = "?" valid_error = "" else: valid = "yes" if c.valid else red("no") valid_error = "" if c.valid else red(c.error_if_invalid) table.append([ c.package_name, c.node_name, c.config_name, date, c.extends, valid, valid_error, d, dtu.friendly_path(c.filename), ]) dtu.remove_table_field(table, "filename") s = dtu.format_table_plus(table, colspacing=4) return s
def config_summary(all_keys: Sequence[str], values: dict, origin: Dict[str, str]) -> str: table = [] table.append(["-" * len(_) for _ in table[0]]) for k in all_keys: if k in values: v = yaml.dump(values[k]) v = v.strip() if v.endswith("..."): v = v[:-3] v = v.strip() table.append([k, v, dtu.friendly_path(origin[k])]) else: table.append([k, "(unset)", "(not found)"]) return dtu.format_table_plus(table, 4)
def format_instances(family, colorize, verbose=False): if not family.instances: s = ( f'No instances files found for family "{family.family_name}" (pattern = ' f"{family.instances_pattern}).\n\n") return s else: s = f'Found {len(family.instances)} instances of algorithm family "{family.family_name}":\n' table = [] table.append([ "Instance name", "constructor", "parameters", "description", "filename" ]) for _ in list(family.instances.values()): row = [] name = _.instance_name if (not _.valid) and colorize: name = dtu.make_red(name) row.append(name) row.append(_.constructor) row.append(dtu.yaml_dump_pretty(_.parameters)) row.append(_.description) row.append(dtu.friendly_path(_.filename)) table.append(row) if not verbose: dtu.remove_table_field(table, "filename") dtu.remove_table_field(table, "description") s += dtu.indent(dtu.format_table_plus(table, colspacing=4), "| ") for _ in list(family.instances.values()): if not _.valid: msg = _.error_if_invalid s += dtu.make_red("\n" + dtu.indent(msg, "", _.instance_name + ": ")) return s