Exemplo n.º 1
0
def load_settings(settings=None):
    if settings is None:
        settings = default_settings

    global g_setting
    g_setting = {}

    for setting in settings:
        with open(setting["path"], "r", encoding="utf-8") as setting_file:
            try:
                g_setting[setting["name"]] = yaml.load(setting_file,
                                                       Loader=yaml.FullLoader)
            except Exception as error:
                notify_error(
                    logger,
                    "配置表={}的格式有问题,具体问题请看下面的报错中的line $行数$ column $列数$来定位\n错误信息:{}\n"
                    .format(setting["name"], error))
                exit(0)

    ok, msg = check_settings(g_setting)
    if not ok:
        notify_error(logger, "配置表填写有误:\n{}".format(msg))
        exit(0)

    logger.info("setting loaded")
    logger.debug("setting={}".format(g_setting))
Exemplo n.º 2
0
def report_bugsnag_in_worker(current_process,
                             error,
                             processed_count,
                             args,
                             show_error_messagebox=True):
    traceback_info = traceback.format_exc()

    # 打印错误日志
    logger.info(
        "work thread {} unhandled exception={} when processing {}th work\nargs={}\n{}"
        .format(current_process, error, processed_count, args, traceback_info))

    # 弹出错误框
    if show_error_messagebox:
        notify_error(
            logger, "工作线程{}在处理第{}个计算项的搜索搭配过程中出现了未处理的异常\n{}".format(
                current_process, processed_count, traceback_info))

    # 上报bugsnag
    cpu_name, physical_cpu_cores, manufacturer = get_hardward_info()
    meta_data = {
        "worker_task_info": {
            "args": args,
        },
        "stacktrace_brief": {
            "info": traceback_info,
        },
        "config": config(),
        "settings": all_settings(),
        "app": {
            "releaseStage": RUN_ENV,
            "version": now_version,
            "release_time": ver_time,
        },
        "device": {
            "uuid": uuid.getnode(),
            "node": platform.node(),
            "osName": platform.system(),
            "osVersion": platform.version(),
            "release": platform.release(),
            "architecture": platform.machine(),
            "processor": platform.processor(),
            "logical_cpu_num": multiprocessing.cpu_count(),
            "physical_cpu_num": physical_cpu_cores,
            "cpu_name": cpu_name,
            "manufacturer": manufacturer,
            "time": time.strftime("%Y-%m-%d %H:%M:%S"),
            "timezone": time.strftime("%z", time.gmtime()),
        },
    }
    bugsnag.notify(
        exception=error,
        context="worker",
        meta_data=meta_data,
        user={
            "id": platform.node(),
            "uuid": uuid.getnode(),
        },
    )
Exemplo n.º 3
0
def load_config(config_path="config.toml"):
    global g_config
    try:
        raw_config = toml.load(config_path)
        g_config.auto_update_config(raw_config)
    except FileNotFoundError as error:
        notify_error(
            logger,
            "读取{}文件出错,是否直接在压缩包中打开了?\n具体出错为:".format(config_path, error))
        exit(-1)
Exemplo n.º 4
0
def load_config(config_path="config.toml"):
    global g_config
    try:
        raw_config = toml.load(config_path)
        g_config.auto_update_config(raw_config)
    except UnicodeDecodeError as error:
        notify_error(logger, "{}的编码格式有问题,应为utf-8,如果使用系统自带记事本的话,请下载vscode或notepad++等文本编辑器\n错误信息:{}\n".format(config_path, error))
        sys.exit(0)
    except Exception as error:
        notify_error(logger, "读取{}文件出错,是否直接在压缩包中打开了?\n具体出错为:".format(config_path, error))
        sys.exit(-1)
Exemplo n.º 5
0
def load_config(config_path="config.toml"):
    global g_config
    try:
        raw_config = toml.load(config_path)
        g_config.auto_update_config(raw_config)

        # 由于新版本调整了ui布局的实现方式,因此必须要有默认布局,避免使用旧版本配置文件的时候启动不了
        if len(g_config.ui.layout.equip_block_infos) == 0:
            g_config.ui.layout.use_default_equip_block_infos()
    except UnicodeDecodeError as error:
        notify_error(
            logger,
            "{}的编码格式有问题,应为utf-8,如果使用系统自带记事本的话,请下载vscode或notepad++等文本编辑器\n错误信息:{}\n"
            .format(config_path, error))
        sys.exit(0)
    except Exception as error:
        if encoding_error_str in str(error):
            notify_error(
                logger,
                "{}的编码格式有问题,应为utf-8,如果使用系统自带记事本的话,请下载vscode或notepad++等文本编辑器\n错误信息:{}\n"
                .format(config_path, error))
            sys.exit(0)

        notify_error(
            logger,
            "读取{}文件出错,是否直接在压缩包中打开了?\n具体出错为:{}".format(config_path, error))
        sys.exit(-1)
Exemplo n.º 6
0
def load_settings(settings=None):
    if settings is None:
        settings = default_settings

    global g_setting
    g_setting = {}

    for setting in settings:
        try:
            with open(setting["path"], "r", encoding="utf-8") as setting_file:
                g_setting[setting["name"]] = yaml.load(setting_file,
                                                       Loader=yaml.FullLoader)
        except FileNotFoundError as error:
            notify_error(
                logger, "没找到配置表={},你是否直接在压缩包中打开了?\n错误信息:{}\n".format(
                    setting["name"], error))
            sys.exit(0)
        except UnicodeDecodeError as error:
            notify_error(
                logger,
                "配置表={}的编码格式有问题,应为utf-8,如果使用系统自带记事本的话,请下载vscode或notepad++等文本编辑器\n错误信息:{}\n"
                .format(setting["name"], error))
            sys.exit(0)
        except Exception as error:
            notify_error(
                logger,
                "配置表={}的格式有问题,具体问题请看下面的报错中的line $行数$ column $列数$来定位\n错误信息:{}\n"
                .format(setting["name"], error))
            sys.exit(0)

    ok, msg = check_settings(g_setting)
    if not ok:
        notify_error(logger, "配置表填写有误:\n{}".format(msg))
        sys.exit(0)

    if multiprocessing.current_process().name == "MainProcess":
        logger.info("setting loaded")
        logger.debug("setting={}".format(g_setting))