From a0a656728438f4fc65d94fe8be353de5ecb2badd Mon Sep 17 00:00:00 2001 From: xuansen fang Date: Thu, 21 Mar 2024 20:24:40 +0800 Subject: [PATCH] add build.py --- src/oebuild/app/build.py | 117 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 src/oebuild/app/build.py diff --git a/src/oebuild/app/build.py b/src/oebuild/app/build.py new file mode 100644 index 0000000..f808977 --- /dev/null +++ b/src/oebuild/app/build.py @@ -0,0 +1,117 @@ +''' +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 pathlib + +import oebuild.util as oebuild_util +from oebuild.command import OebuildCommand +from oebuild.app.main import OebuildApp + + +class QuickBuild(OebuildCommand): + ''' + The build command will quickly generate the compile.yaml + ''' + + def __init__(self): + + super().__init__( + 'build', 'Build the compile.yaml with one click', + textwrap.dedent(''' + The build command will implement the process of init update generate + ''')) + + def do_add_parser(self, parser_adder): + parser = self._parser(parser_adder, usage=''' %(prog)s build''') + + return parser + + def do_run(self, args: argparse.Namespace, unknown=None): + ''' + build action rely on the module of init update generate + ''' + + self.get_app() + self.load_command_date() + self.do_init() + self.do_update() + self.do_generate() + + def get_app(self, ): + self.app = OebuildApp() + self.app._load_extension_specs() + self.app._setup_parsers() + + def load_command_date(self, ): + common_path = pathlib.Path(oebuild_util.get_base_oebuild(), 'app/conf', + 'build.yaml') + + try: + data = oebuild_util.read_yaml(yaml_dir=common_path) + self.init_command = None if 'init' not in data else data["init"] + self.update_command = None if 'update' not in data else data[ + "update"] + self.generate_command = None if 'generate' not in data else data[ + "generate"] + + except Exception as e_p: + raise e_p + + def do_init(self, ): + directory = None if 'directory' not in self.init_command else self.init_command[ + "directory"] + url = None if 'url' not in self.init_command else self.init_command[ + "url"] + branch = None if 'branch' not in self.init_command else self.init_command[ + "branch"] + + argv = [ + 'init', + ] + if directory: + argv.append(directory) + + if url: + argv.append('-u') + argv.append(url) + + if branch: + argv.append('-b') + argv.append(branch) + + self.app.run_command(argv=argv) + + def do_update(self, ): + # layer = None if 'layer' not in self.update_command else self.update_command[ + # "layer"] + # tag = None if 'tag' not in self.update_command else self.update_command[ + # "tag"] + + argv = [ + 'update', + ] + + self.app.run_command(argv=argv) + + def do_generate(self, ): + # platform = None if 'platform' not in self.generate_command else self.generate_command[ + # "platform"] + # features = None if 'features' not in self.generate_command else self.generate_command[ + # "features"] + + argv = [ + 'generate', + ] + + self.app.run_command(argv=argv) -- Gitee