From 558de10d484acd464e1171a8f83cd14023215c99 Mon Sep 17 00:00:00 2001 From: xuansen fang Date: Thu, 21 Mar 2024 16:04:54 +0800 Subject: [PATCH 1/2] Optimzed: impore the class init process *Transforming the properties of base class into the properties of subclasses *avoiding instantiate and function callback, improving performance Signed-off-by: fangxuansen fangxuansen@ncti-gba.cn --- src/oebuild/app/plugins/bitbake/bitbake.py | 37 +-- src/oebuild/app/plugins/clear/clear.py | 33 +-- .../app/plugins/deploy/deploy_target.py | 76 +++--- src/oebuild/app/plugins/generate/generate.py | 228 ++++++++++-------- src/oebuild/app/plugins/init/init.py | 62 +++-- src/oebuild/app/plugins/m_env/m_env.py | 119 +++++---- src/oebuild/app/plugins/m_plugin/m_plugin.py | 219 ++++++++++------- src/oebuild/app/plugins/manifest/manifest.py | 55 +++-- src/oebuild/app/plugins/run_qemu/run_qemu.py | 84 +++---- src/oebuild/app/plugins/update/update.py | 110 +++++---- 10 files changed, 589 insertions(+), 434 deletions(-) diff --git a/src/oebuild/app/plugins/bitbake/bitbake.py b/src/oebuild/app/plugins/bitbake/bitbake.py index 96fd493..04fee5e 100644 --- a/src/oebuild/app/plugins/bitbake/bitbake.py +++ b/src/oebuild/app/plugins/bitbake/bitbake.py @@ -34,31 +34,31 @@ class Bitbake(OebuildCommand): command directly, for example: `oebuild bitbake busybox` ''' - def __init__(self): - self.compile_conf_dir = os.path.join(os.getcwd(), 'compile.yaml') - self.configure = Configure() - - super().__init__( - 'bitbake', - 'execute bitbake command', - textwrap.dedent(''' + help_msg = 'execute bitbake command' + description = textwrap.dedent(''' The bitbake command performs the build operation, and for the build environment, there are two types, one is to build in docker and the other is to build in the host. There are also two construction methods, one is to build directly, and the other is to call up the build environment to be operated freely by the user ''') - ) + + def __init__(self): + self.compile_conf_dir = os.path.join(os.getcwd(), 'compile.yaml') + self.configure = Configure() + + super().__init__('bitbake', self.help_msg, self.description) def do_add_parser(self, parser_adder) -> argparse.ArgumentParser: - parser = self._parser( - parser_adder, - usage=''' + parser = self._parser(parser_adder, + usage=''' %(prog)s [command] ''') parser_adder.add_argument( - 'command', nargs='?', default=None, + 'command', + nargs='?', + default=None, help='''The name of the directory that will be initialized''') return parser @@ -79,7 +79,8 @@ class Bitbake(OebuildCommand): command = self._get_command(unknow=unknown) if not self.check_support_bitbake(): - logger.error("Please do it in compile workspace which contain compile.yaml") + logger.error( + "Please do it in compile workspace which contain compile.yaml") return if not os.path.exists('.env'): @@ -92,9 +93,11 @@ class Bitbake(OebuildCommand): return # if has manifest.yaml, init layer repo with it - yocto_dir = os.path.join(self.configure.source_dir(), "yocto-meta-openeuler") + yocto_dir = os.path.join(self.configure.source_dir(), + "yocto-meta-openeuler") manifest_path = os.path.join(yocto_dir, ".oebuild/manifest.yaml") - parse_compile.check_with_version(self.configure.source_dir(), manifest_path=manifest_path) + parse_compile.check_with_version(self.configure.source_dir(), + manifest_path=manifest_path) parse_env = ParseEnv(env_dir='.env') if parse_compile.build_in == oebuild_const.BUILD_IN_HOST: @@ -111,7 +114,7 @@ class Bitbake(OebuildCommand): parse_compile=parse_compile, command=command) - def check_support_bitbake(self,): + def check_support_bitbake(self, ): ''' The execution of the bitbake instruction mainly relies on compile.yaml, which is initialized by parsing the file diff --git a/src/oebuild/app/plugins/clear/clear.py b/src/oebuild/app/plugins/clear/clear.py index 62a5a11..ab834f5 100644 --- a/src/oebuild/app/plugins/clear/clear.py +++ b/src/oebuild/app/plugins/clear/clear.py @@ -29,29 +29,28 @@ class Clear(OebuildCommand): for some clear task ''' - def __init__(self): - self.configure = Configure() - self.client = None - super().__init__( - 'clear', - 'clear someone which oebuild generate', - textwrap.dedent('''\ + help_msg = 'clear someone which oebuild generate' + description = textwrap.dedent('''\ During the construction process using oebuild, a lot of temporary products will be generated, such as containers,so this command can remove unimportant products, such as containers -''' - )) + ''') + + def __init__(self): + self.configure = Configure() + self.client = None + super().__init__('clear', self.help_msg, self.description) def do_add_parser(self, parser_adder) -> argparse.ArgumentParser: - parser = self._parser( - parser_adder, - usage=''' + parser = self._parser(parser_adder, usage=''' %(prog)s [docker] ''') parser.add_argument( - 'item', nargs='?', default=None, + 'item', + nargs='?', + default=None, help='''The name of the directory that will be initialized''') return parser @@ -71,7 +70,7 @@ class Clear(OebuildCommand): return self.clear_docker() - def clear_docker(self,): + def clear_docker(self, ): ''' clear container ''' @@ -89,10 +88,12 @@ class Clear(OebuildCommand): env_conf = oebuild_util.read_yaml(pathlib.Path(env)) try: container_id = env_conf['container']['short_id'] - container = self.client.get_container(container_id=container_id) + container = self.client.get_container( + container_id=container_id) DockerProxy().stop_container(container=container) DockerProxy().delete_container(container=container) - logger.info("Delete container: %s successful", container.short_id) + logger.info("Delete container: %s successful", + container.short_id) except DockerException: continue except KeyError: diff --git a/src/oebuild/app/plugins/deploy/deploy_target.py b/src/oebuild/app/plugins/deploy/deploy_target.py index 91d0f4d..03227b3 100644 --- a/src/oebuild/app/plugins/deploy/deploy_target.py +++ b/src/oebuild/app/plugins/deploy/deploy_target.py @@ -14,7 +14,6 @@ import argparse import textwrap import logging - from oebuild.command import OebuildCommand from oebuild.app.plugins.deploy.com_target import ComTarget @@ -23,25 +22,27 @@ logger = logging.getLogger() class DeployTarget(OebuildCommand): ''' - we use package in a + we use package in a ''' + help_msg = 'deploy software on line' + description = textwrap.dedent('''\ + Deploys a recipe's build output (i.e. the output of the do_install task) + to a live target machine over ssh. By default, any existing files will be + preserved instead of being overwritten and will be restored if you run + devtool undeploy-target. Note: this only deploys the recipe itself and + not any runtime dependencies, so it is assumed that those have been + installed on the target beforehand. + ''') + def __init__(self) -> None: - super().__init__( - '{}', - 'deploy software on line', - textwrap.dedent('''\ -Deploys a recipe's build output (i.e. the output of the do_install task) to a live target machine over ssh. By default, any existing files will be preserved instead of being -overwritten and will be restored if you run devtool undeploy-target. Note: this only deploys the recipe itself and not any runtime dependencies, so it is assumed that those have -been installed on the target beforehand. -''' - )) + super().__init__('{}', self.help_msg, self.description) def do_add_parser(self, parser_adder) -> argparse.ArgumentParser: - parser = self._parser( - parser_adder, - usage=''' -oebuild deploy-target [-h] [-c] [-s] [-n] [-p] [--no-check-space] [-e SSH_EXEC] [-P PORT] [-I KEY] [-S | --no-strip] recipename target + parser = self._parser(parser_adder, + usage=''' +oebuild deploy-target [-h] [-c] [-s] [-n] [-p] [--no-check-space] [-e SSH_EXEC] +[-P PORT] [-I KEY] [-S | --no-strip] recipename target ''') return parser @@ -54,12 +55,15 @@ oebuild deploy-target [-h] [-c] [-s] [-n] [-p] [--no-check-space] [-e SSH_EXEC] com_target = ComTarget() com_target.exec(str_args=str_args, fun="deploy-target") - def print_help_msg(self,): + def print_help_msg(self, ): print(""" -usage: oebuild deploy-target [-h] [-c] [-s] [-n] [-p] [--no-check-space] [-e SSH_EXEC] [-P PORT] [-I KEY] [-S | --no-strip] recipename target +usage: oebuild deploy-target [-h] [-c] [-s] [-n] [-p] [--no-check-space] [-e SSH_EXEC] + [-P PORT] [-I KEY] [-S | --no-strip] recipename target -Deploys a recipe's build output (i.e. the output of the do_install task) to a live target machine over ssh. By default, any existing files will be preserved instead of being -overwritten and will be restored if you run devtool undeploy-target. Note: this only deploys the recipe itself and not any runtime dependencies, so it is assumed that those have +Deploys a recipe's build output (i.e. the output of the do_install task) to a live target + machine over ssh. By default, any existing files will be preserved instead of being +overwritten and will be restored if you run devtool undeploy-target. Note: this only deploys + the recipe itself and not any runtime dependencies, so it is assumed that those have been installed on the target beforehand. arguments: @@ -77,7 +81,9 @@ options: Executable to use in place of ssh -P PORT, --port PORT Specify port to use for connection to the target -I KEY, --key KEY Specify ssh private key for connection to the target - -S, --strip Strip executables prior to deploying (default: False). The default value of this option can be controlled by setting the strip option in the [Deploy] + -S, --strip Strip executables prior to deploying (default: False). + The default value of this option can be controlled by + setting the strip option in the [Deploy] section to True or False. --no-strip Do not strip executables prior to deploy """) @@ -85,23 +91,23 @@ options: class UnDeployTarget(OebuildCommand): ''' - we use package in a + we use package in a ''' + help_msg = 'undeploy software on line' + description = textwrap.dedent('''\ + Un-deploys recipe output files previously deployed to a live target machine + by devtool deploy-target. + ''') + def __init__(self) -> None: - super().__init__( - '{}', - 'undeploy software on line', - textwrap.dedent('''\ -Un-deploys recipe output files previously deployed to a live target machine by devtool deploy-target. -''' - )) + super().__init__('{}', self.help_msg, self.description) def do_add_parser(self, parser_adder) -> argparse.ArgumentParser: - parser = self._parser( - parser_adder, - usage=''' -oebuild undeploy-target [-h] [-c] [-s] [-a] [-n] [-e SSH_EXEC] [-P PORT] [-I KEY] [recipename] target + parser = self._parser(parser_adder, + usage=''' +oebuild undeploy-target [-h] [-c] [-s] [-a] [-n] [-e SSH_EXEC] +[-P PORT] [-I KEY] [recipename] target ''') return parser @@ -117,9 +123,11 @@ oebuild undeploy-target [-h] [-c] [-s] [-a] [-n] [-e SSH_EXEC] [-P PORT] [-I KEY def print_help_msg(self): print(""" -usage: oebuild undeploy-target [-h] [-c] [-s] [-a] [-n] [-e SSH_EXEC] [-P PORT] [-I KEY] [recipename] target +usage: oebuild undeploy-target [-h] [-c] [-s] [-a] [-n] [-e SSH_EXEC] + [-P PORT] [-I KEY] [recipename] target -Un-deploys recipe output files previously deployed to a live target machine by devtool deploy-target. +Un-deploys recipe output files previously deployed to a live target machine + by devtool deploy-target. arguments: recipename Recipe to undeploy (if not using -a/--all) diff --git a/src/oebuild/app/plugins/generate/generate.py b/src/oebuild/app/plugins/generate/generate.py index 4e13ed7..dfd1031 100644 --- a/src/oebuild/app/plugins/generate/generate.py +++ b/src/oebuild/app/plugins/generate/generate.py @@ -38,96 +38,112 @@ class Generate(OebuildCommand): compile.yaml is generated according to different command parameters by generate ''' - def __init__(self): - self.configure = Configure() - self.nativesdk_dir = None - self.toolchain_dir = None - self.sstate_cache = None - self.tmp_dir = None - self.oebuild_kconfig_path = os.path.expanduser('~') + '/.local/oebuild_kconfig/' - super().__init__( - 'generate', - 'help to mkdir build directory and generate compile.yaml', - textwrap.dedent('''\ + help_msg = 'help to mkdir build directory and generate compile.yaml' + description = textwrap.dedent('''\ The generate command is the core command in the entire build process, which is mainly used to customize the build configuration parameters and generate a compile.yaml by customizing each parameter. In addition, for a large number of configuration parameter input is not very convenient, generate provides a way to specify compile.yaml, users can directly specify the file after customizing the build configuration file -''' - )) + ''') + + def __init__(self): + self.configure = Configure() + self.nativesdk_dir = None + self.toolchain_dir = None + self.sstate_cache = None + self.tmp_dir = None + self.oebuild_kconfig_path = os.path.expanduser( + '~') + '/.local/oebuild_kconfig/' + super().__init__('generate', self.help_msg, self.description) def do_add_parser(self, parser_adder): - parser = self._parser( - parser_adder, - usage=''' + parser = self._parser(parser_adder, usage=''' %(prog)s ''') - parser.add_argument('-l', '--list', dest='list', action="store_true", + parser.add_argument('-l', + '--list', + dest='list', + action="store_true", help=''' will list support archs and features - ''' - ) + ''') - parser.add_argument('-p', '--platform', dest='platform', default="qemu-aarch64", + parser.add_argument('-p', + '--platform', + dest='platform', + default="qemu-aarch64", help=''' this param is for arch, you can find it in yocto-meta-openeuler/.oebuild/platform - ''' - ) + ''') - parser.add_argument('-s', '--state_cache', dest='sstate_cache', + parser.add_argument('-s', + '--state_cache', + dest='sstate_cache', help=''' this param is for SSTATE_MIRRORS - ''' - ) + ''') - parser.add_argument('-s_dir', '--sstate_dir', dest='sstate_dir', + parser.add_argument('-s_dir', + '--sstate_dir', + dest='sstate_dir', help=''' this param is for SSTATE_DIR - ''' - ) + ''') - parser.add_argument('-m', '--tmp_dir', dest='tmp_dir', + parser.add_argument('-m', + '--tmp_dir', + dest='tmp_dir', help=''' this param is for tmp directory, the build result will be stored in - ''' - ) + ''') - parser.add_argument('-f', '--features', dest='features', action='append', + parser.add_argument('-f', + '--features', + dest='features', + action='append', help=''' this param is feature, it's a reuse command - ''' - ) + ''') - parser.add_argument('-d', '--directory', dest='directory', + parser.add_argument('-d', + '--directory', + dest='directory', help=''' this param is build directory, the default is same to platform - ''' - ) + ''') - parser.add_argument('-t', '--toolchain_dir', dest='toolchain_dir', default='', + parser.add_argument('-t', + '--toolchain_dir', + dest='toolchain_dir', + default='', help=''' this param is for external toolchain dir, if you want use your own toolchain - ''' - ) + ''') - parser.add_argument('-n', '--nativesdk_dir', dest='nativesdk_dir', default='', + parser.add_argument('-n', + '--nativesdk_dir', + dest='nativesdk_dir', + default='', help=''' this param is for external nativesdk dir, the param will be useful when you want to build in host - ''' - ) + ''') - parser.add_argument('-tag', '--docker_tag', dest='docker_tag', default='', + parser.add_argument('-tag', + '--docker_tag', + dest='docker_tag', + default='', help=''' when build in docker, the param can be point docker image - ''' - ) + ''') - parser.add_argument('-dt', '--datetime', dest="datetime", + parser.add_argument('-dt', + '--datetime', + dest="datetime", help=''' this param is add DATETIME to local.conf, the value format is 20231212010101 ''') @@ -144,8 +160,12 @@ class Generate(OebuildCommand): parser.add_argument('-b_in', '--build_in', dest='build_in', - choices=[oebuild_const.BUILD_IN_DOCKER, oebuild_const.BUILD_IN_HOST], - default=oebuild_const.BUILD_IN_DOCKER, help=''' + choices=[ + oebuild_const.BUILD_IN_DOCKER, + oebuild_const.BUILD_IN_HOST + ], + default=oebuild_const.BUILD_IN_DOCKER, + help=''' This parameter marks the mode at build time, and is built in the container by docker ''') @@ -162,8 +182,10 @@ class Generate(OebuildCommand): yocto_dir = self.configure.source_yocto_dir() if not self.check_support_oebuild(yocto_dir): - logger.error('Currently, yocto-meta-openeuler does not support oebuild, \ - please modify .oebuild/config and re-execute `oebuild update`') + logger.error( + 'Currently, yocto-meta-openeuler does not support oebuild, \ + please modify .oebuild/config and re-execute `oebuild update`' + ) return if len(unknown) == 0: @@ -249,7 +271,8 @@ class Generate(OebuildCommand): image_list = check_docker_tag.get_tags() for key, value in enumerate(image_list): - print(f"{key}, {oebuild_config.docker.repo_url}:{value}") + print( + f"{key}, {oebuild_config.docker.repo_url}:{value}") k = input("please entry number:") if k == "q": return @@ -265,18 +288,19 @@ class Generate(OebuildCommand): out_dir = pathlib.Path(os.path.join(build_dir, 'compile.yaml')) - oebuild_util.write_yaml(out_dir, parser_template.generate_compile_conf( - nativesdk_dir=self.nativesdk_dir, - toolchain_dir=self.toolchain_dir, - build_in=build_in, - sstate_cache=self.sstate_cache, - tmp_dir=self.tmp_dir, - datetime=args.datetime, - is_disable_fetch=args.is_disable_fetch, - docker_image=docker_image, - src_dir=self.configure.source_dir(), - compile_dir=build_dir - )) + oebuild_util.write_yaml( + out_dir, + parser_template.generate_compile_conf( + nativesdk_dir=self.nativesdk_dir, + toolchain_dir=self.toolchain_dir, + build_in=build_in, + sstate_cache=self.sstate_cache, + tmp_dir=self.tmp_dir, + datetime=args.datetime, + is_disable_fetch=args.is_disable_fetch, + docker_image=docker_image, + src_dir=self.configure.source_dir(), + compile_dir=build_dir)) self._print_generate(build_dir=build_dir) @@ -296,17 +320,20 @@ oebuild bitbake def _check_param_in_host(self, args): if args.toolchain_dir == '': - raise ValueError("build in host must points toolchain directory in '-t' param") + raise ValueError( + "build in host must points toolchain directory in '-t' param") if args.nativesdk_dir == '': - raise ValueError("build in host must points nativesdk directory in '-n' param") + raise ValueError( + "build in host must points nativesdk directory in '-n' param") - def _add_platform_template(self, args, yocto_oebuild_dir, parser_template: ParseTemplate): - if args.platform + '.yaml' in os.listdir(os.path.join(yocto_oebuild_dir, 'platform')): + def _add_platform_template(self, args, yocto_oebuild_dir, + parser_template: ParseTemplate): + if args.platform + '.yaml' in os.listdir( + os.path.join(yocto_oebuild_dir, 'platform')): try: parser_template.add_template( - os.path.join(yocto_oebuild_dir, - 'platform', + os.path.join(yocto_oebuild_dir, 'platform', args.platform + '.yaml')) except BaseParseTemplate as e_p: raise e_p @@ -315,14 +342,16 @@ oebuild bitbake wrong platform, please run `oebuild generate -l` to view support platform""") sys.exit(-1) - def _add_features_template(self, args, yocto_oebuild_dir, parser_template: ParseTemplate): + def _add_features_template(self, args, yocto_oebuild_dir, + parser_template: ParseTemplate): if args.features: for feature in args.features: - if feature + '.yaml' in os.listdir(os.path.join(yocto_oebuild_dir, 'features')): + if feature + '.yaml' in os.listdir( + os.path.join(yocto_oebuild_dir, 'features')): try: - parser_template.add_template(os.path.join(yocto_oebuild_dir, - 'features', - feature + '.yaml')) + parser_template.add_template( + os.path.join(yocto_oebuild_dir, 'features', + feature + '.yaml')) except BaseParseTemplate as b_t: raise b_t else: @@ -337,9 +366,11 @@ wrong platform, please run `oebuild generate -l` to view support feature""") if args.directory is None or args.directory == '': build_dir = os.path.join(self.configure.build_dir(), args.platform) else: - build_dir = os.path.join(self.configure.build_dir(), args.directory) + build_dir = os.path.join(self.configure.build_dir(), + args.directory) - if not os.path.abspath(build_dir).startswith(self.configure.build_dir()): + if not os.path.abspath(build_dir).startswith( + self.configure.build_dir()): logger.error("Build path must in oebuild workspace") return None @@ -397,9 +428,9 @@ wrong platform, please run `oebuild generate -l` to view support feature""") feature_name = feature.replace('.yml', '') if feature.endswith('.yaml'): feature_name = feature.replace('.yaml', '') - feat = oebuild_util.read_yaml(pathlib.Path(os.path.join(yocto_oebuild_dir, - 'features', - feature))) + feat = oebuild_util.read_yaml( + pathlib.Path( + os.path.join(yocto_oebuild_dir, 'features', feature))) if "support" in feat: table.add_row([feature_name, feat.get('support')]) else: @@ -423,9 +454,11 @@ wrong platform, please run `oebuild generate -l` to view support feature""") basic_data = basic_config() platform_data = self.choice_platform(yocto_oebuild_dir) feature_data = self.add_feature(yocto_oebuild_dir) - if not os.path.exists(pathlib.Path(self.oebuild_kconfig_path).absolute()): + if not os.path.exists( + pathlib.Path(self.oebuild_kconfig_path).absolute()): os.makedirs(pathlib.Path(self.oebuild_kconfig_path).absolute()) - kconfig_path = pathlib.Path(self.oebuild_kconfig_path, str(int(time.time()))) + kconfig_path = pathlib.Path(self.oebuild_kconfig_path, + str(int(time.time()))) with open(kconfig_path, 'w', encoding='utf-8') as kconfig_file: kconfig_file.write(platform_data + feature_data + basic_data) @@ -460,8 +493,9 @@ wrong platform, please run `oebuild generate -l` to view support feature""") platform_end = "endchoice" for platform in platform_list: platform_name = os.path.splitext(platform)[0].strip("\n") - platform_info = (f""" config PLATFORM_{platform_name.upper()}\n""" - f""" bool "{platform_name}"\n\n""") + platform_info = ( + f""" config PLATFORM_{platform_name.upper()}\n""" + f""" bool "{platform_name}"\n\n""") platform_start += platform_info platform_data = platform_start + platform_end return platform_data @@ -490,8 +524,9 @@ wrong platform, please run `oebuild generate -l` to view support feature""") feature_data = oebuild_util.read_yaml(feature_path) feature_name = os.path.splitext(feature)[0].strip("\n") if 'support' in feature_data: - support_str = ("if PLATFORM_" + feature_data['support'].upper(). - replace('|', '||PLATFORM_')) + support_str = ("if PLATFORM_" + + feature_data['support'].upper().replace( + '|', '||PLATFORM_')) feature_info = (f"""\nconfig FEATURE_{feature_name.upper()}\n""" f""" bool "{feature_name}" {support_str}\n\n""") @@ -519,17 +554,20 @@ wrong platform, please run `oebuild generate -l` to view support feature""") for basic in basic_list: basic_info = basic.lower().replace("\"", "").split('=') if re.search(r"(?<=--).*(?=\=)", basic): - basic_info[0] = '-' + re.search(r"(?<=--).*(?=\=)", basic).group().lower() + basic_info[0] = '-' + re.search(r"(?<=--).*(?=\=)", + basic).group().lower() if re.search('-DF', basic): generate_command += ['-df'] else: generate_command += basic_info if build_in: - build_command = build_in.group().lower().replace('=y', '').split('--') + build_command = build_in.group().lower().replace('=y', + '').split('--') generate_command += build_command - platform = platform_search.group() if platform_search else 'qemu-aarch64' + platform = platform_search.group( + ) if platform_search else 'qemu-aarch64' generate_command += ['-p', platform.lower()] for feature in feature_list: @@ -546,11 +584,13 @@ def basic_config(): """ toolchain_help = ("(this param is for external toolchain dir, " "if you want use your own toolchain)") - nativesdk_help = ("(this param is for external nativesdk dir," - "the param will be useful when you want to build in host)") - is_disable_fetch_help = ("(this param is set openeuler_fetch in local.conf, " - "the default value is enable, if set -df, the OPENEULER_FETCH" - "will set to 'disable')") + nativesdk_help = ( + "(this param is for external nativesdk dir," + "the param will be useful when you want to build in host)") + is_disable_fetch_help = ( + "(this param is set openeuler_fetch in local.conf, " + "the default value is enable, if set -df, the OPENEULER_FETCH" + "will set to 'disable')") basic_str = textwrap.dedent(f""" comment " THIS IS BASIC CONFIG " config BASIC-SSTATE_CACHE--S diff --git a/src/oebuild/app/plugins/init/init.py b/src/oebuild/app/plugins/init/init.py index f0eefa6..6cf5ef0 100644 --- a/src/oebuild/app/plugins/init/init.py +++ b/src/oebuild/app/plugins/init/init.py @@ -30,15 +30,8 @@ class Init(OebuildCommand): to be followed by the directory name to be initialized ''' - def __init__(self): - self.configure = Configure() - self.oebuild_dir = None - self.src_dir = None - - super().__init__( - 'init', - 'Initialize an OEBUILD working directory', - textwrap.dedent('''\ + help_msg = 'Initialize an OEBUILD working directory' + description = textwrap.dedent('''\ Initialize the OEbuild working directory, and after executing this command, a new directory will be created as the OEBUILD working directory based on the current path. After initialization, the working directory will create an .oebuild @@ -50,25 +43,36 @@ class Init(OebuildCommand): certain changes according to their own needs。 This file is to meet the user's global consideration of the build configuration of OEbuild, and can be easily called by third parties -''' - )) + ''') + + def __init__(self): + self.configure = Configure() + self.oebuild_dir = None + self.src_dir = None + + super().__init__('init', self.help_msg, self.description) def do_add_parser(self, parser_adder): self._parser( parser_adder, - usage=''' - - %(prog)s [directory] [-u yocto_remote_url] [-b branch] -''') + usage='''%(prog)s [directory] [-u yocto_remote_url] [-b branch]''') - parser_adder.add_argument('-u', '--yocto_remote_url', dest='yocto_remote_url', - help='''Specifies the remote of yocto-meta-openeuler''') + parser_adder.add_argument( + '-u', + '--yocto_remote_url', + dest='yocto_remote_url', + help='''Specifies the remote of yocto-meta-openeuler''') - parser_adder.add_argument('-b', '--branch', dest='branch', - help='''Specifies the branch of yocto-meta-openeuler''') + parser_adder.add_argument( + '-b', + '--branch', + dest='branch', + help='''Specifies the branch of yocto-meta-openeuler''') parser_adder.add_argument( - 'directory', nargs='?', default=None, + 'directory', + nargs='?', + default=None, help='''The name of the directory that will be initialized''') return parser_adder @@ -87,6 +91,7 @@ class Init(OebuildCommand): if self.configure.is_oebuild_dir(): log = f'The "{os.path.dirname(self.configure.oebuild_dir())}" \ has already been initialized, please change other directory' + logger.error(log) sys.exit(-1) @@ -103,20 +108,24 @@ class Init(OebuildCommand): os.chdir(args.directory) oebuild_config: Config = self.configure.parse_oebuild_config() - yocto_config: ConfigBasicRepo = oebuild_config.basic_repo[oebuild_const.YOCTO_META_OPENEULER] + yocto_config: ConfigBasicRepo = \ + oebuild_config.basic_repo[oebuild_const.YOCTO_META_OPENEULER] + if args.yocto_remote_url is not None: yocto_config.remote_url = args.yocto_remote_url if args.branch is not None: yocto_config.branch = args.branch - oebuild_config.basic_repo[oebuild_const.YOCTO_META_OPENEULER] = yocto_config + oebuild_config.basic_repo[ + oebuild_const.YOCTO_META_OPENEULER] = yocto_config self.configure.update_oebuild_config(oebuild_config) logger.info("init %s successful", args.directory) format_msg = f''' -There is a build configuration example file under {args.directory}/.oebuild/compile.yaml.sample, -if you want to block complex generate instructions, you can directly copy a configuration file, -and then modify it according to your own needs, and then execute `oebuild generate -c `. +There is a build configuration example file under {args.directory}/.oebuild/compile.yaml.sample, +if you want to block complex generate instructions, you can directly copy a configuration file, +and then modify it according to your own needs, and then execute + `oebuild generate -c `. please execute the follow commands next cd {os.path.abspath(os.getcwd())} @@ -183,6 +192,7 @@ please execute the follow commands next ''' try: compil = oebuild_util.get_compile_yaml_dir() - shutil.copyfile(compil, os.path.join(updir, oebuild_const.COMPILE_YAML)) + shutil.copyfile(compil, + os.path.join(updir, oebuild_const.COMPILE_YAML)) except FileNotFoundError: logger.error("mkdir compile.yaml.sample failed") diff --git a/src/oebuild/app/plugins/m_env/m_env.py b/src/oebuild/app/plugins/m_env/m_env.py index 11602b9..6d535d4 100644 --- a/src/oebuild/app/plugins/m_env/m_env.py +++ b/src/oebuild/app/plugins/m_env/m_env.py @@ -37,25 +37,26 @@ class Menv(OebuildCommand): runned in qt system, the sdk with ros image can be used to develop apps runned in ros system ''' + help_msg = 'Update the basic environment required for the build' + description = textwrap.dedent(''' + This is an environment management function that allows you to configure the environment + through SDK files or unzipped setup files, and you can view, delete, and activate the + corresponding environment. These operations will not have any impact on + your current machine + ''') + def __init__(self): self.configure = Configure() - self.oebuild_env_path = os.path.expanduser('~') + '/.local/oebuild_env/' + self.oebuild_env_path = os.path.expanduser( + '~') + '/.local/oebuild_env/' self.oebuild_env_yaml_path = pathlib.Path( os.path.join(self.oebuild_env_path, 'oebuild_env.yaml')) self.oebuild_env_command = ['list', 'create', 'activate', 'remove'] - super().__init__( - 'menv', - 'Development Environment Management', - description=textwrap.dedent(''' - This is an environment management function that allows you to configure the environment through - SDK files or unzipped setup files, and you can view, delete, and activate the corresponding - environment. These operations will not have any impact on your current machine - ''')) + super().__init__('menv', self.help_msg, self.description) def do_add_parser(self, parser_adder) -> argparse.ArgumentParser: - parser = self._parser( - parser_adder, - usage=''' + parser = self._parser(parser_adder, + usage=''' %(prog)s [create list remove activate][command] create: [-d -f] Create an environment -n env_name list: View existing environment @@ -63,31 +64,35 @@ class Menv(OebuildCommand): activate: -n Activate specified environment ''') - parser.add_argument('-d', '--directory', dest='directory', + parser.add_argument('-d', + '--directory', + dest='directory', help=''' this param is build directory - ''' - ) + ''') - parser.add_argument('-f', '--file', dest='file', + parser.add_argument('-f', + '--file', + dest='file', help=''' this param is build file - ''' - ) + ''') - parser.add_argument('-n', '--env_name', dest='env_name', + parser.add_argument('-n', + '--env_name', + dest='env_name', help=''' this param is env_name - ''' - ) + ''') # Secondary command return parser def do_run(self, args: argparse.Namespace, unknown=None): # perpare parse help command - if unknown[0] not in self.oebuild_env_command or (len(set(unknown[1:]).intersection( - {'-d', '-f', '-n'})) == 0 and unknown[0] != 'list'): + if unknown[0] not in self.oebuild_env_command or ( + len(set(unknown[1:]).intersection({'-d', '-f', '-n'})) == 0 + and unknown[0] != 'list'): unknown = ['-h'] else: command = unknown[0] @@ -109,7 +114,9 @@ Please enter the correct command: oebuild menv create [-d -f] Create an environm if args.env_name: self.activate_environment(args.env_name) sys.exit(0) - print('Please enter the correct command: oebuild menv activate -n env_name') + print( + 'Please enter the correct command: oebuild menv activate -n env_name' + ) sys.exit(-1) elif command == 'list': @@ -126,7 +133,9 @@ Please enter the correct command: oebuild menv create [-d -f] Create an environm if args.env_name: self.delete_environment(args.env_name) sys.exit(0) - print('Please enter the correct command: oebuild menv remove -n env_name') + print( + 'Please enter the correct command: oebuild menv remove -n env_name' + ) sys.exit(-1) def create_environment(self, args): @@ -136,20 +145,24 @@ Please enter the correct command: oebuild menv create [-d -f] Create an environm # Check if the file path exists if args.directory and os.path.isdir(args.directory): setup_file_path = os.path.abspath(args.directory) - sdk_name = args.env_name if args.env_name else args.directory.split('/')[-1] + sdk_name = args.env_name if args.env_name else args.directory.split( + '/')[-1] self.create_or_update_env_yaml(sdk_name, args.directory) - print(f' Created Environment successfully \n {sdk_name.ljust(30)}{setup_file_path}') + print( + f' Created Environment successfully \n {sdk_name.ljust(30)}{setup_file_path}' + ) sys.exit(0) # Creating an environment if args.file and os.path.exists(args.file): - sdk_name = args.env_name if args.env_name else ( - args.file.split('/')[-1].replace('.sh', '') if args.file else None - ) + sdk_name = args.env_name if args.env_name else (args.file.split( + '/')[-1].replace('.sh', '') if args.file else None) setup_file_path = self.oebuild_env_path + sdk_name self.create_or_update_env_yaml(sdk_name, setup_file_path) self.execute_sdk_file(args.file, setup_file_path) - print(f' Created Environment successfully \n {sdk_name.ljust(30)}{setup_file_path}') + print( + f' Created Environment successfully \n {sdk_name.ljust(30)}{setup_file_path}' + ) sys.exit(0) print('The path is invalid, please check the path ') @@ -180,15 +193,19 @@ Please enter the correct command: oebuild menv create [-d -f] Create an environm print(shell_command) print('setup_file matching successful') - subprocess.check_output('cp ~/.bashrc ~/.bashrc_back', shell=True) + subprocess.check_output('cp ~/.bashrc ~/.bashrc_back', + shell=True) # Obtain the current terminal height and length - terminal_info = fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ, "1234") + terminal_info = fcntl.ioctl(sys.stdout.fileno(), + termios.TIOCGWINSZ, "1234") rows_and_cloumns = struct.unpack('HH', terminal_info) rows_command = f'stty rows {rows_and_cloumns[0]} columns {rows_and_cloumns[1]}' - subprocess.check_output(rf"sed -i '$a\{rows_command}' ~/.bashrc", shell=True) + subprocess.check_output( + rf"sed -i '$a\{rows_command}' ~/.bashrc", shell=True) # Add the command to execute the setup file in the .bashrc file in the # working directory - subprocess.check_output(rf"sed -i '$a\{shell_command}' ~/.bashrc", shell=True) + subprocess.check_output( + rf"sed -i '$a\{shell_command}' ~/.bashrc", shell=True) # Replace Console Prompt subprocess.check_output( rf"sed -i 's/\$ /({env_name})>>>>> /g' ~/.bashrc", @@ -232,11 +249,15 @@ Please proceed with the subsequent operations here{wrap} """ try: if os.path.isdir(setup_file_path): - print(f'The setup file folder already exists.path is {setup_file_path}') + print( + f'The setup file folder already exists.path is {setup_file_path}' + ) else: print('Extracting sdk...............') - subprocess.check_output(f'sh {sdk_file} -d {setup_file_path} -y', shell=True) - subprocess.check_output(f'chmod -R 755 {setup_file_path}', shell=True) + subprocess.check_output( + f'sh {sdk_file} -d {setup_file_path} -y', shell=True) + subprocess.check_output(f'chmod -R 755 {setup_file_path}', + shell=True) except SubprocessError as s_e: print('Please provide the valid folder path') logger.error(str(s_e)) @@ -253,17 +274,25 @@ Please proceed with the subsequent operations here{wrap} """ if not os.path.exists(self.oebuild_env_yaml_path.absolute()): - if not os.path.exists(os.path.dirname(self.oebuild_env_yaml_path.absolute())): - os.makedirs(os.path.dirname(self.oebuild_env_yaml_path.absolute())) + if not os.path.exists( + os.path.dirname(self.oebuild_env_yaml_path.absolute())): + os.makedirs( + os.path.dirname(self.oebuild_env_yaml_path.absolute())) os.mknod(self.oebuild_env_yaml_path) env_dict = oebuild_util.read_yaml(self.oebuild_env_yaml_path) if env_dict and 'env_config' in env_dict: - env_list = self.input_or_update_dict(env_name, setup_file_path, env_dict['env_config']) + env_list = self.input_or_update_dict(env_name, setup_file_path, + env_dict['env_config']) env_dict['env_config'] = env_list oebuild_util.write_yaml(self.oebuild_env_yaml_path, env_dict) return - env_dict = {'env_config': [{'env_name': env_name, 'env_value': setup_file_path}]} + env_dict = { + 'env_config': [{ + 'env_name': env_name, + 'env_value': setup_file_path + }] + } oebuild_util.write_yaml(self.oebuild_env_yaml_path, env_dict) def input_or_update_dict(self, env_name, env_value, env_list): @@ -348,14 +377,16 @@ Do you want to overwrite the path of the original environment configuration(Y/N) env_list.append(env_data) elif '/.local/oebuild_env/' in env_data['env_value']: try: - subprocess.check_output(f'rm -rf {env_data["env_value"]}', shell=True) + subprocess.check_output( + f'rm -rf {env_data["env_value"]}', shell=True) except SubprocessError as s_e: print('Fail deleted') logger.error(str(s_e)) sys.exit(-1) if len(env_list) == len(env_dict['env_config']): - logger.error('The environment does not exist, please check the input') + logger.error( + 'The environment does not exist, please check the input') sys.exit(-1) env_dict['env_config'] = env_list oebuild_util.write_yaml(self.oebuild_env_yaml_path, env_dict) diff --git a/src/oebuild/app/plugins/m_plugin/m_plugin.py b/src/oebuild/app/plugins/m_plugin/m_plugin.py index 1318919..cad99af 100644 --- a/src/oebuild/app/plugins/m_plugin/m_plugin.py +++ b/src/oebuild/app/plugins/m_plugin/m_plugin.py @@ -33,24 +33,28 @@ class MPlugin(OebuildCommand): developped, you can use it through oebuild. """ + help_msg = 'Update the basic environment required for the build' + description = textwrap.dedent(''' + This is a plugin management function that supports users to customize plugin and + add them to the oebuild for use. plugin only affect locally installed oebuilds, + and supports viewing personal existing plugin and uninstalling plugin. + ''') + def __init__(self): self.configure = Configure() - self.oebuild_plugin_commands = ['install', 'list', 'enable', 'disable', 'remove'] - self.oebuild_plugin_path = os.path.expanduser('~') + '/.local/oebuild_plugins/' - self.oebuild_plugin_yaml_path = pathlib.Path( - self.oebuild_plugin_path, 'append_plugins.yaml') - self.oebuild_plugin_repository = pathlib.Path(self.oebuild_plugin_path, 'appends') + self.oebuild_plugin_commands = [ + 'install', 'list', 'enable', 'disable', 'remove' + ] + self.oebuild_plugin_path = os.path.expanduser( + '~') + '/.local/oebuild_plugins/' + self.oebuild_plugin_yaml_path = pathlib.Path(self.oebuild_plugin_path, + 'append_plugins.yaml') + self.oebuild_plugin_repository = pathlib.Path(self.oebuild_plugin_path, + 'appends') plugin_dir = pathlib.Path(oebuild_util.get_plugins_yaml_path()) self.command_ext = OebuildApp().get_command_ext( oebuild_util.read_yaml(plugin_dir)['plugins']) - super().__init__( - 'mplugin', - ' Manage Personal Custom plugin', - description=textwrap.dedent(''' -This is a plugin management function that supports users to customize plugin and add them -to the oebuild for use. plugin only affect locally installed oebuilds, and supports -viewing personal existing plugin and uninstalling plugin. -''')) + super().__init__('mplugin', self.help_msg, self.description) def do_add_parser(self, parser_adder) -> argparse.ArgumentParser: """ @@ -64,9 +68,8 @@ viewing personal existing plugin and uninstalling plugin. Returns: """ - parser = self._parser( - parser_adder, - usage=''' + parser = self._parser(parser_adder, + usage=''' %(prog)s [install list remove enable/disable][command] install: -f file_path -n plugin_name @@ -75,29 +78,33 @@ viewing personal existing plugin and uninstalling plugin. enable/disable: enable/disable -n plugin_name remove: -n plugin_name ''') - parser.add_argument('-f', '--file', dest='file', + parser.add_argument('-f', + '--file', + dest='file', help=''' this param is python file - ''' - ) + ''') - parser.add_argument('-n', '--plugin_name', dest='plugin_name', + parser.add_argument('-n', + '--plugin_name', + dest='plugin_name', help=''' this param is plugin name - ''' - ) + ''') - parser.add_argument('-d', '--dir_path', dest='dir_path', + parser.add_argument('-d', + '--dir_path', + dest='dir_path', help=''' this param is dir path - ''' - ) + ''') - parser.add_argument('-m', '--major', dest='major', + parser.add_argument('-m', + '--major', + dest='major', help=''' this param is major class - ''' - ) + ''') return parser @@ -117,8 +124,9 @@ viewing personal existing plugin and uninstalling plugin. command = '' if not unknown: unknown = ['-h'] - elif unknown[0] not in self.oebuild_plugin_commands or (len(set(unknown[1:]).intersection( - {'-f', '-n', '-d'})) == 0 and unknown[0] != 'list'): + elif unknown[0] not in self.oebuild_plugin_commands or ( + len(set(unknown[1:]).intersection({'-f', '-n', '-d'})) == 0 + and unknown[0] != 'list'): unknown = ['-h'] else: command = unknown[0] @@ -129,8 +137,10 @@ viewing personal existing plugin and uninstalling plugin. args = args.parse_args(unknown) if not os.path.exists(self.oebuild_plugin_yaml_path.absolute()): - if not os.path.exists(os.path.dirname(self.oebuild_plugin_yaml_path.absolute())): - os.makedirs(os.path.dirname(self.oebuild_plugin_yaml_path.absolute())) + if not os.path.exists( + os.path.dirname(self.oebuild_plugin_yaml_path.absolute())): + os.makedirs( + os.path.dirname(self.oebuild_plugin_yaml_path.absolute())) os.mknod(self.oebuild_plugin_yaml_path) plugin_dict = oebuild_util.read_yaml(self.oebuild_plugin_yaml_path) plugin_dict_old = copy.deepcopy(plugin_dict) @@ -143,12 +153,12 @@ viewing personal existing plugin and uninstalling plugin. 'file': args.file, 'plugin_name': args.plugin_name, 'command': command - }, - plugin_dict, - plugin_dict_old) + }, plugin_dict, plugin_dict_old) sys.exit(0) elif args.dir_path and os.path.exists(args.dir_path): - file = str(pathlib.Path(args.dir_path, args.major.split('/')[-1])) + file = str( + pathlib.Path(args.dir_path, + args.major.split('/')[-1])) self._install_for_dir_check(args=args, file=file) self.install_plugin( { @@ -156,16 +166,17 @@ viewing personal existing plugin and uninstalling plugin. 'plugin_name': args.plugin_name, 'command': command, 'dir_path': args.dir_path - }, - plugin_dict, - plugin_dict_old) + }, plugin_dict, plugin_dict_old) sys.exit(0) - logger.error("the %s not exist, please check the plugin file path", args.file) + logger.error("the %s not exist, please check the plugin file path", + args.file) sys.exit(-1) elif command == 'list': self.list_plugin(plugin_dict=plugin_dict) elif command in ['enable', 'disable']: - self.enable_disable_plugin(command=command, plugin_dict=plugin_dict, args=args) + self.enable_disable_plugin(command=command, + plugin_dict=plugin_dict, + args=args) elif command == 'remove': self.remove_plugin(args.plugin_name) @@ -192,7 +203,8 @@ viewing personal existing plugin and uninstalling plugin. for plugin_data in plugin_dict['plugins']: if plugin_data['name'] == args.plugin_name: plugin_data['status'] = command - oebuild_util.write_yaml(self.oebuild_plugin_yaml_path, plugin_dict) + oebuild_util.write_yaml(self.oebuild_plugin_yaml_path, + plugin_dict) print('change success') logger.error('the plugin %s does not exist', args.plugin_name) sys.exit(-1) @@ -205,12 +217,14 @@ viewing personal existing plugin and uninstalling plugin. logger.error(" Please specify the major file ") sys.exit(-1) if not os.path.exists(file): - logger.error("the %s not exist, please check the plugin file path", file) + logger.error("the %s not exist, please check the plugin file path", + file) sys.exit(-1) def _install_param_check(self, args, plugin_dict): if not args.plugin_name: - logger.error('Please enter the correct command: Missing -n parameter ') + logger.error( + 'Please enter the correct command: Missing -n parameter ') sys.exit(-1) if args.plugin_name == 'mplugin': @@ -218,21 +232,24 @@ viewing personal existing plugin and uninstalling plugin. sys.exit(-1) if plugin_dict is not None: - append_command_ext = OebuildApp().get_command_ext(plugin_dict['plugins']) + append_command_ext = OebuildApp().get_command_ext( + plugin_dict['plugins']) else: append_command_ext = {} if args.plugin_name in self.command_ext.keys() \ or args.plugin_name in append_command_ext.keys(): while True: - user_input = input('Do you want to overwrite the existing ' - f'plugin ({args.plugin_name}) in oebuild(Y/N)') + user_input = input( + 'Do you want to overwrite the existing ' + f'plugin ({args.plugin_name}) in oebuild(Y/N)') if user_input.lower() == 'y': break if user_input.lower() == 'n': sys.exit(0) - def create_or_update_plugin_yaml(self, plugin_name, class_name, python_file_name, plugin_dict): + def create_or_update_plugin_yaml(self, plugin_name, class_name, + python_file_name, plugin_dict): """ Args: @@ -253,14 +270,19 @@ viewing personal existing plugin and uninstalling plugin. 'class_name': class_name, 'python_file_name': python_file_name, 'plugin_status': "enable" - }, - plugin_dict['plugins']) + }, plugin_dict['plugins']) plugin_dict['plugins'] = plugin_list oebuild_util.write_yaml(self.oebuild_plugin_yaml_path, plugin_dict) return old_plugin_path - plugin_dict = {'plugins': [{'name': plugin_name, 'class': class_name, - 'path': python_file_name, 'status': 'enable'}]} + plugin_dict = { + 'plugins': [{ + 'name': plugin_name, + 'class': class_name, + 'path': python_file_name, + 'status': 'enable' + }] + } oebuild_util.write_yaml(self.oebuild_plugin_yaml_path, plugin_dict) return old_plugin_path @@ -285,15 +307,18 @@ viewing personal existing plugin and uninstalling plugin. return plugin_list, old_plugin_path if plugin_data['name'] == plugin_obj['plugin_name']: plugin_data['class'] = plugin_obj['class_name'] - old_plugin_path = os.path.abspath(os.path.dirname(plugin_data['path'])) + old_plugin_path = os.path.abspath( + os.path.dirname(plugin_data['path'])) plugin_data['path'] = plugin_obj['python_file_name'] plugin_data['status'] = plugin_obj['plugin_status'] insert_flag = False if insert_flag: - plugin_list.append({'name': plugin_obj['plugin_name'], - 'class': plugin_obj['class_name'], - 'path': plugin_obj['python_file_name'], - 'status': plugin_obj['plugin_status']}) + plugin_list.append({ + 'name': plugin_obj['plugin_name'], + 'class': plugin_obj['class_name'], + 'path': plugin_obj['python_file_name'], + 'status': plugin_obj['plugin_status'] + }) return plugin_list, old_plugin_path def query_method(self, file_path): @@ -309,14 +334,18 @@ viewing personal existing plugin and uninstalling plugin. def_name = "" class_name = "" for file_line in file: - if file_line.startswith('def') or file_line.startswith(' def'): + if file_line.startswith('def') or file_line.startswith( + ' def'): if re.search(r'(?<=def)\s+\w+', file_line): - def_name += re.search(r'(?<=def)\s+\w+', file_line).group() + def_name += re.search(r'(?<=def)\s+\w+', + file_line).group() def_name += "," - if file_line.startswith('class') or file_line.startswith(' class'): + if file_line.startswith('class') or file_line.startswith( + ' class'): if re.search(r'((?<=class)\s+\w+\(OebuildCommand\))', file_line) and \ not class_name: - class_name = re.search(r'(?<=class)\s+\w+', file_line).group().strip() + class_name = re.search(r'(?<=class)\s+\w+', + file_line).group().strip() return def_name, class_name def remove_plugin(self, plugin_name): @@ -333,16 +362,20 @@ viewing personal existing plugin and uninstalling plugin. if plugin_data['name'] == plugin_name: plugin_dict['plugins'].remove(plugin_data) delete_path = os.path.abspath( - pathlib.Path(os.path.dirname(plugin_data['path']), '..')) - subprocess.check_output(f'rm -rf {delete_path}', shell=True) - oebuild_util.write_yaml(self.oebuild_plugin_yaml_path, plugin_dict) + pathlib.Path(os.path.dirname(plugin_data['path']), + '..')) + subprocess.check_output(f'rm -rf {delete_path}', + shell=True) + oebuild_util.write_yaml(self.oebuild_plugin_yaml_path, + plugin_dict) print('delete success') return logger.error('the plugin %s does not exist', plugin_name) else: logger.error('No plugin has been created yet') - def install_plugin(self, install_plugin_object, plugin_dict, plugin_dict_old): + def install_plugin(self, install_plugin_object, plugin_dict, + plugin_dict_old): """ install plugin the install_plugin_object container follow item file: xxx @@ -373,25 +406,28 @@ viewing personal existing plugin and uninstalling plugin. install_plugin_object['plugin_name'], file_name) - old_plugin_path = self.create_or_update_plugin_yaml(install_plugin_object['plugin_name'], - class_name, - str(file_path), plugin_dict) + old_plugin_path = self.create_or_update_plugin_yaml( + install_plugin_object['plugin_name'], class_name, str(file_path), + plugin_dict) if old_plugin_path != '': subprocess.check_output( - f'mv {old_plugin_path} ~/.local/{old_plugin_path.split("/")[-1]}', shell=True) + f'mv {old_plugin_path} ~/.local/{old_plugin_path.split("/")[-1]}', + shell=True) - file_dir_path = pathlib.Path(self.oebuild_plugin_repository, - install_plugin_object['plugin_name']).absolute() + file_dir_path = pathlib.Path( + self.oebuild_plugin_repository, + install_plugin_object['plugin_name']).absolute() if not os.path.exists(pathlib.Path(file_dir_path, 'plugin_info')): os.makedirs(pathlib.Path(file_dir_path, 'plugin_info')) if 'dir_path' not in install_plugin_object: - subprocess.check_output(f"cp {install_plugin_object['file']} {file_path}", - shell=True) + subprocess.check_output( + f"cp {install_plugin_object['file']} {file_path}", shell=True) else: - subprocess.check_output(f"cp -r {install_plugin_object['dir_path']} {file_dir_path}", - shell=True) + subprocess.check_output( + f"cp -r {install_plugin_object['dir_path']} {file_dir_path}", + shell=True) command_info = subprocess.run( ['oebuild', f"{install_plugin_object['plugin_name']}", '-h'], @@ -401,25 +437,34 @@ viewing personal existing plugin and uninstalling plugin. check=False) if command_info.returncode != 0: - logger.error("\nError Message!!!!!!!!!!!!! \n\n %s ", command_info.stderr) - logger.error('Installation failed. There is an issue with your code. ' - 'Please check and fix it before reinstalling.') - - oebuild_util.write_yaml(self.oebuild_plugin_yaml_path, plugin_dict_old) + logger.error("\nError Message!!!!!!!!!!!!! \n\n %s ", + command_info.stderr) + logger.error( + 'Installation failed. There is an issue with your code. ' + 'Please check and fix it before reinstalling.') + + oebuild_util.write_yaml(self.oebuild_plugin_yaml_path, + plugin_dict_old) subprocess.check_output(f'rm -rf {file_dir_path}', shell=True) if old_plugin_path != '': os.makedirs(file_dir_path) subprocess.check_output( - f'cp -r ~/.local/{old_plugin_path.split("/")[-1]} {file_dir_path}', shell=True) + f'cp -r ~/.local/{old_plugin_path.split("/")[-1]} {file_dir_path}', + shell=True) subprocess.check_output( - f'rm -rf ~/.local/{old_plugin_path.split("/")[-1]}', shell=True) + f'rm -rf ~/.local/{old_plugin_path.split("/")[-1]}', + shell=True) sys.exit(-1) if old_plugin_path != '': - subprocess.check_output(f'rm -rf ~/.local/{old_plugin_path.split("/")[-1]}', shell=True) - - print(f"{install_plugin_object['command'].title()} plugin successfully \n" - f'{"name".ljust(20)}{"status".ljust(20)}{"path"} \n' - f"{install_plugin_object['plugin_name'].ljust(20)}{'enable'.ljust(20)}{file_path}") + subprocess.check_output( + f'rm -rf ~/.local/{old_plugin_path.split("/")[-1]}', + shell=True) + + print( + f"{install_plugin_object['command'].title()} plugin successfully \n" + f'{"name".ljust(20)}{"status".ljust(20)}{"path"} \n' + f"{install_plugin_object['plugin_name'].ljust(20)}{'enable'.ljust(20)}{file_path}" + ) diff --git a/src/oebuild/app/plugins/manifest/manifest.py b/src/oebuild/app/plugins/manifest/manifest.py index 8578853..d62e94b 100644 --- a/src/oebuild/app/plugins/manifest/manifest.py +++ b/src/oebuild/app/plugins/manifest/manifest.py @@ -33,23 +33,21 @@ class Manifest(OebuildCommand): relevant source repositories based on the manifest file ''' + help_msg = 'generate manifest from oebuild workspace' + description = textwrap.dedent('''\ + manifest provides the manifest function of generating dependent + source repositories in the build working directory, and can restore + relevant source repositories based on the manifest file + ''') + def __init__(self): self.configure = Configure() self.manifest_command = ['download', 'create'] - super().__init__( - 'manifest', - 'generate manifest from oebuild workspace', - textwrap.dedent('''\ - manifest provides the manifest function of generating dependent - source repositories in the build working directory, and can restore - relevant source repositories based on the manifest file -''' - )) + super().__init__('manifest', self.help_msg, self.description) def do_add_parser(self, parser_adder) -> argparse.ArgumentParser: - parser = self._parser( - parser_adder, - usage=''' + parser = self._parser(parser_adder, + usage=''' %(prog)s [create / download] [-f MANIFEST_DIR] @@ -60,8 +58,7 @@ class Manifest(OebuildCommand): dest='manifest_dir', help=''' specify a manifest path to perform the create or restore operation - ''' - ) + ''') return parser @@ -111,19 +108,23 @@ class Manifest(OebuildCommand): } print("\r", end="") progress = int((index + 1) / len(src_list) * 100) - print(f"Expose progress: {progress}%: ", "▋" * (progress // 2), end="") + print(f"Expose progress: {progress}%: ", + "▋" * (progress // 2), + end="") sys.stdout.flush() print() manifest_list = dict(sorted(manifest_list.items(), key=lambda s: s[0])) - oebuild_util.write_yaml( - yaml_dir=pathlib.Path(manifest_dir), - data={'manifest_list': manifest_list}) + oebuild_util.write_yaml(yaml_dir=pathlib.Path(manifest_dir), + data={'manifest_list': manifest_list}) self._add_manifest_banner(manifest_dir=os.path.abspath(manifest_dir)) - print(f"expose successful, the directory is {os.path.abspath(manifest_dir)}") + print( + f"expose successful, the directory is {os.path.abspath(manifest_dir)}" + ) def _add_manifest_banner(self, manifest_dir): - oebuild_conf_dir = os.path.join(oebuild_util.get_base_oebuild(), 'app/conf') + oebuild_conf_dir = os.path.join(oebuild_util.get_base_oebuild(), + 'app/conf') manifest_banner_dir = os.path.join(oebuild_conf_dir, 'manifest_banner') with open(manifest_banner_dir, 'r', encoding='utf-8') as r_f: @@ -156,10 +157,16 @@ class Manifest(OebuildCommand): all package download successful!!!""") def _download_repo(self, src_dir, key, value): - logger.info("====================download %s=====================", key) - repo_git = OGit(os.path.join(src_dir, key), remote_url=value['remote_url'], branch=None) + logger.info("====================download %s=====================", + key) + repo_git = OGit(os.path.join(src_dir, key), + remote_url=value['remote_url'], + branch=None) if repo_git.check_out_version(version=value['version']): - logger.info("====================download %s successful=====================", key) + logger.info( + "====================download %s successful=====================", + key) return True - logger.warning("====================download %s failed=====================", key) + logger.warning( + "====================download %s failed=====================", key) return False diff --git a/src/oebuild/app/plugins/run_qemu/run_qemu.py b/src/oebuild/app/plugins/run_qemu/run_qemu.py index 5b07801..c4b56fe 100644 --- a/src/oebuild/app/plugins/run_qemu/run_qemu.py +++ b/src/oebuild/app/plugins/run_qemu/run_qemu.py @@ -31,6 +31,11 @@ class RunQemu(OebuildCommand): The command for run in qemu platform. ''' + help_msg = 'run in qemu platform' + description = textwrap.dedent(''' + The command for run in qemu platform. + ''') + def __init__(self): self.configure = Configure() self.client = None @@ -38,35 +43,30 @@ class RunQemu(OebuildCommand): self.work_dir = os.getcwd() self.old_bashrc = None - super().__init__( - 'run_qemu', - 'run in qemu platform', - textwrap.dedent(''' - The command for run in qemu platform. - ''') - ) + super().__init__('run_qemu', self.help_msg, self.description) def __del__(self): if self.client is not None: try: container = self.client.get_container(self.container_id) - self.client.delete_container(container=container, is_force=True) + self.client.delete_container(container=container, + is_force=True) except DockerException: print(f""" -the container {self.container_id} failed to be destroyed, please run +the container {self.container_id} failed to be destroyed, please run `docker rm {self.container_id}` """) def do_add_parser(self, parser_adder): - parser = self._parser( - parser_adder, - usage=''' + parser = self._parser(parser_adder, usage=''' %(prog)s [command] ''') parser_adder.add_argument( - 'command', nargs='?', default=None, + 'command', + nargs='?', + default=None, help='''The name of the directory that will be initialized''') return parser @@ -85,16 +85,17 @@ the container {self.container_id} failed to be destroyed, please run for index, param in enumerate(unknown): if param.startswith("qemuparams"): - unknown[index] = "qemuparams=\""+param.split("=")[1]+"\"" + unknown[index] = "qemuparams=\"" + param.split("=")[1] + "\"" if param.startswith("bootparams"): - unknown[index] = "bootparams=\""+param.split("=")[1]+"\"" + unknown[index] = "bootparams=\"" + param.split("=")[1] + "\"" self.exec_qemu(' '.join(unknown)) def exec_qemu(self, params): ''' exec qemu ''' - container: Container = self.client.get_container(self.container_id) # type: ignore + container: Container = self.client.get_container( + self.container_id) # type: ignore self.bak_bash(container=container) self.init_bash(container=container) content = self._get_bashrc_content(container=container) @@ -104,8 +105,7 @@ the container {self.container_id} failed to be destroyed, please run ) qemu_helper_dir = os.path.join( oebuild_const.CONTAINER_BUILD, - "/tmp/work/x86_64-linux/qemu-helper-native" - ) + "/tmp/work/x86_64-linux/qemu-helper-native") staging_bindir_native = f""" if [ ! -d {qemu_helper_usr} ];then mkdir -p {qemu_helper_usr} @@ -113,12 +113,13 @@ if [ ! -d {qemu_helper_usr} ];then ln -s /opt/buildtools/nativesdk/sysroots/x86_64-pokysdk-linux/usr/bin {qemu_helper_usr} fi """ + content = oebuild_util.add_bashrc(content=content, + line=staging_bindir_native) content = oebuild_util.add_bashrc( - content=content, line=staging_bindir_native) - content = oebuild_util.add_bashrc( - content=content, line=f"mv -f /root/{self.old_bashrc} /root/.bashrc") - content = oebuild_util.add_bashrc( - content=content, line=f"""runqemu {params} && exit""") + content=content, + line=f"mv -f /root/{self.old_bashrc} /root/.bashrc") + content = oebuild_util.add_bashrc(content=content, + line=f"""runqemu {params} && exit""") self.update_bashrc(container=container, content=content) os.system(f"docker exec -it -u root {container.short_id} bash") @@ -131,9 +132,10 @@ fi ''' old_content = self._get_bashrc_content(container=container) self.update_bashrc(container=container, - content=oebuild_util.restore_bashrc_content(old_content=old_content)) + content=oebuild_util.restore_bashrc_content( + old_content=old_content)) - def _check_qemu_ifup(self,): + def _check_qemu_ifup(self, ): if not os.path.exists("/etc/qemu-ifup"): print("""please create a virtual network interface as follows: 1, open /etc/qemu-ifup in vim or vi @@ -145,7 +147,6 @@ fi now, you can continue run `oebuild runqemu` in compile directory """) sys.exit(0) - return def deal_env_container(self, docker_image): ''' @@ -160,7 +161,8 @@ now, you can continue run `oebuild runqemu` in compile directory volumns.append("/dev/net/tun:/dev/net/tun") volumns.append("/etc/qemu-ifup:/etc/qemu-ifup") volumns.append(self.work_dir + ':' + oebuild_const.CONTAINER_BUILD) - volumns.append(self.configure.source_dir() + ':' + oebuild_const.CONTAINER_SRC) + volumns.append(self.configure.source_dir() + ':' + + oebuild_const.CONTAINER_SRC) parameters = oebuild_const.DEFAULT_CONTAINER_PARAMS + " --privileged" container: Container = self.client.create_container( @@ -188,9 +190,7 @@ now, you can continue run `oebuild runqemu` in compile directory self.client.container_exec_command( container=container, command=f"cp /root/.bashrc /root/{old_bash}", - user="root", - work_space=None, - stream=False) + user="root") self.old_bashrc = old_bash def init_bash(self, container: Container): @@ -202,21 +202,20 @@ now, you can continue run `oebuild runqemu` in compile directory # read container default user .bashrc content content = self._get_bashrc_content(container=container) # get nativesdk environment path automatic for next step - sdk_env_path = oebuild_util.get_nativesdk_environment(container=container) + sdk_env_path = oebuild_util.get_nativesdk_environment( + container=container) init_sdk_command = f'. {oebuild_const.NATIVESDK_DIR}/{sdk_env_path}' init_oe_command = f'. {oebuild_const.CONTAINER_SRC}/yocto-poky/oe-init-build-env \ {oebuild_const.CONTAINER_BUILD}' + init_command = [init_sdk_command, init_oe_command] new_content = oebuild_util.init_bashrc_content(content, init_command) self.update_bashrc(container=container, content=new_content) def _get_bashrc_content(self, container: Container): content = self.client.container_exec_command( - container=container, - command="cat /root/.bashrc", - user="root", - work_space=None, - stream=False).output + container=container, command="cat /root/.bashrc", + user="root").output return content.decode() @@ -227,14 +226,11 @@ now, you can continue run `oebuild runqemu` in compile directory remove it ''' tmp_file = self._set_tmpfile_content(content) - self.client.copy_to_container( - container=container, - source_path=tmp_file, - to_path='/root') - container.exec_run( - cmd=f"mv /root/{tmp_file} /root/.bashrc", - user="root" - ) + self.client.copy_to_container(container=container, + source_path=tmp_file, + to_path='/root') + container.exec_run(cmd=f"mv /root/{tmp_file} /root/.bashrc", + user="root") os.remove(tmp_file) def _set_tmpfile_content(self, content: str): diff --git a/src/oebuild/app/plugins/update/update.py b/src/oebuild/app/plugins/update/update.py index 96d8338..cf11c26 100644 --- a/src/oebuild/app/plugins/update/update.py +++ b/src/oebuild/app/plugins/update/update.py @@ -36,46 +36,47 @@ class Update(OebuildCommand): related to the build, such as container images, build base repositories, etc ''' + help_msg = 'Update the basic environment required for the build' + description = textwrap.dedent(''' + The update command will involve three areas, namely the build container, + yocto-meta-openeuler and the corresponding layers, if there are no parameters + after the update, it will be updated in order yocto-meta-openeuler, build + container and layers, the update of these three places is related, the update + of the build container will be affected by three factors, first, execute the + tag parameter, The container image related to the tag is updated, the second + identifies the build container image bound to the main build repository, in + yocto-meta-openeuler/.oebuild/env.yaml, the third identifies the branch + information of the main build repository, and identifies the type of build image + through the branch information of the main build repository. The layer update must + rely on yocto-meta-openeuler, if the main build repository does not exist will first + download the main build repository (the relevant git information is in .oebuild/config), + the layers update execution logic is different in different directories, if not in + the build directory will be parsed yocto-meta-openeuler/.oebuild/ common.yaml to get + the information that needs to be updated, and if it is in the build directory, it will + parse compile.yaml to get the updated information + ''') + def __init__(self): self.configure = Configure() - super().__init__( - 'update', - 'Update the basic environment required for the build', - textwrap.dedent(''' - The update command will involve three areas, namely the build container, - yocto-meta-openeuler and the corresponding layers, if there are no parameters - after the update, it will be updated in order yocto-meta-openeuler, build - container and layers, the update of these three places is related, the update - of the build container will be affected by three factors, first, execute the - tag parameter, The container image related to the tag is updated, the second - identifies the build container image bound to the main build repository, in - yocto-meta-openeuler/.oebuild/env.yaml, the third identifies the branch - information of the main build repository, and identifies the type of build image - through the branch information of the main build repository. The layer update must - rely on yocto-meta-openeuler, if the main build repository does not exist will first - download the main build repository (the relevant git information is in .oebuild/config), - the layers update execution logic is different in different directories, if not in - the build directory will be parsed yocto-meta-openeuler/.oebuild/ common.yaml to get - the information that needs to be updated, and if it is in the build directory, it will - parse compile.yaml to get the updated information - ''') - ) + super().__init__('update', self.help_msg, self.description) def do_add_parser(self, parser_adder): - parser = self._parser( - parser_adder, - usage=''' + parser = self._parser(parser_adder, + usage=''' %(prog)s [yocto docker layer] [-tag] ''') - parser.add_argument('-tag', '--tag', dest='docker_tag', + parser.add_argument('-tag', + '--tag', + dest='docker_tag', help=''' with platform will list support archs, with feature will list support features - ''' - ) + ''') parser.add_argument( - 'item', nargs='?', default=None, + 'item', + nargs='?', + default=None, help='''The name of the directory that will be initialized''') return parser @@ -127,12 +128,13 @@ class Update(OebuildCommand): if update_layer: self.get_layer_repo() - def get_layer_repo(self,): + def get_layer_repo(self, ): ''' download or update layers that will be needed ''' # check the main layer if exists - yocto_dir = os.path.join(self.configure.source_dir(), "yocto-meta-openeuler") + yocto_dir = os.path.join(self.configure.source_dir(), + "yocto-meta-openeuler") if not os.path.exists(yocto_dir): # update main layer self.get_basic_repo() @@ -140,28 +142,32 @@ class Update(OebuildCommand): # or /compile.yaml where in build directory repos = None if os.path.exists(os.path.join(os.getcwd(), "compile.yaml")): - parse_compile = ParseCompile(compile_conf_dir=os.path.join(os.getcwd(), "compile.yaml")) + parse_compile = ParseCompile( + compile_conf_dir=os.path.join(os.getcwd(), "compile.yaml")) repos = parse_compile.repos else: - common_path = pathlib.Path(os.path.join(yocto_dir, ".oebuild/common.yaml")) + common_path = pathlib.Path( + os.path.join(yocto_dir, ".oebuild/common.yaml")) repos = oebuild_util.read_yaml(yaml_dir=common_path)['repos'] if repos is None: return for _, item in repos.items(): if isinstance(item, OebuildRepo): - local_dir = os.path.join(self.configure.source_dir(), item.path) + local_dir = os.path.join(self.configure.source_dir(), + item.path) key_repo = OGit(repo_dir=local_dir, remote_url=item.url, branch=item.refspec) else: - local_dir = os.path.join(self.configure.source_dir(), item['path']) + local_dir = os.path.join(self.configure.source_dir(), + item['path']) key_repo = OGit(repo_dir=local_dir, remote_url=item['url'], branch=item['refspec']) key_repo.clone_or_pull_repo() - def get_basic_repo(self,): + def get_basic_repo(self, ): ''' note: get_basic_repo is to download or update basic repo in config which set in keys basic_repo, the rule is that when the @@ -172,9 +178,11 @@ class Update(OebuildCommand): embedded/src/yocto-meta-openeuler not exists, so just clone from config setting. ''' oebuild_config = self.configure.parse_oebuild_config() - yocto_config: ConfigBasicRepo = oebuild_config.basic_repo[oebuild_const.YOCTO_META_OPENEULER] + yocto_config: ConfigBasicRepo = \ + oebuild_config.basic_repo[oebuild_const.YOCTO_META_OPENEULER] - local_dir = os.path.join(self.configure.source_dir(), yocto_config.path) + local_dir = os.path.join(self.configure.source_dir(), + yocto_config.path) yocto_repo = OGit(repo_dir=local_dir, remote_url=yocto_config.remote_url, branch=yocto_config.branch) @@ -182,27 +190,33 @@ class Update(OebuildCommand): def docker_image_update(self, docker_tag=None): ''' - The container update logic is to update the corresponding tag - container image if tag is specified, otherwise it is determined - according to the yocto-meta-openeuler version branch in config, - and if the version branch does not correspond to it, it will enter + The container update logic is to update the corresponding tag + container image if tag is specified, otherwise it is determined + according to the yocto-meta-openeuler version branch in config, + and if the version branch does not correspond to it, it will enter interactive mode, which is selected by the user ''' oebuild_config = self.configure.parse_oebuild_config() docker_config = oebuild_config.docker - check_docker_tag = CheckDockerTag(docker_tag=docker_tag, configure=self.configure) + check_docker_tag = CheckDockerTag(docker_tag=docker_tag, + configure=self.configure) if docker_tag is not None: - if check_docker_tag.get_tag() is None or check_docker_tag.get_tag() == "": + if check_docker_tag.get_tag() is None or check_docker_tag.get_tag( + ) == "": check_docker_tag.list_image_tag() return - docker_image = docker_config.repo_url + ":" + check_docker_tag.get_tag() + docker_image = docker_config.repo_url + ":" + check_docker_tag.get_tag( + ) else: - docker_image = YoctoEnv().get_docker_image(self.configure.source_yocto_dir()) + docker_image = YoctoEnv().get_docker_image( + self.configure.source_yocto_dir()) if docker_image is None or docker_image == "": - if check_docker_tag.get_tag() is None or check_docker_tag.get_tag() == "": + if check_docker_tag.get_tag( + ) is None or check_docker_tag.get_tag() == "": check_docker_tag.list_image_tag() return - docker_image = docker_config.repo_url + ":" + check_docker_tag.get_tag() + docker_image = docker_config.repo_url + ":" + check_docker_tag.get_tag( + ) client = DockerProxy() logger.info("Pull %s ...", docker_image) -- Gitee From e302885cee0942fa178a65c1d68a9acc6ac4d9e2 Mon Sep 17 00:00:00 2001 From: xuansen fang Date: Thu, 21 Mar 2024 17:35:18 +0800 Subject: [PATCH 2/2] Optimzed: impore the class init process *Transforming the properties of base class into the properties of subclasses *avoiding instantiate and function callback, improving performance Signed-off-by: fangxuansen fangxuansen@ncti-gba.cn --- src/oebuild/spec.py | 32 ++++++++++++++------------------ src/oebuild/util.py | 27 ++++++++++++++++++--------- 2 files changed, 32 insertions(+), 27 deletions(-) diff --git a/src/oebuild/spec.py b/src/oebuild/spec.py index 5b19ba7..cc7d882 100644 --- a/src/oebuild/spec.py +++ b/src/oebuild/spec.py @@ -36,7 +36,7 @@ class ExtensionCommandError(CommandError): def __init__(self, **kwargs): self.hint = kwargs.pop('hint', None) - super(ExtensionCommandError, self).__init__(**kwargs) + super().__init__(**kwargs) @dataclass @@ -62,18 +62,11 @@ class _CmdFactory: # Get the attribute which provides the OebuildCommand subclass. try: - cls = getattr(mod, self.attr) + return getattr(mod, self.attr) except AttributeError as a_e: raise ExtensionCommandError( hint=f'no attribute {self.attr} in {self.py_file}') from a_e - # Create the command instance and return it. - try: - return cls() - except Exception as e_p: - raise ExtensionCommandError( - hint='command constructor threw an exception') from e_p - @dataclass class OebuildExtCommandSpec: @@ -111,15 +104,18 @@ def get_spec(pre_dir, command_ext: _ExtCommand): xxx ''' - py_file = os.path.join(os.path.dirname(__file__), pre_dir, command_ext.path) if ( - '/.local/oebuild_plugins/' not in command_ext.path) else command_ext.path - factory = _CmdFactory(py_file=py_file, name=command_ext.name, attr=command_ext.class_name) - - return OebuildExtCommandSpec( - name=command_ext.name, - description=factory().description, - help=factory().help_msg, - factory=factory) + py_file = os.path.join( + os.path.dirname(__file__), pre_dir, + command_ext.path) if ('/.local/oebuild_plugins/' + not in command_ext.path) else command_ext.path + factory = _CmdFactory(py_file=py_file, + name=command_ext.name, + attr=command_ext.class_name) + + return OebuildExtCommandSpec(name=command_ext.name, + description=factory().description, + help=factory().help_msg, + factory=factory) def _commands_module_from_file(file, mod_name): diff --git a/src/oebuild/util.py b/src/oebuild/util.py index 14945fb..9db1e4b 100644 --- a/src/oebuild/util.py +++ b/src/oebuild/util.py @@ -49,9 +49,12 @@ def get_nativesdk_environment(nativesdk_dir=oebuild_const.NATIVESDK_DIR, if os.path.isfile(abs_path) and not os.path.islink(abs_path): return item else: - res = container.exec_run("ls -al", user=oebuild_const.CONTAINER_USER, workdir=nativesdk_dir) + res = container.exec_run("ls -al", + user=oebuild_const.CONTAINER_USER, + workdir=nativesdk_dir) if res.exit_code != 0: - logger.error("can not find any nativesdk environment initialization shell") + logger.error( + "can not find any nativesdk environment initialization shell") sys.exit(res.exit_code) list_items = res.output.decode("utf-8").split("\n") for item in list_items: @@ -62,7 +65,8 @@ def get_nativesdk_environment(nativesdk_dir=oebuild_const.NATIVESDK_DIR, item_split = item.split(" ") if len(item_split) <= 0: continue - ret = re.match("^(environment-setup-)", item_split[len(item_split) - 1]) + ret = re.match("^(environment-setup-)", + item_split[len(item_split) - 1]) if ret is not None and item_split[0].startswith("-"): return item_split[len(item_split) - 1] @@ -129,28 +133,32 @@ def get_config_yaml_dir(): ''' return config yaml dir ''' - return os.path.join(get_base_oebuild(), 'app/conf', oebuild_const.CONFIG_YAML) + return os.path.join(get_base_oebuild(), 'app/conf', + oebuild_const.CONFIG_YAML) def get_plugins_yaml_path(): ''' return plugin yaml path ''' - return os.path.join(get_base_oebuild(), 'app/conf', oebuild_const.PLUGINS_YAML) + return os.path.join(get_base_oebuild(), 'app/conf', + oebuild_const.PLUGINS_YAML) def get_compile_yaml_dir(): ''' return compile.yaml.sample yaml dir ''' - return os.path.join(get_base_oebuild(), 'app/conf', oebuild_const.COMPILE_YAML) + return os.path.join(get_base_oebuild(), 'app/conf', + oebuild_const.COMPILE_YAML) def get_upgrade_yaml_dir(): ''' return upgrade yaml dir ''' - return os.path.join(get_base_oebuild(), 'app/conf', oebuild_const.UPGRADE_YAML) + return os.path.join(get_base_oebuild(), 'app/conf', + oebuild_const.UPGRADE_YAML) def generate_random_str(randomlength=16): @@ -199,7 +207,7 @@ def get_instance(factory): ''' Instantiate a class ''' - return factory() + return factory()() def restore_bashrc_content(old_content): @@ -209,7 +217,8 @@ def restore_bashrc_content(old_content): new_content = '' for line in old_content.split('\n'): line: str = line - if line.endswith(oebuild_const.BASH_END_FLAG) or line.replace(" ", '') == '': + if line.endswith(oebuild_const.BASH_END_FLAG) or line.replace( + " ", '') == '': continue new_content = new_content + line + '\n' return new_content -- Gitee