From acf1e764952f98e35ee54a0a7112cd61089a7056 Mon Sep 17 00:00:00 2001 From: lixinyu Date: Wed, 17 Jan 2024 15:03:22 +0800 Subject: [PATCH] code: format the code * optimize the code format and let it more standardized Signed-off-by: alichinese --- setup.py | 16 +- src/oebuild/app/conf/plugins.yaml | 4 +- src/oebuild/app/main.py | 8 +- .../app/plugins/bitbake/in_container.py | 37 ++-- src/oebuild/app/plugins/bitbake/in_host.py | 17 +- src/oebuild/app/plugins/clear/clear.py | 4 +- src/oebuild/app/plugins/compile/compile.py | 167 ------------------ src/oebuild/app/plugins/deploy/com_target.py | 64 +++++-- .../app/plugins/deploy/deploy-image.py | 0 .../{deploy-target.py => deploy_target.py} | 0 src/oebuild/app/plugins/generate/generate.py | 8 +- src/oebuild/app/plugins/m_env/m_env.py | 163 +++++++++-------- src/oebuild/app/plugins/m_plugin/m_plugin.py | 93 ++++++---- src/oebuild/app/plugins/run_qemu/run_qemu.py | 29 ++- src/oebuild/const.py | 1 + src/oebuild/docker_proxy.py | 6 +- src/oebuild/local_conf.py | 6 +- src/oebuild/ogit.py | 2 +- src/oebuild/parse_env.py | 12 +- src/oebuild/parse_template.py | 6 +- src/oebuild/util.py | 9 +- 21 files changed, 314 insertions(+), 338 deletions(-) delete mode 100644 src/oebuild/app/plugins/compile/compile.py delete mode 100644 src/oebuild/app/plugins/deploy/deploy-image.py rename src/oebuild/app/plugins/deploy/{deploy-target.py => deploy_target.py} (100%) diff --git a/setup.py b/setup.py index ddbecb8..ea6b18a 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,15 @@ +''' +Copyright (c) 2023 openEuler Embedded +oebuild is licensed under Mulan PSL v2. +You can use this software according to the terms and conditions of the Mulan PSL v2. +You may obtain a copy of Mulan PSL v2 at: + http://license.coscl.org.cn/MulanPSL2 +THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, +EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +See the Mulan PSL v2 for more details. +''' + import os import setuptools @@ -5,10 +17,10 @@ import setuptools SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) os.chdir(SCRIPT_DIR) -with open('README.rst', 'r') as f: +with open('README.md', 'r', encoding="utf-8") as f: long_description = f.read() -with open('src/oebuild/version.py', 'r') as f: +with open('src/oebuild/version.py', 'r', encoding="utf-8") as f: __version__ = None exec(f.read()) assert __version__ is not None diff --git a/src/oebuild/app/conf/plugins.yaml b/src/oebuild/app/conf/plugins.yaml index 83e65df..e4b6de0 100644 --- a/src/oebuild/app/conf/plugins.yaml +++ b/src/oebuild/app/conf/plugins.yaml @@ -25,10 +25,10 @@ plugins: path: plugins/m_env/m_env.py - name: deploy-target class: DeployTarget - path: plugins/deploy/deploy-target.py + path: plugins/deploy/deploy_target.py - name: undeploy-target class: UnDeployTarget - path: plugins/deploy/deploy-target.py + path: plugins/deploy/deploy_target.py - name: mplugin class: MPlugin path: plugins/m_plugin/m_plugin.py diff --git a/src/oebuild/app/main.py b/src/oebuild/app/main.py index 0f4db78..aed6e09 100644 --- a/src/oebuild/app/main.py +++ b/src/oebuild/app/main.py @@ -41,9 +41,11 @@ class OebuildApp: self.oebuild_plugins_path = os.path.expanduser('~') + '/.local/oebuild_plugins/' self.append_plugins_dir = pathlib.Path(self.oebuild_plugins_path, 'append_plugins.yaml') self.command_ext = self.get_command_ext(oebuild_util.read_yaml(plugins_dir)['plugins']) - if os.path.exists(self.append_plugins_dir) and oebuild_util.read_yaml(self.append_plugins_dir): - self.command_ext = self.get_command_ext(oebuild_util.read_yaml(self.append_plugins_dir)['plugins'], - self.command_ext) + if os.path.exists(self.append_plugins_dir) \ + and oebuild_util.read_yaml(self.append_plugins_dir): + self.command_ext = self.get_command_ext( + oebuild_util.read_yaml(self.append_plugins_dir)['plugins'], + self.command_ext) self.command_spec = {} except Exception as e_p: raise e_p diff --git a/src/oebuild/app/plugins/bitbake/in_container.py b/src/oebuild/app/plugins/bitbake/in_container.py index 4dd229a..e71b567 100644 --- a/src/oebuild/app/plugins/bitbake/in_container.py +++ b/src/oebuild/app/plugins/bitbake/in_container.py @@ -34,15 +34,6 @@ class InContainer(BaseBuild): self.client = DockerProxy() self.container_id = None - def __del__(self): - if self.container_id is None: - return - # try: - # container = self.client.get_container(self.container_id) - # self.client.stop_container(container=container) - # except Exception as e_p: - # raise e_p - def exec(self, parse_env: ParseEnv, parse_compile: ParseCompile, command): ''' execute bitbake command @@ -172,7 +163,7 @@ class InContainer(BaseBuild): else: content = self._get_bashrc_content(container=container) for b_s in oebuild_const.BASH_BANNER.split('\n'): - b_s = f"echo {b_s}{oebuild_const.BASH_END_FLAG}" + b_s = f"echo {b_s}" content = self._add_bashrc(content=content, line=b_s) self.update_bashrc(container=container, content=content) os.system( @@ -266,10 +257,21 @@ class InContainer(BaseBuild): self._install_software(container=container, software="sudo") def _replace_yum_mirror(self, container: Container): + """ + replace the yum mirror in container + + Args: + container (Container): 目标容器 + + Returns: + None + """ self.client.container_exec_command( container=container, user='root', - command=r"sed -i 's/repo.openeuler.org/mirrors.huaweicloud.com\/openeuler/g' /etc/yum.repos.d/openEuler.repo", + command=r""" + sed -i 's/repo.openeuler.org/mirrors.huaweicloud.com\/openeuler/g' /etc/yum.repos.d/openEuler.repo + """, work_space=f"/home/{oebuild_const.CONTAINER_USER}", stream=False ) @@ -302,8 +304,13 @@ class InContainer(BaseBuild): command = f'export {key}={value}; git config --global {key_git} {value};' init_proxy_command = f'{init_proxy_command} {command}' - init_sdk_command = f'. {oebuild_const.NATIVESDK_DIR}/{oebuild_util.get_nativesdk_environment(container=container)}' - set_template = f'export TEMPLATECONF="{oebuild_const.CONTAINER_SRC}/yocto-meta-openeuler/.oebuild"' + # get nativesdk environment path automatic for next step + sdk_env_path = oebuild_util.get_nativesdk_environment(container=container) + init_sdk_command = f'. {oebuild_const.NATIVESDK_DIR}/{sdk_env_path}' + # get template dir for initialize yocto build environment + template_dir = f"{oebuild_const.CONTAINER_SRC}/yocto-meta-openeuler/.oebuild" + set_template = f'export TEMPLATECONF="{template_dir}"' + init_oe_comand = f'. {oebuild_const.CONTAINER_SRC}/yocto-poky/oe-init-build-env \ {oebuild_const.CONTAINER_BUILD}/{build_dir_name}' init_command = [init_proxy_command, init_sdk_command, set_template, init_oe_comand] @@ -323,7 +330,9 @@ class InContainer(BaseBuild): source_path=tmp_file, to_path=f'/home/{oebuild_const.CONTAINER_USER}') container.exec_run( - cmd=f"mv /home/{oebuild_const.CONTAINER_USER}/{tmp_file} /home/{oebuild_const.CONTAINER_USER}/.bashrc", + cmd=f''' + mv /home/{oebuild_const.CONTAINER_USER}/{tmp_file} /home/{oebuild_const.CONTAINER_USER}/.bashrc + ''', user="root" ) os.remove(tmp_file) diff --git a/src/oebuild/app/plugins/bitbake/in_host.py b/src/oebuild/app/plugins/bitbake/in_host.py index f9d1c4c..7c258cb 100644 --- a/src/oebuild/app/plugins/bitbake/in_host.py +++ b/src/oebuild/app/plugins/bitbake/in_host.py @@ -109,13 +109,20 @@ initialization operations''') pty.spawn("bash") def _mk_build_sh(self, nativesdk_dir, build_dir): - init_sdk_command = f'. {nativesdk_dir}/{oebuild_util.get_nativesdk_environment(nativesdk_dir)}' - set_template = f'export TEMPLATECONF="{self.configure.source_dir()}/yocto-meta-openeuler/.oebuild"' - init_oe_command = f'. {self.configure.source_dir()}/yocto-poky/oe-init-build-env {build_dir}' + # get nativesdk environment path automatic for next step + sdk_env_path = oebuild_util.get_nativesdk_environment(nativesdk_dir) + init_sdk_command = f'. {nativesdk_dir}/{sdk_env_path}' + # get template dir for initialize yocto build environment + template_dir = f"{self.configure.source_dir()}/yocto-meta-openeuler/.oebuild" + set_template = f'export TEMPLATECONF="{template_dir}"' + init_oe_command = f'. {self.configure.source_dir()}/yocto-poky/oe-init-build-env \ + {build_dir}' ps1_command = 'PS1="\\u\\h:\\W> "' - self._append_build_sh(str_list= [init_sdk_command, set_template, init_oe_command, ps1_command], - build_dir=build_dir) + self._append_build_sh( + str_list= [init_sdk_command, set_template, init_oe_command, ps1_command], + build_dir=build_dir + ) def _init_build_sh(self, build_dir): build_sh_dir = os.path.join(build_dir, 'build.sh') diff --git a/src/oebuild/app/plugins/clear/clear.py b/src/oebuild/app/plugins/clear/clear.py index 69b306b..c6663f8 100644 --- a/src/oebuild/app/plugins/clear/clear.py +++ b/src/oebuild/app/plugins/clear/clear.py @@ -92,7 +92,9 @@ class Clear(OebuildCommand): DockerProxy().stop_container(container=container) DockerProxy().delete_container(container=container) logger.info("Delete container: %s successful",container.short_id) - except: + except DockerException: + continue + except KeyError: continue # get all container which name start with oebuild and delete it, diff --git a/src/oebuild/app/plugins/compile/compile.py b/src/oebuild/app/plugins/compile/compile.py deleted file mode 100644 index e030855..0000000 --- a/src/oebuild/app/plugins/compile/compile.py +++ /dev/null @@ -1,167 +0,0 @@ -''' -Copyright (c) 2023 openEuler Embedded -oebuild is licensed under Mulan PSL v2. -You can use this software according to the terms and conditions of the Mulan PSL v2. -You may obtain a copy of Mulan PSL v2 at: - http://license.coscl.org.cn/MulanPSL2 -THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, -EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, -MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. -See the Mulan PSL v2 for more details. -''' - -import argparse -import textwrap -import os - -from docker.errors import DockerException - -from docker.models.containers import Container -from oebuild.docker_proxy import DockerProxy - -from oebuild.command import OebuildCommand -from oebuild.configure import Configure -from oebuild.m_log import logger - -class Compile(OebuildCommand): - ''' - The command for cross-compile, configure runtime environment, run code and output results. - ''' - def __init__(self): - self.compile_conf_dir = os.path.join(os.getcwd(), 'compile.yaml') - self.configure = Configure() - self.client = None - self.container_id = None - self.dir_platform = None - self.chain_platform = None - - super().__init__( - 'cross-compile', - 'Cross-compile for the code file', - textwrap.dedent(''' - This command will perform cross-compile the c or cpp file for openEuler platform. - ''') - ) - - def do_add_parser(self, parser_adder): - parser = self._parser( - parser_adder, - usage=''' - - %(prog)s [-d source_directory] [-p platform] -''') - - parser.add_argument('-d', dest='source_directory', nargs='?', default=None, - help=''' - Source file path - ''' - ) - - parser.add_argument('-p', dest='platform', default="aarch64", - help=''' - this param is for arch. All possible choices: arm, aarch64, riscv64, x86_64 - ''' - ) - - return parser - - def do_run(self, args: argparse.Namespace, unknown=None): - - #logger.info(args) - # perpare parse help command - if self.pre_parse_help(args, unknown): - return - # Parse the command-line arguments - args = args.parse_args(unknown) - try: - self.client = DockerProxy() - except DockerException: - logger.error("Please install docker first!!!") - return - - if(args.source_directory) is None: - logger.error('Please specify directory of the source file') - self.dir_platform, self.chain_platform = self._check_platform(args) - self._check_file(args) - self.cross_compile(cross_compile_dir_target_file = args.source_directory) - - def cross_compile(self, cross_compile_dir_target_file): - ''' - for cross compile task - ''' - logger.info("cross-compilation starting ...") - - default_image = "swr.cn-north-4.myhuaweicloud.com/openeuler-embedded/openeuler-container:latest" - - container_target_dir = "./" - _final_dir_platform = self.dir_platform - _final_chain_platform = self.chain_platform - - # parse_compile = ParseCompile(self.compile_conf_dir) - if not self.client.is_image_exists(default_image): - logger.error(f'''The docker image does not exists, please run fellow command: - `oebuild update docker`''') - container:Container = self.client.container_run_simple(image=default_image, volumes=[]) - - logger.info("cross-compilation copying into the docker ...") - self.client.copy_to_container( - container=container, - source_path=cross_compile_dir_target_file, - to_path=container_target_dir) - - environment_var = { - "PATH": f"/usr1/openeuler/gcc/openeuler_gcc_{_final_dir_platform}/bin:/usr1/openeuler/gcc:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" - } - - # Compile inside the docker - logger.info("cross-compilation gonna run inside the docker ...") - - compile_command = f"/bin/sh -c '{_final_chain_platform}-{self._tool_chain_type} -o {container_target_dir}{self._target_base_name} {container_target_dir}{self._target_file_name} -static'" - exec_result = container.exec_run(compile_command, environment = environment_var) - # logger.info(exec_result) - - logger.info("cross-compilation copying file from docker to host ...") - # copy compiled file from container to host - output_file = "./" # output to ./ - self.client.copy_from_container( - container=container, - from_path=f"{container_target_dir}{self._target_base_name}", - dst_path=output_file) - - logger.info("cross-compilation finished!") - container.stop() - container.remove() - - def _check_file(self, args): - file_path = args.source_directory - if not os.path.exists(file_path): - raise ValueError(f"The file '{file_path}' does not exist, please check again") - else: - self._target_file_name = os.path.basename(file_path) # hello.c - self._target_base_name = os.path.splitext(self._target_file_name)[0] # hello - self._target_extension_name = self._target_file_name.split('.')[-1] # c - - if self._target_extension_name == "c": - self._tool_chain_type = "gcc" - elif self._target_extension_name == "cpp": - self._tool_chain_type = "g++" - else: - raise ValueError(f"The extension name of file '{self._target_extension_name}' is wrong, only c or cpp are supported") - - - def _check_platform(self, args): - if args.platform == "arm": - _dir_platform = "arm32le" - _chain_platform = "arm-openeuler-linux-gnueabi" - elif args.platform == "aarch64": - _dir_platform = "arm64le" - _chain_platform = "aarch64-openeuler-linux-gnu" - elif args.platform == "riscv64": - _dir_platform = "riscv64" - _chain_platform = "riscv64-openeuler-linux-gnu" - elif args.platform == "x86_64": - _dir_platform = "x86_64" - _chain_platform = "x86_64-openeuler-linux-gnu" - else: - raise ValueError(f"such platform '{args.platform}' does not exist, please check again") - return _dir_platform, _chain_platform diff --git a/src/oebuild/app/plugins/deploy/com_target.py b/src/oebuild/app/plugins/deploy/com_target.py index d4f8db0..5559ad3 100644 --- a/src/oebuild/app/plugins/deploy/com_target.py +++ b/src/oebuild/app/plugins/deploy/com_target.py @@ -31,6 +31,10 @@ TARGET_DIR_NAME = "target_dev" TARGET_SCRIPT_NAME = "oebuild_dev" class ComTarget: + ''' + The class is used to deploy-target and undeploy-target, this is a main body, the deploy-target + and undeploy-target is just a interface and finally go into ComTarget + ''' def __init__(self) -> None: self.configure = Configure() self.client:DockerProxy = None @@ -52,7 +56,10 @@ the container {self.container_id} failed to be destroyed, please run """) def exec(self, str_args: str, fun): - + ''' + the exec as a common function that will be invoked by deploy-target and undeploy-target, + it means this is a entry runner. + ''' self.client = DockerProxy() if not self._check_compile_directory(): @@ -64,12 +71,15 @@ the container {self.container_id} failed to be destroyed, please run sys.exit(-1) if not self._check_yocto_poky(): - logger.error('''Please make sure that yocto-poky source code in src directory, or you can run: + logger.error(''' + Please make sure that yocto-poky source code be in src directory, or you can run: oebuild update layer''') sys.exit(-1) if not self._check_conf_directory(): - logger.error("You must work in a exist build directory, that mean you built before or initialize environment at least") + logger.error(''' + You must work in a exist build directory, that mean you built before or initialize environment at least + ''') sys.exit(-1) logger.info("Initializing environment, please wait ...") @@ -79,11 +89,21 @@ the container {self.container_id} failed to be destroyed, please run self.bak_bash(container=container) self.init_bash(container=container) content = self._get_bashrc_content(container=container) - content = oebuild_util.add_bashrc(content=content, line=f"export PATH=$PATH:/home/openeuler/{TARGET_DIR_NAME}") - content = oebuild_util.add_bashrc(content=content, line=f"mv -f /home/{oebuild_const.CONTAINER_USER}/{self.old_bashrc} /home/{oebuild_const.CONTAINER_USER}/.bashrc") - content = oebuild_util.add_bashrc(content=content, line=f"{TARGET_SCRIPT_NAME} {fun} {str_args}") + content = oebuild_util.add_bashrc( + content=content, + line=f"export PATH=$PATH:/home/openeuler/{TARGET_DIR_NAME}") + content = oebuild_util.add_bashrc( + content=content, + line=f""" + mv -f /home/{oebuild_const.CONTAINER_USER}/{self.old_bashrc} /home/{oebuild_const.CONTAINER_USER}/.bashrc + """) + content = oebuild_util.add_bashrc( + content=content, + line=f"{TARGET_SCRIPT_NAME} {fun} {str_args}") print(f"{TARGET_SCRIPT_NAME} {str_args}") - content = oebuild_util.add_bashrc(content=content, line=f"rm -rf /home/openeuler/{TARGET_DIR_NAME} && exit") + content = oebuild_util.add_bashrc( + content=content, + line=f"rm -rf /home/openeuler/{TARGET_DIR_NAME} && exit") self.update_bashrc(container=container, content=content) os.system(f"docker exec -it -u {oebuild_const.CONTAINER_USER} {container.short_id} bash") @@ -116,7 +136,7 @@ the container {self.container_id} failed to be destroyed, please run on compile.yaml, which is initialized by parsing the file ''' return os.path.exists(os.path.join(self.work_dir, 'compile.yaml')) - + def _check_yocto_poky(self,): ''' package deploy need poky lib, so we have a detect about yocto-poky @@ -129,7 +149,10 @@ the container {self.container_id} failed to be destroyed, please run # copy package lib to docker curr_path = os.path.dirname(os.path.realpath(__file__)) lib_path = os.path.join(curr_path, TARGET_DIR_NAME) - self.client.copy_to_container(container=container, source_path=lib_path, to_path="/home/openeuler/") + self.client.copy_to_container( + container=container, + source_path=lib_path, + to_path="/home/openeuler/") container.exec_run(f"chmod 755 /home/openeuler/{TARGET_DIR_NAME}/{TARGET_SCRIPT_NAME}") def deal_env_container(self,docker_image:str): @@ -163,17 +186,20 @@ the container {self.container_id} failed to be destroyed, please run def bak_bash(self, container: Container): ''' - xxx + before we alter .bashrc we should make a copy or named bak to another where, thus when we + finished some thing we can restore it. ''' old_bash = oebuild_util.generate_random_str(6) self.client.container_exec_command( container=container, - command=f"cp /home/{oebuild_const.CONTAINER_USER}/.bashrc /home/{oebuild_const.CONTAINER_USER}/{old_bash}", + command=f""" + cp /home/{oebuild_const.CONTAINER_USER}/.bashrc /home/{oebuild_const.CONTAINER_USER}/{old_bash} + """, user="root", work_space=None, stream=False) self.old_bashrc = old_bash - + def init_bash(self, container: Container): ''' Bitbake will initialize the compilation environment by reading @@ -183,7 +209,9 @@ the container {self.container_id} failed to be destroyed, please run self._check_change_ugid(container=container) # read container default user .bashrc content content = self._get_bashrc_content(container=container) - init_sdk_command = f'. {oebuild_const.NATIVESDK_DIR}/{oebuild_util.get_nativesdk_environment(container=container)}' + # get nativesdk environment path automatic for next step + sdk_env_path = oebuild_util.get_nativesdk_environment(container=container) + init_sdk_command = f'. {oebuild_const.NATIVESDK_DIR}/{sdk_env_path}' build_dir_name = os.path.basename(self.work_dir) init_oe_command = f'. {oebuild_const.CONTAINER_SRC}/yocto-poky/oe-init-build-env \ {oebuild_const.CONTAINER_BUILD}/{build_dir_name}' @@ -200,7 +228,7 @@ the container {self.container_id} failed to be destroyed, please run stream=False).output return content.decode() - + def update_bashrc(self, container: Container, content: str): ''' update user initialization script by replace file, first create @@ -213,7 +241,9 @@ the container {self.container_id} failed to be destroyed, please run source_path=tmp_file, to_path=f'/home/{oebuild_const.CONTAINER_USER}') container.exec_run( - cmd=f"mv /home/{oebuild_const.CONTAINER_USER}/{tmp_file} /home/{oebuild_const.CONTAINER_USER}/.bashrc", + cmd=f""" + mv /home/{oebuild_const.CONTAINER_USER}/{tmp_file} /home/{oebuild_const.CONTAINER_USER}/.bashrc + """, user="root" ) os.remove(tmp_file) @@ -236,7 +266,7 @@ the container {self.container_id} failed to be destroyed, please run old_content = self._get_bashrc_content(container=container) self.update_bashrc(container=container, content=self._restore_bashrc_content(old_content=old_content)) - + def _restore_bashrc_content(self, old_content): new_content = '' for line in old_content.split('\n'): @@ -295,4 +325,4 @@ the container {self.container_id} failed to be destroyed, please run user='root', command=f"groupmod -g {gid} {oebuild_const.CONTAINER_USER}", work_space=f"/home/{oebuild_const.CONTAINER_USER}", - stream=False) \ No newline at end of file + stream=False) diff --git a/src/oebuild/app/plugins/deploy/deploy-image.py b/src/oebuild/app/plugins/deploy/deploy-image.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/oebuild/app/plugins/deploy/deploy-target.py b/src/oebuild/app/plugins/deploy/deploy_target.py similarity index 100% rename from src/oebuild/app/plugins/deploy/deploy-target.py rename to src/oebuild/app/plugins/deploy/deploy_target.py diff --git a/src/oebuild/app/plugins/generate/generate.py b/src/oebuild/app/plugins/generate/generate.py index 96d3f85..fa75fa2 100644 --- a/src/oebuild/app/plugins/generate/generate.py +++ b/src/oebuild/app/plugins/generate/generate.py @@ -325,7 +325,9 @@ oebuild bitbake except BaseParseTemplate as e_p: raise e_p else: - raise ValueError("wrong platform, please run `oebuild generate -l` to view support platform") + logger.error(""" +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): if args.features: @@ -338,7 +340,9 @@ oebuild bitbake except BaseParseTemplate as b_t: raise b_t else: - raise ValueError("wrong platform, please run `oebuild generate -l` to view support feature") + logger.error(""" +wrong platform, please run `oebuild generate -l` to view support feature""") + sys.exit(-1) def _init_build_dir(self, args): if not os.path.exists(self.configure.build_dir()): diff --git a/src/oebuild/app/plugins/m_env/m_env.py b/src/oebuild/app/plugins/m_env/m_env.py index 02831d6..9552ae1 100644 --- a/src/oebuild/app/plugins/m_env/m_env.py +++ b/src/oebuild/app/plugins/m_env/m_env.py @@ -12,47 +12,53 @@ See the Mulan PSL v2 for more details. import argparse import fcntl -import logging import pty import re import struct import subprocess +from subprocess import SubprocessError import sys import termios import textwrap +import os +import pathlib -from oebuild import util from oebuild.command import OebuildCommand from oebuild.configure import Configure -from oebuild.util import * - -logger = logging.getLogger() - +import oebuild.util as oebuild_util +from oebuild.m_log import logger class Menv(OebuildCommand): - + ''' + the class is used to manager sdk environment, the sdk environment refers to openEuler + Embedded image sdk, you can use the sdk to develop some apps that can run in openEuler + Embedded system you built. for example, the sdk with qt image can be used to develop apps + runned in qt system, the sdk with ros image can be used to develop apps runned in ros system + ''' def __init__(self): self.configure = Configure() 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', 'active', 'remove'] + 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''' - )) + 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 do_add_parser(self, parser_adder) -> argparse.ArgumentParser: parser = self._parser( parser_adder, - usage=''' - %(prog)s [create list remove activation][command] + usage=''' + %(prog)s [create list remove activate][command] create: [-d -f] Create an environment -n env_name list: View existing environment remove: -n Delete specified environment - active: -n Active specified environment + activate: -n Activate specified environment ''') parser.add_argument('-d', '--directory', dest='directory', @@ -91,7 +97,9 @@ class Menv(OebuildCommand): if command == 'create': if not args.env_name: - print('Please enter the correct command: oebuild menv create [-d -f] Create an environment -n env_name') + print(''' + Please enter the correct command: oebuild menv create [-d -f] Create an environment -n env_name + ''') return # Check if the file path exists if args.directory and os.path.isdir(args.directory): @@ -102,26 +110,27 @@ class Menv(OebuildCommand): return # Creating an environment - elif 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 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 + ) 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}') return - else: - print('The path is invalid, please check the path ') - elif command == 'active': + + print('The path is invalid, please check the path ') + elif command == 'activate': # Activate Environment if args.env_name: return self.activate_environment(args.env_name) - else: - print('Please enter the correct command: oebuild menv active -n env_name') + print('Please enter the correct command: oebuild menv activate -n env_name') elif command == 'list': - env_dict = util.read_yaml(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: - self.view_environment(None, env_dict) + self.list_environment(None, env_dict) else: print('No environment has been created yet') return @@ -130,8 +139,7 @@ class Menv(OebuildCommand): elif command == 'remove': if args.env_name: return self.delete_environment(args.env_name) - else: - print('Please enter the correct command: oebuild menv remove -n env_name') + print('Please enter the correct command: oebuild menv remove -n env_name') def execute_setup_directory(self, setup_file_path, env_name): """ @@ -149,51 +157,56 @@ class Menv(OebuildCommand): # Determine the number of setup_files if setup_num == 1: try: - # Determine if the path ends with / - setup_file_path = setup_file_path if setup_file_path.endswith('/') else setup_file_path + '/' - # Convert relative path to absolute path - file_path = setup_file_path + re.search('environment-setup.*?(?=\')', file_list).group() + file_path = os.path.join( + setup_file_path, + re.search('environment-setup.*?(?=\')', file_list).group()) absolute_file_path = os.path.abspath(file_path) # Splice Execution Command shell_command = '. ' + absolute_file_path print(shell_command) print('setup_file matching successful') - subprocess.check_output(rf'''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") 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) - # 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\{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) # Replace Console Prompt - subprocess.check_output(rf'''sed -i 's/\$ /({env_name})>>>>> /g' ~/.bashrc''', shell=True) - subprocess.check_output(rf'''sed -i '$a\mv ~/.bashrc_back ~/.bashrc -f' ~/.bashrc''', shell=True) + subprocess.check_output( + rf"sed -i 's/\$ /({env_name})>>>>> /g' ~/.bashrc", + shell=True) + subprocess.check_output( + r"sed -i '$a\mv ~/.bashrc_back ~/.bashrc -f' ~/.bashrc", + shell=True) # Add prompt words separator = "====================================================" prompt_one = "Your environment is ready" prompt_two = "Please proceed with the subsequent operations here" wrap = '\\n###!###\\n' prompt_words = separator + wrap + prompt_one + wrap + prompt_two + wrap + separator - subprocess.check_output(rf'''sed -i '$a\echo "{prompt_words}"' ~/.bashrc''', shell=True) + subprocess.check_output( + rf'''sed -i '$a\echo "{prompt_words}"' ~/.bashrc''', + shell=True) pty.spawn("/bin/bash") - except Exception as c_e: - print(c_e) + except SubprocessError as s_e: print('Please provide the valid folder path') - logger.error(c_e) - return False + logger.error(str(s_e)) + sys.exit(-1) return True - elif setup_num == 0: + if setup_num == 0: print('not setup_file, please check your directory') return False - else: - print('Illegal path, only one environment setup file allowed') - return False + print('Illegal path, only one environment setup file allowed') + return False def execute_sdk_file(self, sdk_file, setup_file_path): """ - Execute the SDK file, produce the setup folder, and then execute the corresponding method for the setup file + Execute the SDK file, produce the setup folder, and then execute the corresponding + method for the setup file Args: sdk_file: SDK file path setup_file_path: setup file path @@ -208,9 +221,10 @@ class Menv(OebuildCommand): 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) - except Exception as c_e: + except SubprocessError as s_e: print('Please provide the valid folder path') - logger.error(c_e) + logger.error(str(s_e)) + sys.exit(1) def create_or_update_env_yaml(self, env_name, setup_file_path): """ @@ -226,15 +240,15 @@ class Menv(OebuildCommand): 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 = util.read_yaml(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_dict['env_config'] = env_list - util.write_yaml(self.oebuild_env_yaml_path, env_dict) + 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}]} - util.write_yaml(self.oebuild_env_yaml_path, env_dict) + oebuild_util.write_yaml(self.oebuild_env_yaml_path, env_dict) def input_or_update_dict(self, env_name, env_value, env_list): """ @@ -254,12 +268,13 @@ class Menv(OebuildCommand): return if env_data['env_name'] == env_name: while True: - user_input = input( - "Do you want to overwrite the path of the original environment configuration(Y/N)") + user_input = input(""" + Do you want to overwrite the path of the original environment configuration(Y/N) + """) if user_input.lower() == 'y': env_data['env_value'] = env_value break - elif user_input.lower() == 'n': + if user_input.lower() == 'n': return [] insert_flag = False if insert_flag: @@ -267,16 +282,20 @@ class Menv(OebuildCommand): return env_list def activate_environment(self, env_name): - env_dict = util.read_yaml(self.oebuild_env_yaml_path) + ''' + activate the sdk environment, is means that environment shell will be sourced, and + open a new pty, so that developer can compile app with sdk environment + ''' + env_dict = oebuild_util.read_yaml(self.oebuild_env_yaml_path) if env_dict and 'env_config' in env_dict: - setup_file_path = self.view_environment(env_name, env_dict) + setup_file_path = self.list_environment(env_name, env_dict) if setup_file_path: - return self.execute_setup_directory(setup_file_path, env_name) - else: - print('The environment does not exist') + self.execute_setup_directory(setup_file_path, env_name) return + print('The environment does not exist') + return - def view_environment(self, env_name, env_dict): + def list_environment(self, env_name, env_dict): """ View the environment, if env_ If name exists, it is necessary to find the corresponding environment's setup file @@ -292,8 +311,6 @@ class Menv(OebuildCommand): return env_data['env_value'] print(env_data['env_name'].ljust(30) + env_data['env_value']) - return - def delete_environment(self, env_name): """ delete your environment @@ -303,7 +320,7 @@ class Menv(OebuildCommand): Returns: """ - env_dict = util.read_yaml(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 = [] for env_data in env_dict['env_config']: @@ -313,17 +330,15 @@ class Menv(OebuildCommand): elif '/.local/oebuild_env/' in env_data['env_value']: try: subprocess.check_output(f'rm -rf {env_data["env_value"]}', shell=True) - except Exception as r_e: + except SubprocessError as s_e: print('Fail deleted') - print(r_e) - logger.error(r_e) - return + logger.error(str(s_e)) + sys.exit(-1) if len(env_list) == len(env_dict['env_config']): - print('The environment does not exist, please check the input') - return - else: - env_dict['env_config'] = env_list - util.write_yaml(self.oebuild_env_yaml_path, env_dict) + 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) print('Successfully deleted') return diff --git a/src/oebuild/app/plugins/m_plugin/m_plugin.py b/src/oebuild/app/plugins/m_plugin/m_plugin.py index 7c4f882..af3403a 100644 --- a/src/oebuild/app/plugins/m_plugin/m_plugin.py +++ b/src/oebuild/app/plugins/m_plugin/m_plugin.py @@ -12,39 +12,40 @@ See the Mulan PSL v2 for more details. import argparse import copy -import datetime import os import pathlib import re import subprocess import textwrap -import logging -import time from oebuild.command import OebuildCommand import oebuild.util as oebuild_util from oebuild.configure import Configure from oebuild.app.main import OebuildApp - -logger = logging.getLogger() +from oebuild.m_log import logger class MPlugin(OebuildCommand): - """ Plugin management function """ - + """ + this class is used to manager oebuild plugin, you can install, list, enable and so on to + manager it, the plugin must be in oebuild plugin standard, when you install the plugin you + developped, you can use it through oebuild. + """ 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_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_base_oebuild(), 'app/conf', 'plugins.yaml') - self.command_ext = OebuildApp().get_command_ext(oebuild_util.read_yaml(plugin_dir)['plugins']) + 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 + 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.''' )) @@ -134,7 +135,7 @@ class MPlugin(OebuildCommand): if command == 'install': if not args.plugin_name: - logger.error(f'Please enter the correct command: Missing -n parameter ') + logger.error('Please enter the correct command: Missing -n parameter ') return if args.plugin_name == 'mplugin': @@ -146,16 +147,22 @@ class MPlugin(OebuildCommand): else: append_command_ext = {} - if args.plugin_name in self.command_ext.keys() or args.plugin_name in append_command_ext.keys(): + if args.plugin_name in self.command_ext.keys() \ + or args.plugin_name in append_command_ext.keys(): while True: user_input = input( - f"Do you want to overwrite the existing plugin ({args.plugin_name}) in oebuild(Y/N)") +f'Do you want to overwrite the existing plugin ({args.plugin_name}) in oebuild(Y/N)') if user_input.lower() == 'y': break if user_input.lower() == 'n': return if args.file and os.path.exists(args.file): - self.install_plugin(args.file, args.plugin_name, plugin_dict, plugin_dict_old, command, None) + self.install_plugin(args.file, + args.plugin_name, + plugin_dict, + plugin_dict_old, + command, + None) elif args.dir_path and os.path.exists(args.dir_path): if not args.major: @@ -163,12 +170,18 @@ class MPlugin(OebuildCommand): return file = str(pathlib.Path(args.dir_path, args.major.split('/')[-1])) if not os.path.exists(file): - logger.error(f"the {file} not exist, please check the plugin file path") + logger.error("the %s not exist, please check the plugin file path", file) return - self.install_plugin(file, args.plugin_name, plugin_dict, plugin_dict_old, command, args.dir_path) + self.install_plugin( + file, + args.plugin_name, + plugin_dict, + plugin_dict_old, + command, + args.dir_path) else: - logger.error(f"the {args.file} not exist, please check the plugin file path") + logger.error("the %s not exist, please check the plugin file path", args.file) return if command == 'list': if plugin_dict and 'plugins' in plugin_dict: @@ -189,7 +202,7 @@ class MPlugin(OebuildCommand): oebuild_util.write_yaml(self.oebuild_plugin_yaml_path, plugin_dict) print('change success') return - logger.error(f'the plugin {args.plugin_name} does not exist') + logger.error('the plugin %s does not exist', args.plugin_name) else: logger.error('No plugin has been created yet') @@ -211,8 +224,12 @@ class MPlugin(OebuildCommand): old_plugin_path = '' if plugin_dict and 'plugins' in plugin_dict: - plugin_list, old_plugin_path = self.input_or_update_dict(plugin_name, class_name, python_file_name, - 'enable', plugin_dict['plugins']) + plugin_list, old_plugin_path = self.input_or_update_dict( + plugin_name, + class_name, + python_file_name, + 'enable', + plugin_dict['plugins']) plugin_dict['plugins'] = plugin_list oebuild_util.write_yaml(self.oebuild_plugin_yaml_path, plugin_dict) return old_plugin_path @@ -222,7 +239,12 @@ class MPlugin(OebuildCommand): oebuild_util.write_yaml(self.oebuild_plugin_yaml_path, plugin_dict) return old_plugin_path - def input_or_update_dict(self, plugin_name, class_name, python_file_name, plugin_status, plugin_list): + def input_or_update_dict(self, + plugin_name, + class_name, + python_file_name, + plugin_status, + plugin_list): """ Modify or insert environmental data Args: @@ -270,7 +292,8 @@ class MPlugin(OebuildCommand): def_name += re.search(r'(?<=def)\s+\w+', file_line).group() def_name += "," if file_line.startswith('class') or file_line.startswith(' class'): - if re.search(r'((?<=class)\s+\w+\(OebuildCommand\))', file_line) and not class_name: + 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() return def_name, class_name @@ -287,12 +310,13 @@ class MPlugin(OebuildCommand): for plugin_data in plugin_dict['plugins']: 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']), '..')) + 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) print('delete success') return - logger.error(f'the plugin {plugin_name} does not exist') + logger.error('the plugin %s does not exist', plugin_name) else: logger.error('No plugin has been created yet') @@ -328,7 +352,8 @@ class MPlugin(OebuildCommand): 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) + subprocess.check_output( + f'mv {old_plugin_path} ~/.local/{old_plugin_path.split("/")[-1]}', shell=True) file_dir_path = pathlib.Path(self.oebuild_plugin_repository, plugin_name).absolute() if not os.path.exists(pathlib.Path(file_dir_path, 'plugin_info')): @@ -339,11 +364,15 @@ class MPlugin(OebuildCommand): else: subprocess.check_output(f'cp -r {dir_path} {file_dir_path}', shell=True) - command_info = subprocess.run(['oebuild', f'{plugin_name}', '-h'], stdout=subprocess.PIPE, - stderr=subprocess.PIPE, text=True) + command_info = subprocess.run( + ['oebuild', f'{plugin_name}', '-h'], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + text=True, + check=False) if command_info.returncode != 0: - logger.error("\nError Message!!!!!!!!!!!!! \n\n" + command_info.stderr) + 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.') @@ -353,8 +382,10 @@ class MPlugin(OebuildCommand): 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) - subprocess.check_output(f'rm -rf ~/.local/{old_plugin_path.split("/")[-1]}', shell=True) + subprocess.check_output( + 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) return if old_plugin_path != '': diff --git a/src/oebuild/app/plugins/run_qemu/run_qemu.py b/src/oebuild/app/plugins/run_qemu/run_qemu.py index a51c8a0..0732a29 100644 --- a/src/oebuild/app/plugins/run_qemu/run_qemu.py +++ b/src/oebuild/app/plugins/run_qemu/run_qemu.py @@ -96,18 +96,27 @@ the container {self.container_id} failed to be destroyed, please run self.bak_bash(container=container) self.init_bash(container=container) content = self._get_bashrc_content(container=container) - qemu_helper_usr = oebuild_const.CONTAINER_BUILD+"/tmp/work/x86_64-linux/qemu-helper-native/1.0-r1/recipe-sysroot-native/usr" - qemu_helper_dir = oebuild_const.CONTAINER_BUILD+"/tmp/work/x86_64-linux/qemu-helper-native" - STAGING_BINDIR_NATIVE = f""" + qemu_helper_usr = os.path.join( + oebuild_const.CONTAINER_BUILD, + "/tmp/work/x86_64-linux/qemu-helper-native/1.0-r1/recipe-sysroot-native/usr" + ) + qemu_helper_dir = os.path.join( + oebuild_const.CONTAINER_BUILD, + "/tmp/work/x86_64-linux/qemu-helper-native" + ) + staging_bindir_native = f""" if [ ! -d {qemu_helper_usr} ];then mkdir -p {qemu_helper_usr} chown -R {oebuild_const.CONTAINER_USER}:{oebuild_const.CONTAINER_USER} {qemu_helper_dir} 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=f"mv -f /root/{self.old_bashrc} /root/.bashrc") - content = oebuild_util.add_bashrc(content=content, line=f"""runqemu {params} && exit""") + 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""") self.update_bashrc(container=container, content=content) os.system(f"docker exec -it -u root {container.short_id} bash") @@ -190,9 +199,11 @@ now, you can continue run `oebuild runqemu` in compile directory ''' # read container default user .bashrc content content = self._get_bashrc_content(container=container) - - init_sdk_command = f'. {oebuild_const.NATIVESDK_DIR}/{oebuild_util.get_nativesdk_environment(container=container)}' - init_oe_command = f'. {oebuild_const.CONTAINER_SRC}/yocto-poky/oe-init-build-env {oebuild_const.CONTAINER_BUILD}' + # get nativesdk environment path automatic for next step + 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) diff --git a/src/oebuild/const.py b/src/oebuild/const.py index 195342d..690e0b7 100644 --- a/src/oebuild/const.py +++ b/src/oebuild/const.py @@ -12,6 +12,7 @@ See the Mulan PSL v2 for more details. # used for util.py CONFIG_YAML = 'config.yaml' +PLUGINS_YAML = 'plugins.yaml' UPGRADE_YAML = 'upgrade.yaml' COMPILE_YAML = 'compile.yaml.sample' BASH_END_FLAG = " ###!!!###" diff --git a/src/oebuild/docker_proxy.py b/src/oebuild/docker_proxy.py index 077299b..f3b00ff 100644 --- a/src/oebuild/docker_proxy.py +++ b/src/oebuild/docker_proxy.py @@ -207,7 +207,11 @@ class DockerProxy: return res - def create_container(self, image:str, parameters:str, volumes:list[str], command:str) -> Container: + def create_container(self, + image:str, + parameters:str, + volumes:list[str], + command:str) -> Container: ''' create a new container ''' diff --git a/src/oebuild/local_conf.py b/src/oebuild/local_conf.py index 5f27a93..1f93ed6 100644 --- a/src/oebuild/local_conf.py +++ b/src/oebuild/local_conf.py @@ -117,9 +117,11 @@ class LocalConf: # replace toolchain if parse_compile.toolchain_dir is not None: if parse_compile.build_in == oebuild_const.BUILD_IN_DOCKER: - replace_toolchain_str = f'{parse_compile.toolchain_type} = "{oebuild_const.NATIVE_GCC_DIR}"' + replace_toolchain_str = f''' +{parse_compile.toolchain_type} = "{oebuild_const.NATIVE_GCC_DIR}"''' else: - replace_toolchain_str = f'{parse_compile.toolchain_type} = "{parse_compile.toolchain_dir}"' + replace_toolchain_str = f''' +{parse_compile.toolchain_type} = "{parse_compile.toolchain_dir}"''' content = match_and_replace( pre=parse_compile.toolchain_type, new_str=replace_toolchain_str, diff --git a/src/oebuild/ogit.py b/src/oebuild/ogit.py index 5c2a511..c04d253 100644 --- a/src/oebuild/ogit.py +++ b/src/oebuild/ogit.py @@ -112,6 +112,6 @@ class CustomRemote(git.RemoteProgress): rewrote update function ''' end_str = "\r" - if op_code & 2 == 2: + if op_code & 2 == RemoteProgress.END: end_str = "\r\n" print(self._cur_line, end=end_str) diff --git a/src/oebuild/parse_env.py b/src/oebuild/parse_env.py index 16e4798..98fcc44 100644 --- a/src/oebuild/parse_env.py +++ b/src/oebuild/parse_env.py @@ -13,8 +13,10 @@ See the Mulan PSL v2 for more details. from typing import Optional from dataclasses import dataclass import pathlib +import sys import oebuild.util as oebuild_util +from oebuild.m_log import logger @dataclass class EnvContainer: @@ -57,9 +59,13 @@ class ParseEnv: if "container" in data: env_container = data['container'] - self.env.container = EnvContainer( - short_id=env_container['short_id'] - ) + try: + self.env.container = EnvContainer( + short_id=env_container['short_id'] + ) + except KeyError: + logger.error(".env parse error, please check it") + sys.exit(-1) def set_env_container(self, env_container: EnvContainer): ''' diff --git a/src/oebuild/parse_template.py b/src/oebuild/parse_template.py index d93ffc2..a13399c 100644 --- a/src/oebuild/parse_template.py +++ b/src/oebuild/parse_template.py @@ -142,9 +142,9 @@ class ParseTemplate: if 'support' in data: support_arch = data['support'].split('|') if platform not in support_arch: - raise FeatureNotSupport(f'your arch is {platform}, \ - the feature is not supported, please check your \ - application support archs') + raise FeatureNotSupport(f''' +your arch is {platform}, the feature is not supported, please check your application support archs +''') self.feature_template.append(FeatureTemplate( feature_name=LiteralScalarString(os.path.splitext(config_name)[0]), diff --git a/src/oebuild/util.py b/src/oebuild/util.py index dd6c6b6..6ed560a 100644 --- a/src/oebuild/util.py +++ b/src/oebuild/util.py @@ -55,7 +55,8 @@ def get_nativesdk_environment(nativesdk_dir=oebuild_const.NATIVESDK_DIR, list_items = res.output.decode("utf-8").split("\n") for item in list_items: item:str = item - # notice: the item is like format with "drwxr-xr-x 3 openeuler openeuler 4096 Nov 8 08:10 ." + # notice: the item is like format with + # "drwxr-xr-x 3 openeuler openeuler 4096 Nov 8 08:10 ." # so we must get the last clip from split with space item_split = item.split(" ") if len(item_split) <= 0: @@ -124,6 +125,12 @@ def get_config_yaml_dir(): ''' 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) + def get_compile_yaml_dir(): ''' return compile.yaml.sample yaml dir -- Gitee