From 4d19279f4c4b2a1781ad51e69cc1b3abe085fe4e Mon Sep 17 00:00:00 2001 From: "alichinese lixinyu44@huawei.com" Date: Sat, 28 Oct 2023 10:40:46 +0800 Subject: [PATCH 1/5] code: optimize some function * optimize some function help msg * alter generate command about datetime param, we use value that set Signed-off-by: alichinese --- src/oebuild/app/plugins/generate/generate.py | 28 ++++++++++---------- src/oebuild/app/plugins/init/init.py | 4 +-- src/oebuild/app/plugins/manifest/manifest.py | 1 + src/oebuild/app/plugins/update/update.py | 2 +- src/oebuild/oebuild_parser.py | 2 +- src/oebuild/parse_template.py | 7 +++-- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/oebuild/app/plugins/generate/generate.py b/src/oebuild/app/plugins/generate/generate.py index c3c3edb..9294282 100644 --- a/src/oebuild/app/plugins/generate/generate.py +++ b/src/oebuild/app/plugins/generate/generate.py @@ -58,37 +58,37 @@ class Generate(OebuildCommand): %(prog)s [-p platform] [-f features] [-t toolchain_dir] [-d build_directory] [-l list] [-b_in build_in] ''') - parser.add_argument('-l', 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', 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', dest='sstate_cache', + parser.add_argument('-s','--state_cache', dest='sstate_cache', help=''' this param is for SSTATE_MIRRORS ''' ) - parser.add_argument('-s_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', 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', dest='features', action='append', + parser.add_argument('-f', '--features', dest='features', action='append', help=''' this param is feature, it's a reuse command ''' @@ -100,33 +100,33 @@ class Generate(OebuildCommand): ''' ) - parser.add_argument('-d', 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', 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', 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', 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 = "is_datetime", action = "store_true", + parser.add_argument('-dt', '--datetime', dest = "datetime", help=''' - this param is add DATETIME to local.conf, the value is getting current time + this param is add DATETIME to local.conf, the value format is 20231212010101 ''') parser.add_argument('-df', @@ -137,7 +137,7 @@ class Generate(OebuildCommand): this param is set openeuler_fetch in local.conf, the default value is enable, if set -df, the OPENEULER_FETCH will set to 'disable' ''') - parser.add_argument('-b_in', dest='build_in', choices=[BUILD_IN_DOCKER, BUILD_IN_HOST], + parser.add_argument('-b_in', '--build_in', dest='build_in', choices=[BUILD_IN_DOCKER, BUILD_IN_HOST], default = BUILD_IN_DOCKER, help=''' This parameter marks the mode at build time, and is built in the container by docker ''' @@ -272,7 +272,7 @@ following container, enter it numerically, and enter q to exit:''') build_in=build_in, sstate_cache= self.sstate_cache, tmp_dir = self.tmp_dir, - is_datetime = args.is_datetime, + datetime = args.datetime, is_disable_fetch = args.is_disable_fetch, docker_image=docker_image )) diff --git a/src/oebuild/app/plugins/init/init.py b/src/oebuild/app/plugins/init/init.py index 602a629..5644e1d 100644 --- a/src/oebuild/app/plugins/init/init.py +++ b/src/oebuild/app/plugins/init/init.py @@ -59,10 +59,10 @@ class Init(OebuildCommand): %(prog)s [directory] [-u yocto_remote_url] [-b branch] ''') - parser_adder.add_argument('-u', dest = 'yocto_remote_url', + 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', dest = 'branch', + parser_adder.add_argument('-b', '--branch', dest = 'branch', help='''Specifies the branch of yocto-meta-openeuler''') parser_adder.add_argument( diff --git a/src/oebuild/app/plugins/manifest/manifest.py b/src/oebuild/app/plugins/manifest/manifest.py index f20b9e9..1eaca5e 100644 --- a/src/oebuild/app/plugins/manifest/manifest.py +++ b/src/oebuild/app/plugins/manifest/manifest.py @@ -74,6 +74,7 @@ class Manifest(OebuildCommand): ''') parser.add_argument('-m_dir', + '--manifest_dir', dest='manifest_dir', help=''' specify a manifest path to perform the create or restore operation diff --git a/src/oebuild/app/plugins/update/update.py b/src/oebuild/app/plugins/update/update.py index 84409a3..5a3c8bd 100644 --- a/src/oebuild/app/plugins/update/update.py +++ b/src/oebuild/app/plugins/update/update.py @@ -66,7 +66,7 @@ class Update(OebuildCommand): usage=''' %(prog)s [yocto docker layer] [-tag] ''') - parser.add_argument('-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 ''' diff --git a/src/oebuild/oebuild_parser.py b/src/oebuild/oebuild_parser.py index 055a5ff..5d43b89 100644 --- a/src/oebuild/oebuild_parser.py +++ b/src/oebuild/oebuild_parser.py @@ -111,7 +111,7 @@ class OebuildArgumentParser(argparse.ArgumentParser): self._format_thing_and_help(append, opt_str, help_msg, width) def _format_command(self, append, command, width): - thing = f' {command.name}:' + thing = f' {command.name}' self._format_thing_and_help(append, thing, command.help, width) def _format_thing_and_help(self, append, thing, help_msg: str, width): diff --git a/src/oebuild/parse_template.py b/src/oebuild/parse_template.py index e235457..6be388a 100644 --- a/src/oebuild/parse_template.py +++ b/src/oebuild/parse_template.py @@ -169,7 +169,7 @@ class ParseTemplate: build_in: str = BUILD_IN_DOCKER, sstate_cache = None, tmp_dir = None, - is_datetime = False, + datetime = None, is_disable_fetch = False, docker_image = ""): ''' @@ -230,9 +230,8 @@ class ParseTemplate: if feature.local_conf is not None: local_conf = LiteralScalarString(feature.local_conf + '\n' + local_conf) - if is_datetime: - now_time = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time())) - datetime_str = LiteralScalarString(f'DATETIME = "{now_time}"') + if datetime is not None: + datetime_str = LiteralScalarString(f'DATETIME = "{datetime}"') local_conf = LiteralScalarString(local_conf + '\n' + datetime_str) if is_disable_fetch: -- Gitee From 953ff7bd88dbc7b6041617f836817c4eab0f90bc Mon Sep 17 00:00:00 2001 From: "alichinese lixinyu44@huawei.com" Date: Sat, 28 Oct 2023 10:49:29 +0800 Subject: [PATCH 2/5] generate: fix get docker tag bug * when get docker_tag and docker_tag is float, it will be raise error because float has not strip attribute, so we translate docker_tag string force Signed-off-by: alichinese lixinyu44@huawei.com --- src/oebuild/app/plugins/generate/generate.py | 2 +- src/oebuild/parse_template.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/oebuild/app/plugins/generate/generate.py b/src/oebuild/app/plugins/generate/generate.py index 9294282..63db529 100644 --- a/src/oebuild/app/plugins/generate/generate.py +++ b/src/oebuild/app/plugins/generate/generate.py @@ -241,7 +241,7 @@ class Generate(OebuildCommand): check_docker_tag = CheckDockerTag(args.docker_tag, self.configure) oebuild_config = self.configure.parse_oebuild_config() if check_docker_tag.get_tag() is not None: - docker_tag = check_docker_tag.get_tag() + docker_tag = str(check_docker_tag.get_tag()) else: # select docker image while True: diff --git a/src/oebuild/parse_template.py b/src/oebuild/parse_template.py index 6be388a..4443d27 100644 --- a/src/oebuild/parse_template.py +++ b/src/oebuild/parse_template.py @@ -14,7 +14,6 @@ from dataclasses import dataclass from typing import Dict, Optional import pathlib import os -import time from ruamel.yaml.scalarstring import LiteralScalarString -- Gitee From f2dbc92014e2a791b72ff904363e7b55177f8a8a Mon Sep 17 00:00:00 2001 From: "alichinese lixinyu44@huawei.com" Date: Sat, 28 Oct 2023 14:21:54 +0800 Subject: [PATCH 3/5] code: fix docker exception bug * fix the bug that when run help in a environment who not install docker will raise docker exception Signed-off-by: alichinese lixinyu44@huawei.com --- src/oebuild/app/plugins/clear/clear.py | 12 +++++- src/oebuild/app/plugins/compile/compile.py | 42 ++++++++++---------- src/oebuild/app/plugins/qemu_run/qemu_run.py | 34 ++++++++-------- 3 files changed, 49 insertions(+), 39 deletions(-) diff --git a/src/oebuild/app/plugins/clear/clear.py b/src/oebuild/app/plugins/clear/clear.py index 8b6733c..91fd296 100644 --- a/src/oebuild/app/plugins/clear/clear.py +++ b/src/oebuild/app/plugins/clear/clear.py @@ -15,6 +15,8 @@ import textwrap import os import pathlib +from docker.errors import DockerException + from oebuild.command import OebuildCommand import oebuild.util as oebuild_util from oebuild.configure import Configure @@ -22,10 +24,13 @@ from oebuild.docker_proxy import DockerProxy from oebuild.m_log import logger class Clear(OebuildCommand): + ''' + for some clear task + ''' def __init__(self): self.configure = Configure() - self.client = DockerProxy() + self.client = None super().__init__( 'clear', 'clear someone which oebuild generate', @@ -58,6 +63,11 @@ class Clear(OebuildCommand): args = args.parse_args(unknown) if args.item == "docker": + try: + self.client = DockerProxy() + except DockerException: + logger.error("please install docker first!!!") + return self.clear_docker() def clear_docker(self,): diff --git a/src/oebuild/app/plugins/compile/compile.py b/src/oebuild/app/plugins/compile/compile.py index 655eda4..56d6e5c 100644 --- a/src/oebuild/app/plugins/compile/compile.py +++ b/src/oebuild/app/plugins/compile/compile.py @@ -13,32 +13,27 @@ See the Mulan PSL v2 for more details. import argparse import textwrap import os -import sys -import pathlib -from shutil import copyfile + +from docker.errors import DockerException from docker.models.containers import Container from oebuild.docker_proxy import DockerProxy from oebuild.command import OebuildCommand -import oebuild.util as oebuild_util -from oebuild.parse_compile import ParseCompile,CheckCompileError -from oebuild.configure import Configure, ConfigBasicRepo, YOCTO_META_OPENEULER -from oebuild.parse_template import BaseParseTemplate, ParseTemplate, BUILD_IN_DOCKER, BUILD_IN_HOST -from oebuild.m_log import logger, INFO_COLOR -from oebuild.check_docker_tag import CheckDockerTag - -''' -The command for cross-compile, configure runtime environment, run code and output results. -''' +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 = DockerProxy() + self.client = None self.container_id = None + self.dir_platform = None + self.chain_platform = None super().__init__( 'cross-compile', @@ -67,26 +62,33 @@ class Compile(OebuildCommand): 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" diff --git a/src/oebuild/app/plugins/qemu_run/qemu_run.py b/src/oebuild/app/plugins/qemu_run/qemu_run.py index 2860dd8..b7a8401 100644 --- a/src/oebuild/app/plugins/qemu_run/qemu_run.py +++ b/src/oebuild/app/plugins/qemu_run/qemu_run.py @@ -13,31 +13,24 @@ See the Mulan PSL v2 for more details. import argparse import textwrap import os -import sys -import pathlib -from shutil import copyfile + +from docker.errors import DockerException from docker.models.containers import Container from oebuild.docker_proxy import DockerProxy from oebuild.command import OebuildCommand -import oebuild.util as oebuild_util -from oebuild.parse_compile import ParseCompile,CheckCompileError -from oebuild.configure import Configure, ConfigBasicRepo, YOCTO_META_OPENEULER -from oebuild.parse_template import BaseParseTemplate, ParseTemplate, BUILD_IN_DOCKER, BUILD_IN_HOST -from oebuild.m_log import logger, INFO_COLOR -from oebuild.check_docker_tag import CheckDockerTag - -''' -The command for run executable file under qemu. -''' - -class Qemu_run(OebuildCommand): +from oebuild.configure import Configure +from oebuild.m_log import logger +class QemuRun(OebuildCommand): + ''' + The command for run executable file under qemu. + ''' def __init__(self): self.compile_conf_dir = os.path.join(os.getcwd(), 'compile.yaml') self.configure = Configure() - self.client = DockerProxy() + self.client = None self.container_id = None super().__init__( @@ -73,17 +66,22 @@ class Qemu_run(OebuildCommand): this param is for the mode for running qemu. All possible choices: user, system ''' ) - + return parser def do_run(self, args: argparse.Namespace, unknown=None): - # 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.target_directory) is None: logger.error('Please specify directory of the target file') self._check_file(args) -- Gitee From c61ec3d6724a4e3b6ed5179469d93368ccb52c30 Mon Sep 17 00:00:00 2001 From: "alichinese lixinyu44@huawei.com" Date: Sat, 28 Oct 2023 14:24:20 +0800 Subject: [PATCH 4/5] plugins: remove will not publish function * the compile and qemu_run function just not publish, so remove from plugins conf file Signed-off-by: alichinese --- src/oebuild/app/conf/plugins.yaml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/oebuild/app/conf/plugins.yaml b/src/oebuild/app/conf/plugins.yaml index 7aa6c42..2c62fd9 100644 --- a/src/oebuild/app/conf/plugins.yaml +++ b/src/oebuild/app/conf/plugins.yaml @@ -17,9 +17,3 @@ plugins: - name: clear class: Clear path: plugins/clear/clear.py -- name: compile - class: Compile - path: plugins/compile/compile.py -- name: qemu_run - class: Qemu_run - path: plugins/qemu_run/qemu_run.py -- Gitee From 0f176984fd5aebfcfb173a5295612e34bd1c36a6 Mon Sep 17 00:00:00 2001 From: "alichinese lixinyu44@huawei.com" Date: Sat, 28 Oct 2023 14:30:37 +0800 Subject: [PATCH 5/5] version: upgrade version to 0.0.31 * fix docker exception bug * optimize some help message Signed-off-by: alichinese --- 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 eae0a12..b05f40a 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.30' +__version__ = '0.0.31' -- Gitee