From bcce250c31bfd772cd2403d8a89c5346f52fa9df Mon Sep 17 00:00:00 2001 From: cc <18856836718@163.com> Date: Fri, 23 Feb 2024 10:18:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E6=AC=A1=E6=8F=90=E4=BA=A4=20install?= =?UTF-8?q?=5Fdependency=20=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.sh | 12 +++++++ .../src/download.py | 0 .../src/download_config.py | 0 .../config/machine.yaml | 0 tools/install_dependency/src/command_line.py | 30 ++++++++++++++++ tools/install_dependency/src/constant.py | 9 +++++ .../install_dependency/src/devkitpipeline.py | 36 +++++++++++++++++++ .../src/exception/__init__.py} | 0 .../src/handler/__init__.py | 0 .../src/handler/pipeline.py | 0 tools/install_dependency/src/log.py | 18 ++++++++++ .../src/machine/__init__.py | 0 12 files changed, 105 insertions(+) rename tools/{download_dependence => download_dependency}/src/download.py (100%) rename tools/{download_dependence => download_dependency}/src/download_config.py (100%) rename tools/{install_dependence => install_dependency}/config/machine.yaml (100%) create mode 100644 tools/install_dependency/src/command_line.py create mode 100644 tools/install_dependency/src/constant.py create mode 100644 tools/install_dependency/src/devkitpipeline.py rename tools/{install_dependence/src/devkitpipeline.py => install_dependency/src/exception/__init__.py} (100%) create mode 100644 tools/install_dependency/src/handler/__init__.py create mode 100644 tools/install_dependency/src/handler/pipeline.py create mode 100644 tools/install_dependency/src/log.py create mode 100644 tools/install_dependency/src/machine/__init__.py diff --git a/build.sh b/build.sh index 64dc01d..9679080 100644 --- a/build.sh +++ b/build.sh @@ -1,3 +1,15 @@ #!/bin/bash # SourceCode build script # Copyright: Copyright (c) Huawei Technologies Co., Ltd. All rights reserved. + +set -e +current_dir=$(cd $(dirname $0); pwd) + +cd $current_dir +cp $current_dir/tools/download_dependency/src/* $current_dir/tools/install_dependency/src/ + +cd $current_dir/tools/download_dependency +pyinstaller -F ./src/download.py -p ./ + +cd $current_dir/tools/install_dependency +pyinstaller -F ./src/devkitpipeline.py -p ./ diff --git a/tools/download_dependence/src/download.py b/tools/download_dependency/src/download.py similarity index 100% rename from tools/download_dependence/src/download.py rename to tools/download_dependency/src/download.py diff --git a/tools/download_dependence/src/download_config.py b/tools/download_dependency/src/download_config.py similarity index 100% rename from tools/download_dependence/src/download_config.py rename to tools/download_dependency/src/download_config.py diff --git a/tools/install_dependence/config/machine.yaml b/tools/install_dependency/config/machine.yaml similarity index 100% rename from tools/install_dependence/config/machine.yaml rename to tools/install_dependency/config/machine.yaml diff --git a/tools/install_dependency/src/command_line.py b/tools/install_dependency/src/command_line.py new file mode 100644 index 0000000..6d62b97 --- /dev/null +++ b/tools/install_dependency/src/command_line.py @@ -0,0 +1,30 @@ +import argparse + +DEFAULT_YAML_PATH = './machine.yaml' + + +class CommandLine: + yaml_path = DEFAULT_YAML_PATH + debug = False + + @classmethod + def add_option(cls, parser): + parser.add_argument("-f", "--config", action="store", dest="yaml_path", default=DEFAULT_YAML_PATH, + help="Assign yaml config file path.") + parser.add_argument("--debug", action="store_true", dest="debug", default=False, help="Open debug log.") + + @classmethod + def process_args(cls, args): + cls.yaml_path = args.yaml_path if args.yaml_path and args.yaml_path != "./" else DEFAULT_YAML_PATH + cls.debug = args.debug + return cls.yaml_path + + +def process_command_line(program, description, class_list): + parser = argparse.ArgumentParser(prog=program, description=description, add_help=True) + for klass in class_list: + klass.add_option(parser) + + args = parser.parse_args() + for klass in class_list: + klass.process_args(args) diff --git a/tools/install_dependency/src/constant.py b/tools/install_dependency/src/constant.py new file mode 100644 index 0000000..840d428 --- /dev/null +++ b/tools/install_dependency/src/constant.py @@ -0,0 +1,9 @@ +USER = "user" +PKEY = "pkey" +PASSWORD = "password" +SCANNER = "scanner" +BUILDER = "builder" +EXECUTOR = "executor" +MACHINE = "machine" +DEPENDENCE_FILE = "devkitdependencies.tar.gz" +DEPENDENCY_DIR = "devkitdependencies" \ No newline at end of file diff --git a/tools/install_dependency/src/devkitpipeline.py b/tools/install_dependency/src/devkitpipeline.py new file mode 100644 index 0000000..712b07f --- /dev/null +++ b/tools/install_dependency/src/devkitpipeline.py @@ -0,0 +1,36 @@ +import sys +import logging +import yaml + +from log import config_logging +from command_line import process_command_line, CommandLine + +LOGGER = logging.getLogger("install_dependency") + + +def read_yaml_file(yaml_path): + try: + with open(yaml_path, "r") as file: + config_dict = yaml.safe_load(file) + except (FileNotFoundError, IsADirectoryError) as e: + LOGGER.error(f"Yaml file is not in specified path. Error: {str(e)}") + sys.exit(1) + except (yaml.parser.ParserError, + yaml.scanner.ScannerError, + yaml.composer.ComposerError, + yaml.constructor.ConstructorError) as e: + LOGGER.error(f"Incorrect yaml file. Error: {str(e)}") + sys.exit(1) + return config_dict + + +if __name__ == '__main__': + try: + process_command_line(program="install_dependency", description="devkit-pipeline install_dependency tool", + class_list=[CommandLine]) + config_logging(CommandLine.debug) + config_dict = read_yaml_file(CommandLine.yaml_path) + LOGGER.debug(f"-- config_dict: {config_dict}") + + except (KeyboardInterrupt, Exception) as e: + print(f"[warning] Program Exited. {str(e)}") diff --git a/tools/install_dependence/src/devkitpipeline.py b/tools/install_dependency/src/exception/__init__.py similarity index 100% rename from tools/install_dependence/src/devkitpipeline.py rename to tools/install_dependency/src/exception/__init__.py diff --git a/tools/install_dependency/src/handler/__init__.py b/tools/install_dependency/src/handler/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tools/install_dependency/src/handler/pipeline.py b/tools/install_dependency/src/handler/pipeline.py new file mode 100644 index 0000000..e69de29 diff --git a/tools/install_dependency/src/log.py b/tools/install_dependency/src/log.py new file mode 100644 index 0000000..1f1fe3d --- /dev/null +++ b/tools/install_dependency/src/log.py @@ -0,0 +1,18 @@ +import logging +import sys + + +def config_logging(debug=False): + logger = logging.getLogger("install_dependency") + logger.setLevel(logging.DEBUG) + + formatter = logging.Formatter( + "[%(asctime)s] [%(levelname)s] [processID:%(process)d]" + " [%(threadName)s] [%(module)s:%(funcName)s:%(lineno)d]" + " %(message)s") + + handler = logging.StreamHandler(sys.stdout) + handler.setLevel(logging.DEBUG if debug else logging.INFO) + handler.setFormatter(formatter) + + logger.addHandler(handler) diff --git a/tools/install_dependency/src/machine/__init__.py b/tools/install_dependency/src/machine/__init__.py new file mode 100644 index 0000000..e69de29 -- Gitee