From d3cf9cd47fd6a1e991061ecd9998c956f5db7064 Mon Sep 17 00:00:00 2001 From: xuhe Date: Tue, 10 Dec 2024 16:11:40 +0800 Subject: [PATCH] Optimize argparse and change structure for further ana function --- common/tool_cmd.py | 5 +++- extuner.py | 74 +++++++++++++++++++++++++++++----------------- main.py | 9 +++--- 3 files changed, 55 insertions(+), 33 deletions(-) diff --git a/common/tool_cmd.py b/common/tool_cmd.py index 9bfe41b..791e1ba 100644 --- a/common/tool_cmd.py +++ b/common/tool_cmd.py @@ -99,9 +99,10 @@ class ToolCmd: def args_help(self): usage_msg = 'extuner [options]\n' + usage_msg += ' --version Get current version\n' usage_msg += ' --work_path Extuner working path\n' usage_msg += ' --inst_path Extuner installed path\n' - usage_msg += ' --inst_path Output file path, including data, log and report\n' + usage_msg += ' --out_path Output file path, including data, log and report\n' usage_msg += ' --func Running function:\n' usage_msg += ' col collect system info\n' usage_msg += ' ana analyze system info\n' @@ -109,6 +110,8 @@ class ToolCmd: # parrent parent_parser = argparse.ArgumentParser(usage = usage_msg) + parent_parser.add_argument('-v', '--version' , action = 'version', version = self.__get_version(), + help = 'Get current version') parent_parser.add_argument('--work_path' , type = str, default = '.', help = 'Work path for extuner') parent_parser.add_argument('--inst_path' , type = str, default = '.', diff --git a/extuner.py b/extuner.py index 2f900ce..53a59f0 100644 --- a/extuner.py +++ b/extuner.py @@ -13,39 +13,59 @@ import time # if __name__=='__main__': def main(): - Timer = { "start": "", "stop": "" } - ret = False args = ToolCmd().args_help() - func = args.func - - - if args.work_path == '': - work_path = '/usr/share/extuner/' - else: - work_path = args.work_path - - if args.inst_path == '': - inst_path = '/usr/share/extuner/' - else: - inst_path = args.inst_path - - out_path = args.out_path + func = args.func + + work_path = args.work_path + inst_path = args.inst_path + out_path = args.out_path - SummaryInfo.init(out_path,work_path, inst_path) + SummaryInfo.init(out_path, work_path, inst_path) Logger().info("Extuner 开始执行") - Timer["start"] = time.strftime("%Y-%m-%d %H:%M:%S") - + if 'col' == func: - #get 功能 - ret = SummaryInfo.get_info() - - if ThreadPool().is_thread_working: + func_col() + elif 'ana' == func: + func_ana() + + + Logger().info("Extuner 执行成功") + + +def func_col(): + timer = { "start": "", "stop": "" } + + timer["start"] = time.strftime("%Y-%m-%d %H:%M:%S") + + ret = SummaryInfo.get_info() + + if ThreadPool().is_thread_working(): ThreadPool().thread_finish() + timer["stop"] = time.strftime("%Y-%m-%d %H:%M:%S") + + if ret: + KyReport().ky_build(timer) + + return ret + +def func_ana(): + timer = { "start": "", "stop": "" } - Timer["stop"] = time.strftime("%Y-%m-%d %H:%M:%S") + timer["start"] = time.strftime("%Y-%m-%d %H:%M:%S") - KyReport().ky_build(Timer) + ret = SummaryInfo.get_info() - Logger().info("Extuner 执行成功") - # Logger().info("结果输出目录为 : {}".format(Config.path_format(os.path.abspath(Config.get_output_path())))) \ No newline at end of file + if ThreadPool().is_thread_working(): + ThreadPool().thread_finish() + + # analyze功能 + #get_global_indicators() + #decide_global_indicators() + + timer["stop"] = time.strftime("%Y-%m-%d %H:%M:%S") + + if ret: + KyReport().ky_build(timer) + + return ret diff --git a/main.py b/main.py index f3f490b..5a39a4c 100644 --- a/main.py +++ b/main.py @@ -7,8 +7,7 @@ from common.log import Logger # main function if __name__=='__main__': - main() - # try: - # main() - # except Exception as err: - # Logger().error("Error: {}".format(err)) \ No newline at end of file + try: + main() + except Exception as err: + Logger().error("Error: {}".format(err)) -- Gitee