Files
37duAutomation/plugins/XQ0001-0100/XQ0082 通联数据核对/config/__init__.py
T

73 lines
1.6 KiB
Python

# -*- coding: utf-8 -*-
"""xq0082 通联数据核对 —— 配置常量与全局钩子。
从 XQ0085 拆出的独立插件:只做通联扫码统计表的每日流程,不涉及共享盘,也不做对比表。
只依赖标准库 / 第三方库 / 底座注入的 RunContext。
"""
import os
import time
# ==================== 全局钩子(run() 启动时注入) ====================
_log = None
_progress = None
_debug = False
def set_log(fn):
global _log
_log = fn
def set_progress(fn):
global _progress
_progress = fn
def set_debug(on):
global _debug
_debug = bool(on)
def debug_enabled():
return _debug
def log(msg, level='INFO'):
text = f'[{time.strftime("%H:%M:%S")}] {msg}'
if level == 'DEBUG' and not _debug:
return
if _log:
_log(str(msg), level)
else:
print(f'[{level}] {text}')
def progress(pct):
if _progress:
try:
_progress(int(pct))
except Exception:
pass
# ==================== 工作目录 ====================
# 界面「本地工作目录」= 放扫码统计工作簿与各类导出件的目录,留空用默认。
DEFAULT_DIR = r'D:\资料\财务\团购数据核对\通联'
OUT_DIR = DEFAULT_DIR
def set_out_dir(path=None):
"""界面填的目录优先,留空回默认;返回最终目录。"""
global OUT_DIR
OUT_DIR = str(path or '').strip().strip('"').strip() or DEFAULT_DIR
return OUT_DIR
def ensure_dirs():
os.makedirs(OUT_DIR, exist_ok=True)
return OUT_DIR
# ==================== 运行参数 ====================
RETRY_MAX = 3