#!/usr/bin/env python # -*- coding: utf-8 -*- # Copyright (c) Huawei Technologies Co., Ltd. 2022-2023. All rights reserved. from common import consts, log_info, log_error, close_log from common import RetCode from common.task_common import create_out_timestamp_dir from common import compress_output_dir_tar from params import ParamDict from cmdline import CommandLineParser from config import AsysConfigParser from collect import AsysCollect from launch import AsysLaunch from info import AsysInfo from diagnose import AsysDiagnose from health import AsysHealth from analyze import AsysAnalyze __all__ = ["main"] def main(): """entrance of Ascend system advisor""" # 1. parse the command line and check args asys_parser = CommandLineParser() parse_ret = asys_parser.parse() if ParamDict().get_command() is None: if parse_ret == RetCode.SUCCESS: # -h, --help, and only asys asys_parser.print_help() return True else: log_error("arguments parse failed, asys exit.") return False # info/diagnose/health close info & warning level log if ParamDict().get_command() in [consts.info_cmd, consts.diagnose_cmd, consts.health_cmd]: close_log() env_ret = ParamDict().get_env_type() if env_ret == RetCode.FAILED: log_error("Failed to obtain the execution environment type.") return False # 2. read the config file and load configs conf_parser = AsysConfigParser() conf_res = conf_parser.parse() if not conf_res: log_error('configs parse failed, asys exit.') return False log_info("asys start.") if ParamDict().get_command() in [consts.collect_cmd, consts.launch_cmd] and \ create_out_timestamp_dir() != RetCode.SUCCESS: log_error("create asys output directory failed.") return False task_res = True # 3. execute the command if ParamDict().get_command() == consts.collect_cmd: asys_collector = AsysCollect() task_res = asys_collector.collect() asys_collector.clean_work() elif ParamDict().get_command() == consts.launch_cmd: asys_launcher = AsysLaunch() task_res = asys_launcher.launch() asys_launcher.clean_work() elif ParamDict().get_command() == consts.info_cmd: asys_info = AsysInfo() task_res = asys_info.run_info() elif ParamDict().get_command() == consts.diagnose_cmd: asys_diagnoser = AsysDiagnose() task_res = asys_diagnoser.diagnose() elif ParamDict().get_command() == consts.health_cmd: asys_health = AsysHealth() task_res = asys_health.health() elif ParamDict().get_command() == consts.analyze_cmd: asys_analyze = AsysAnalyze() task_res = asys_analyze.analyze() log_info("{0} task execute finish.".format(ParamDict().get_command())) # 4. Compress the output dir using tar. if ParamDict().get_arg("tar") in ["T", "TRUE"]: compress_output_dir_tar() log_info("asys finish.") return task_res if __name__ == "__main__": main()