From 639cb8d282b51caa03539af811ba77ba3fae28b0 Mon Sep 17 00:00:00 2001 From: alichinese Date: Sat, 24 Jun 2023 09:18:15 +0800 Subject: [PATCH 1/5] help: improve the help command mechanism * optimize the underlying structure and add pre-parsing of help commands to cope with the scenario of self-parsing commands Signed-off-by: lixinyu --- src/oebuild/app/plugins/bitbake/bitbake.py | 2 +- src/oebuild/app/plugins/clear/clear.py | 6 +++++- src/oebuild/app/plugins/generate/generate.py | 4 ++++ src/oebuild/app/plugins/init/init.py | 8 ++++++-- src/oebuild/app/plugins/manifest/manifest.py | 4 ++++ src/oebuild/app/plugins/update/update.py | 4 ++++ src/oebuild/command.py | 14 ++++++++++++-- 7 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/oebuild/app/plugins/bitbake/bitbake.py b/src/oebuild/app/plugins/bitbake/bitbake.py index a92ad40..e9fc707 100644 --- a/src/oebuild/app/plugins/bitbake/bitbake.py +++ b/src/oebuild/app/plugins/bitbake/bitbake.py @@ -68,7 +68,7 @@ class Bitbake(OebuildCommand): and the fourth step to enter the build environment ''' if '-h' in unknown or '--help' in unknown: - args.parse_args(unknown) + self.print_help_msg() return command = self._get_command(unknow=unknown) diff --git a/src/oebuild/app/plugins/clear/clear.py b/src/oebuild/app/plugins/clear/clear.py index 80bc413..318e43b 100644 --- a/src/oebuild/app/plugins/clear/clear.py +++ b/src/oebuild/app/plugins/clear/clear.py @@ -51,8 +51,12 @@ class Clear(OebuildCommand): return parser def do_run(self, args: argparse.Namespace, unknown = None): + # perpare parse help command + if self.pre_parse_help(args, unknown): + return + args = args.parse_args(unknown) - + if args.item == "docker": self.clear_docker() diff --git a/src/oebuild/app/plugins/generate/generate.py b/src/oebuild/app/plugins/generate/generate.py index 62bcf8c..bea902b 100644 --- a/src/oebuild/app/plugins/generate/generate.py +++ b/src/oebuild/app/plugins/generate/generate.py @@ -139,6 +139,10 @@ class Generate(OebuildCommand): return parser def do_run(self, args: argparse.Namespace, unknown = None): + # perpare parse help command + if self.pre_parse_help(args, unknown): + return + args = args.parse_args(unknown) if not self.configure.is_oebuild_dir(): diff --git a/src/oebuild/app/plugins/init/init.py b/src/oebuild/app/plugins/init/init.py index 02ae440..aa482ad 100644 --- a/src/oebuild/app/plugins/init/init.py +++ b/src/oebuild/app/plugins/init/init.py @@ -66,7 +66,11 @@ class Init(OebuildCommand): ''' detach target dicrectory if finished init, if inited, just put out err msg and exit ''' - iargs = args + + # perpare parse help command + if self.pre_parse_help(args, unknown): + return + args = args.parse_args(unknown) if self.configure.is_oebuild_dir(): @@ -78,7 +82,7 @@ class Init(OebuildCommand): if args.directory is None: logger.error("'oebuild init' need param directory") logger.info("\noebuild init help:") - self.print_help(iargs) + self.print_help_msg() return if not self.init_workspace(args.directory): diff --git a/src/oebuild/app/plugins/manifest/manifest.py b/src/oebuild/app/plugins/manifest/manifest.py index e550232..f5ea527 100644 --- a/src/oebuild/app/plugins/manifest/manifest.py +++ b/src/oebuild/app/plugins/manifest/manifest.py @@ -83,6 +83,10 @@ class Manifest(OebuildCommand): return parser def do_run(self, args: argparse.Namespace, unknown = None): + # perpare parse help command + if self.pre_parse_help(args, unknown): + return + args = args.parse_args(unknown) if not self.configure.is_oebuild_dir(): diff --git a/src/oebuild/app/plugins/update/update.py b/src/oebuild/app/plugins/update/update.py index e90010a..82eae1d 100644 --- a/src/oebuild/app/plugins/update/update.py +++ b/src/oebuild/app/plugins/update/update.py @@ -68,6 +68,10 @@ class Update(OebuildCommand): ''' update action rely on directory which has initd, so check it first ''' + # perpare parse help command + if self.pre_parse_help(args, unknown): + return + args = args.parse_args(unknown) if not self.configure.is_oebuild_dir(): diff --git a/src/oebuild/command.py b/src/oebuild/command.py index 8af8072..07d22bf 100644 --- a/src/oebuild/command.py +++ b/src/oebuild/command.py @@ -35,11 +35,21 @@ class OebuildCommand(ABC): The executing body, each inherited class will register the executor with the executor body for execution ''' + self.do_run(args=args, unknown=unknown) + + def pre_parse_help(self, args: argparse.ArgumentParser, unknown: List[str]): + ''' + Whether to parse the help command in advance, designed to adapt to some extended + scenarios that do not require command resolution, generally the function is placed + in the front of the do_run to execute, if it returns true, it means that it is a + help command, then there is no need to continue to execute, otherwise the specific + function content is executed + ''' pars = args.parse_args(unknown) if pars.help: self.print_help_msg() - return - self.do_run(args=args, unknown=unknown) + return True + return False def add_parser(self, parser_adder: argparse.ArgumentParser): ''' -- Gitee From 182e916071c0d38d4f975000a6d90d7e1b112c00 Mon Sep 17 00:00:00 2001 From: alichinese Date: Sat, 24 Jun 2023 09:21:30 +0800 Subject: [PATCH 2/5] clear: format some code * format a line log code Signed-off-by: lixinyu --- src/oebuild/app/plugins/clear/clear.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/oebuild/app/plugins/clear/clear.py b/src/oebuild/app/plugins/clear/clear.py index 318e43b..8b6733c 100644 --- a/src/oebuild/app/plugins/clear/clear.py +++ b/src/oebuild/app/plugins/clear/clear.py @@ -72,7 +72,7 @@ class Clear(OebuildCommand): build_dir = os.path.join(self.configure.build_dir(), build_dir) if os.path.exists(os.path.join(build_dir,".env")): env_list.append(os.path.join(build_dir,".env")) - + # traversal every env file and get container_id, and then try to stop it and rm it for env in env_list: env_conf = oebuild_util.read_yaml(pathlib.Path(env)) @@ -81,10 +81,10 @@ class Clear(OebuildCommand): container = self.client.get_container(container_id=container_id) DockerProxy().stop_container(container=container) DockerProxy().delete_container(container=container) - logger.info(f"delete container: {container.short_id} successful") + logger.info("delete container: %s successful",container.short_id) except: continue - + # get all container which name start with oebuild and delete it, # in case when user rm build directory then legacy container # containers = self.client.get_all_container() -- Gitee From e0568eb8914a371e7bc9c7a053c6191b7a685052 Mon Sep 17 00:00:00 2001 From: alichinese Date: Sat, 24 Jun 2023 10:30:07 +0800 Subject: [PATCH 3/5] manifest: fix generate manifest.yaml bug * generate generate.yaml file and use upstream when reading remote, and adapt to the remote name set when dynamically downloading the upstream repository during yocto build Signed-off-by: lixinyu --- src/oebuild/app/plugins/manifest/manifest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/oebuild/app/plugins/manifest/manifest.py b/src/oebuild/app/plugins/manifest/manifest.py index f5ea527..f20b9e9 100644 --- a/src/oebuild/app/plugins/manifest/manifest.py +++ b/src/oebuild/app/plugins/manifest/manifest.py @@ -105,7 +105,7 @@ class Manifest(OebuildCommand): local_dir = os.path.join(self.configure.source_dir(), repo_dir) try: repo = Repo(local_dir) - remote_url = repo.remote().url + remote_url = repo.remote("upstream").url version = repo.head.commit.hexsha except git.GitError: continue @@ -183,7 +183,7 @@ class Manifest(OebuildCommand): else: continue if remote is None: - remote_name = "manifest" + remote_name = "upstream" remote = git.Remote.add(repo = repo, name = remote_name, url = value['remote_url']) try: repo.git.checkout(value['version']) -- Gitee From 3034df01001997115683f58376e784860a99b0bc Mon Sep 17 00:00:00 2001 From: alichinese Date: Sat, 24 Jun 2023 14:28:16 +0800 Subject: [PATCH 4/5] version: upgrade version to 0.0.26 * alter version to 0.0.26 Signed-off-by: lixinyu --- src/oebuild/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/oebuild/version.py b/src/oebuild/version.py index bc48636..d705e18 100644 --- a/src/oebuild/version.py +++ b/src/oebuild/version.py @@ -10,4 +10,4 @@ MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. See the Mulan PSL v2 for more details. ''' -__version__ = '0.0.25' +__version__ = '0.0.26' -- Gitee From 6918d9c8990b9dabef7f778b4c8a92a78d75cb17 Mon Sep 17 00:00:00 2001 From: alichinese Date: Sat, 24 Jun 2023 14:33:11 +0800 Subject: [PATCH 5/5] init: fix a bug * when run init command, oebuild should copy compile.yaml.sample to .oebuild directory, now fix this bug Signed-off-by: lixinyu --- src/oebuild/app/plugins/init/init.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/oebuild/app/plugins/init/init.py b/src/oebuild/app/plugins/init/init.py index aa482ad..c71bb79 100644 --- a/src/oebuild/app/plugins/init/init.py +++ b/src/oebuild/app/plugins/init/init.py @@ -124,6 +124,7 @@ please execute the follow commands next self.oebuild_dir = self.create_oebuild_directory(directory) self.copy_config_file(self.oebuild_dir) + self.copy_compile_file(self.oebuild_dir) self.src_dir = self.create_src_directory(directory) return True @@ -163,14 +164,14 @@ please execute the follow commands next shutil.copyfile(config, os.path.join(updir, CONFIG)) except FileNotFoundError: logger.error("mkdir config faild") - + @staticmethod def copy_compile_file(updir : str): ''' copy oebuild compile.yaml.sample to some directory ''' try: - compile = oebuild_util.get_compile_yaml_dir() - shutil.copyfile(compile, os.path.join(updir, COMPILE_YAML)) + compil = oebuild_util.get_compile_yaml_dir() + shutil.copyfile(compil, os.path.join(updir, COMPILE_YAML)) except FileNotFoundError: logger.error("mkdir compile.yaml.sample faild") -- Gitee