diff --git a/build.sh b/build.sh index 64dc01d325b02308cbdd4a034db48d193ecf3141..96790801bbde729300e7c937a6839e13cb69a9d4 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 0000000000000000000000000000000000000000..6d62b97e635146b58c18561dbe580822a59ff7d9 --- /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 0000000000000000000000000000000000000000..840d428e2942ca7337af2890039cabc750503674 --- /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 0000000000000000000000000000000000000000..712b07fcb22e11cff43318f2a3fa89f96af2d56c --- /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 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tools/install_dependency/src/handler/pipeline.py b/tools/install_dependency/src/handler/pipeline.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tools/install_dependency/src/log.py b/tools/install_dependency/src/log.py new file mode 100644 index 0000000000000000000000000000000000000000..1f1fe3dca78e56e6dca38a082f1eb63b3a850e05 --- /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 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391