def _input(name, title, validator, hdata): data = "" while not validator(data): if data: print(utils.colorize(f"<red>Invalid {name} format</red>")) data = input(utils.colorize(f"<f>Enter {title}:</f>\n")) if any(x for x in hdata if getattr(x, name) == data): _abort(f"Host already exists with {name}={data}") return data
def check(_: Dict[str, str]): """Check build environment""" all_pass = True # check required tools for rtool in REQUIRED_TOOLS: has_tool = utils.where(rtool.name) if has_tool: print( utils.colorize(f"[ <grn>PASS</grn> ]\t{rtool.name} is ready")) else: all_pass = False print( utils.colorize(f"[ <red>FAIL</red> ]\t{rtool.name} is " f"required for {rtool.step} step. " f"see --help")) return all_pass
def prepare_docopt_help(for_print=False): """Prepare docstring for docopt""" command_templates = "" if for_print: command_templates = "\n ".join([ f"{__binname__} {x.template:30} {utils.format_help(x.help)}" for x in COMMANDS ]) else: command_templates = "\n ".join( [f"{__binname__} {x.template}" for x in COMMANDS]) return utils.colorize(__doc__.format(command_templates=command_templates))
def set_ver(args: Dict[str, str]): """Update version number""" ver_finder = re.compile(r"4\.\d\.\d") new_version = args["<ver>"] if ver_finder.match(new_version): print(f"Updating version to v{new_version}...") _modify_contents( files=configs.VERSION_FILES, finder=ver_finder, new_value=new_version, ) else: print(utils.colorize("<red>Invalid version format (e.g. 4.8.0)</red>")) sys.exit(1)
def set_ver(args: Dict[str, str]): """Update version number""" new_version = _update_build_number(args["<ver>"]) # add wip to version if this is a wip build is_wip = args.get("<build>", "release") == "wip" if is_wip: new_version += configs.PYREVIT_WIP_VERSION_EXT if VER_FINDER.match(new_version): print(f"Updating version to v{new_version}...") _modify_contents( files=configs.VERSION_FILES, finder=VER_FINDER, new_value=new_version, ) else: print(utils.colorize("<red>Invalid version format (e.g. 4.8.0)</red>")) sys.exit(1)