def main(args=None): args = command_handle_args(args, definition) config = get_config() try: ic = InstallerContext(config=config) default_installer_name = ic.get_default_installer_name() results, errors = resolve(args.xylem_key, all_keys=args.all, config=config, installer_context=ic) if errors: error("\n".join(indent(exc_to_str(e), 2, exclude_first=True) for _, e in errors)) for key, (installer_name, resolutions) in results: if installer_name != default_installer_name or \ args.show_default_installer: installer_string = "{0}: ".format(installer_name) else: installer_string = "" resolution_string = ', '.join(map(to_str, resolutions)) info("{0} --> {1}{2}". format(ansi("cyanf") + key + ansi("reset"), ansi("bluef") + installer_string, ansi("yellowf") + resolution_string)) if errors: sys.exit(1) except (KeyboardInterrupt, EOFError): info('') sys.exit(1)
def warning(msg, file=None, *args, **kwargs): """Print warning to console or file. Works like :func:`print`, optionally uses terminal colors and tries to handle unicode correctly by encoding to ``utf-8`` before printing. Can be enabled or disabled with :func:`enable_debug`. """ file = file if file is not None else sys.stderr msg = to_str(msg) msg = ansi('yellowf') + msg + ansi('reset') print(to_bytes(msg), file=file, *args, **kwargs) return msg
def error(msg, file=None, exit=False, *args, **kwargs): """Print error statement and optionally exit. Works like :func:`print`, optionally uses terminal colors and tries to handle unicode correctly by encoding to ``utf-8`` before printing. """ file = file if file is not None else sys.stderr msg = to_str(msg) msg = ansi('redf') + ansi('boldon') + msg + ansi('reset') if exit: sys.exit(to_bytes(msg)) print(to_bytes(msg), file=file, *args, **kwargs) return msg
def main(args=None): args = command_handle_args(args, definition) config = get_config() try: # TODO: handle multiple keys in one go ic = InstallerContext(config=config) for key in args.xylem_key: result = lookup(key, compact=True, config=config, installer_context=ic) info("Rules for '{}' on '{}':\n{}". format(ansi('cyanf') + key + ansi('reset'), ansi('cyanf') + ic.get_os_string() + ansi('reset'), ansi('yellowf') + dump_yaml(result)[:-1])) except (KeyboardInterrupt, EOFError): # Note: @William why EOFError here? info('') sys.exit(1)
def main(args=None): args = command_handle_args(args, definition) config = get_config() try: # TODO: handle multiple keys in one go ic = InstallerContext(config=config) for key in args.xylem_key: result = lookup(key, compact=True, config=config, installer_context=ic) info("Rules for '{}' on '{}':\n{}".format( ansi('cyanf') + key + ansi('reset'), ansi('cyanf') + ic.get_os_string() + ansi('reset'), ansi('yellowf') + dump_yaml(result)[:-1])) except (KeyboardInterrupt, EOFError): # Note: @William why EOFError here? info('') sys.exit(1)
def info(msg, file=None, *args, **kwargs): """Print info to console or file. Works like :func:`print`, optionally uses terminal colors and tries to handle unicode correctly by encoding to ``utf-8`` before printing. """ file = file if file is not None else sys.stdout msg = to_str(msg) msg = msg + ansi('reset') # Assume that msg might contain colors print(to_bytes(msg), file=file, *args, **kwargs) return msg