建模程序 多个定时程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

57 lines
2.1 KiB

import sys
import os
import importlib
from utils.config import cfg, get_work_dir
def get_command_handler(command):
"""动态导入并返回命令处理函数"""
if command == 'batch_download':
module = importlib.import_module('download_batch_data.main_download_batch_data_and_trans')
return module.main
elif command == 'begin_sliceing':
module = importlib.import_module('auto_sliceing_operate.main_begin_sliceing')
return module.main
elif command == 'download_slice':
module = importlib.import_module('auto_sliceing_operate.main_download_zip')
return module.main
else:
return None
if __name__ == '__main__':
# 可用命令列表
available_commands = ['batch_download', 'begin_sliceing', 'download_slice']
# 检查参数数量
if len(sys.argv) < 2:
print('Usage: python main.py <command> [work_dir]')
print('可用命令:', ' | '.join(available_commands))
print('\n注意: work_dir 参数可选,如果未提供将从配置文件读取默认值')
sys.exit(1)
command = sys.argv[1]
# 检查命令是否存在
if command not in available_commands:
print(f'错误: 未知命令 "{command}"')
print('可用命令:', ' | '.join(available_commands))
sys.exit(1)
# 获取工作目录:优先使用命令行参数,其次使用配置文件,最后使用 None
work_dir = None
if len(sys.argv) > 2:
work_dir = sys.argv[2]
# 打印配置信息(可选,用于调试)
if cfg('log.level', 'INFO') == 'DEBUG':
print(f'配置信息:')
print(f' - API URL: {cfg("api.base_url", "未配置")}')
print(f' - Redis Host: {cfg("redis.host", "未配置")}')
print(f' - 工作目录: {work_dir if work_dir else "未指定(将使用默认值)"}')
# 动态导入并执行对应的处理函数
handler = get_command_handler(command)
if handler is None:
print(f'错误: 无法加载命令 "{command}" 的处理模块')
sys.exit(1)
handler(work_dir=work_dir)