From 347ed74015b903f0b4333c6c580f3aa86f1679d9 Mon Sep 17 00:00:00 2001 From: zhanghan2021 Date: Fri, 17 Nov 2023 09:30:22 +0800 Subject: [PATCH] init config file and set log output --- common/config.py | 38 ++++++++++++++++++++++++++++++++++++++ summary_info.py | 18 ++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 common/config.py create mode 100644 summary_info.py diff --git a/common/config.py b/common/config.py new file mode 100644 index 0000000..ff6dc66 --- /dev/null +++ b/common/config.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python +# -*- coding: UTF-8 -*- +# cython:language_level=3 + +import io +import json5 +import os +import sys +import time + +# Initialize classes, load working directory and output directory, etc. +class Config: + @staticmethod + def init_config(opath, wpath , ipath ): + ''' + Initialize working directory information, must be called + ''' + Config.set_work_path(wpath) + Config.set_inst_path(ipath) + Config.set_out_path(opath) + + try: + with io.open(Config.conf_fn, 'r', encoding='utf-8') as file: + Config.dict_json = json5.load(file) + except Exception as err: + print("程序初始化失败: 配置文件内容设置异常 {},请修改后重新启动程序。".format(err)) + sys.exit() + + if not os.path.exists('{}/output-{}/'.format(Config.out_path, Config.dt)): + os.makedirs('{}/output-{}/'.format(Config.out_path, Config.dt)) + + if not os.path.exists(Config.out_path + '/log/'): + os.makedirs(Config.out_path + '/log/') + + # if not os.path.exists(Config.out_path+'/temp/'): + # os.makedirs(Config.out_path + '/temp/') + + \ No newline at end of file diff --git a/summary_info.py b/summary_info.py new file mode 100644 index 0000000..d64395e --- /dev/null +++ b/summary_info.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python +# -*- coding: UTF-8 -*- +# cython:language_level=3 + + +from common.config import Config + + +# Access to information for external use +class SummaryInfo: + @staticmethod + def init(out_path , work_path , inst_path ): + ''' + initialization, must be called first + ''' + Config.init_config(out_path, work_path, inst_path) + # Specify debug mode + # Logger().on_debug_type() -- Gitee