From: Zbigniew Jędrzejewski-Szmek Date: Fri, 21 May 2021 13:51:35 +0000 (+0200) Subject: mkosi: move two dynamically created methods to class level X-Git-Tag: v10~27^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F720%2Fhead;p=thirdparty%2Fmkosi.git mkosi: move two dynamically created methods to class level --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 9fc6d3120..1af69d9ef 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -4696,6 +4696,15 @@ class ArgumentParserMkosi(argparse.ArgumentParser): kwargs["fromfile_prefix_chars"] = ArgumentParserMkosi.fromfile_prefix_chars super().__init__(*kargs, **kwargs) + @staticmethod + def _camel_to_arg(camel: str) -> str: + s1 = re.sub("(.)([A-Z][a-z]+)", r"\1-\2", camel) + return re.sub("([a-z0-9])([A-Z])", r"\1-\2", s1).lower() + + @classmethod + def _ini_key_to_cli_arg(cls, key: str) -> str: + return cls.SPECIAL_MKOSI_DEFAULT_PARAMS.get(key) or ("--" + cls._camel_to_arg(key)) + def _read_args_from_files(self, arg_strings: List[str]) -> List[str]: """Convert @ prefixed command line arguments with corresponding file content @@ -4713,16 +4722,6 @@ class ArgumentParserMkosi(argparse.ArgumentParser): return value: ['--distribution', 'fedora', '-p', 'httpd'] """ - def camel_to_arg(camel: str) -> str: - s1 = re.sub("(.)([A-Z][a-z]+)", r"\1-\2", camel) - return re.sub("([a-z0-9])([A-Z])", r"\1-\2", s1).lower() - - def ini_key_to_cli_arg(key: str) -> str: - try: - return ArgumentParserMkosi.SPECIAL_MKOSI_DEFAULT_PARAMS[key] - except KeyError: - return "--" + camel_to_arg(key) - # expand arguments referencing files new_arg_strings = [] for arg_string in arg_strings: @@ -4741,7 +4740,7 @@ class ArgumentParserMkosi(argparse.ArgumentParser): config.read_file(args_file) for section in config.sections(): for key, value in config.items(section): - cli_arg = ini_key_to_cli_arg(key) + cli_arg = self._ini_key_to_cli_arg(key) # \n in value strings is forwarded. Depending on the action type, \n is considered as a delimiter or needs to be replaced by a ' ' for action in self._actions: