def _print_yaml_data(headers, data): # pragma: no cover l = [ dict(zip(headers, [getattr(datum, field) for field in datum._fields])) for datum in data ] syntax = Syntax(util.safe_dump(l), "yaml") console.print(syntax)
def drivers(ctx, format): # pragma: no cover """List drivers.""" drivers = [[x] for x in api.drivers()] headers = ["name"] table_format = "simple" if format == "plain": for driver in drivers: console.print(*driver) else: headers = [] table_format = format _print_tabulate_data(headers, drivers, table_format)
def _print_tabulate_data(headers, data, table_format): # pragma: no cover """ Show the tabulate data on the screen and returns None. :param headers: A list of column headers. :param data: A list of tabular data to display. :returns: None """ t = Table(box=box.MINIMAL) for header in headers: t.add_column(header) for line in data: t.add_row(*line) console.print(t)
def print_version(ctx, param, value): """Print version information.""" if not value or ctx.resilient_parsing: return v = pkg_resources.parse_version(molecule.__version__) color = "bright_yellow" if v.is_prerelease else "green" msg = f"molecule [{color}]{v}[/] using python [repr.number]{sys.version_info[0]}.{sys.version_info[1]}[/] \n" msg += ( f" [repr.attrib_name]ansible[/][dim]:[/][repr.number]{ansible_version()}[/]" ) for driver in drivers(): msg += f"\n [repr.attrib_name]{str(driver)}[/][dim]:[/][repr.number]{driver.version}[/][dim] from {driver.module}[/]" console.print(msg) ctx.exit()
def wrapper(*args, **kwargs): self = args[0] scenario = self._config.scenario.name subcommand = underscore(self.__class__.__name__) console.print( "::group::", f"[ci_info]Molecule[/] [scenario]{scenario}[/] > [action]{subcommand}[/]", sep="", markup=True, emoji=False, highlight=False, ) try: return func(*args, **kwargs) finally: console.print("::endgroup::", markup=True, emoji=False, highlight=False)
def print_version(ctx, param, value): """Print version information.""" if not value or ctx.resilient_parsing: return v = packaging.version.Version(molecule.__version__) color = "bright_yellow" if v.is_prerelease else "green" msg = f"molecule [{color}]{v}[/] using python [repr.number]{sys.version_info[0]}.{sys.version_info[1]}[/] \n" runtime = Runtime() msg += f" [repr.attrib_name]ansible[/][dim]:[/][repr.number]{runtime.version}[/]" for driver in drivers(): msg += f"\n [repr.attrib_name]{str(driver)}[/][dim]:[/][repr.number]{driver.version}[/][dim] from {driver.module}[/]" if driver.required_collections: msg += " requiring collections:" for name, version in driver.required_collections.items(): msg += f" {name}>={version}" console.print(msg) ctx.exit()
def wrapper(*args, **kwargs): self = args[0] scenario = self._config.scenario.name subcommand = underscore(self.__class__.__name__) console.print( f"section_start:{int(time.time())}:{scenario}.{subcommand}", end=clear_line, markup=False, emoji=False, highlight=False, ) console.print( # must be one color for the whole line or gitlab sets odd widths to each word. f"[ci_info]Molecule {scenario} > {subcommand}[/]", end="\n", markup=True, emoji=False, highlight=False, ) try: return func(*args, **kwargs) finally: console.print( f"section_end:{int(time.time())}:{scenario}.{subcommand}", end=f"{clear_line}\n", markup=False, emoji=False, highlight=False, )
def print_debug(title: str, data: str) -> None: """Print debug information.""" console.print(f"DEBUG: {title}:\n{data}")
def print_as_yaml(data: Any) -> None: """Render python object as yaml on console.""" result = Syntax(safe_dump(data), "yaml") console.print(result)