Update: Refactor to absolute imports, fix QPS limits, and enhance Gitea sync with SQLite support

This commit is contained in:
2026-07-21 10:25:29 +08:00
parent ef04fc5627
commit 97d9d98b4c
67 changed files with 1691 additions and 457 deletions
+98 -121
View File
@@ -40,63 +40,43 @@ added_files = [
('config/barcode_mappings.json', 'config/'),
('config/config.ini', 'config/'),
('templates/银豹-采购单模板.xls', 'templates/'),
('app', 'app'),
]
# 需要隐式导入的模块
hidden_imports = [
'tkinter',
'tkinter.ttk',
'tkinter.filedialog',
'tkinter.messagebox',
'tkinter.scrolledtext',
'pandas',
'numpy',
'openpyxl',
'xlrd',
'xlwt',
'xlutils',
'requests',
'dotenv',
'tkinterdnd2',
'configparser',
'threading',
'datetime',
'json',
're',
'subprocess',
'shutil',
'app.config.settings',
'app.services.ocr_service',
'app.services.order_service',
'app.services.tobacco_service',
'app.services.processor_service',
'app.core.utils.dialog_utils',
'app.core.utils.file_utils',
'app.core.utils.log_utils',
'app.core.utils.string_utils',
'app.core.handlers.column_mapper',
'app.core.excel.converter',
'app.core.db.product_db',
'app.ui.error_utils',
'app.ui.theme',
'app.ui.logging_ui',
'app.ui.ui_widgets',
'app.ui.user_settings',
'app.ui.result_previews',
'app.ui.command_runner',
'app.ui.file_operations',
'app.ui.action_handlers',
'app.ui.barcode_editor',
'app.ui.config_dialog',
'app.ui.shortcuts',
'app.ui.main_window',
'app.ui.memory_editor',
]
'tkinter',
'tkinter.ttk',
'tkinter.filedialog',
'tkinter.messagebox',
'tkinter.scrolledtext',
'pandas',
'numpy',
'openpyxl',
'xlrd',
'xlwt',
'xlutils',
'xlutils.copy',
'requests',
'dotenv',
'tkinterdnd2',
'configparser',
'threading',
'datetime',
'json',
're',
'subprocess',
'shutil',
'sqlite3',
'logging',
'base64',
'concurrent.futures',
'pathlib',
'typing',
]
a = Analysis(
['启动器.py'],
pathex=[],
pathex=['.'],
binaries=[],
datas=added_files,
hiddenimports=hidden_imports,
@@ -217,107 +197,104 @@ def build_exe():
return True
def create_portable_package():
"""创建便携版打包"""
print("创建便携版打包...")
"""创建并更新便携版打包,并同步到桌面"""
print("更新便携版打包...")
# 创建发布目录
# 1. 准备本地 release 目录
release_dir = Path('release')
if release_dir.exists():
try:
shutil.rmtree(release_dir)
except Exception as e:
print(f"警告: 无法完全清理发布目录 (可能文件被占用): {e}")
# 如果目录还在,尝试清理能清理的部分
for item in release_dir.iterdir():
try:
if item.is_dir(): shutil.rmtree(item)
else: item.unlink()
except Exception: pass
release_dir.mkdir(exist_ok=True)
# 不再删除整个目录,以保留 data/input 等用户数据
if not release_dir.exists():
release_dir.mkdir(parents=True)
print(f"已创建本地发布目录: {release_dir}")
else:
print(f"本地发布目录已存在,将进行增量更新: {release_dir}")
# 2. 更新核心文件到本地 release
# 复制exe文件
exe_file = Path('dist/OCR订单处理系统.exe')
if exe_file.exists():
shutil.copy2(exe_file, release_dir)
print(f"复制: {exe_file} -> {release_dir}")
print(f"更新 EXE: {exe_file} -> {release_dir}")
# 创建必要的目录结构
dirs_to_create = ['data/input', 'data/output', 'logs', 'templates', 'config']
for dir_path in dirs_to_create:
# 确保必要的目录存在
dirs_to_ensure = ['data/input', 'data/output', 'data/result', 'logs', 'templates', 'config']
for dir_path in dirs_to_ensure:
(release_dir / dir_path).mkdir(parents=True, exist_ok=True)
print(f"已创建目录: {dir_path}")
# 复制配置文件(包含API密钥)
config_file = Path('config/config.ini')
if config_file.exists():
shutil.copy2(config_file, release_dir / 'config')
print(f"已复制配置文件: {config_file} -> {release_dir / 'config'}")
else:
print(f"警告: 配置文件不存在: {config_file}")
# 复制配置文件
files_to_copy = [
(Path('config/config.ini'), release_dir / 'config'),
(Path('config/barcode_mappings.json'), release_dir / 'config'),
(Path('config.ini'), release_dir),
(Path('templates/银豹-采购单模板.xls'), release_dir / 'templates'),
(Path('templates/商品资料.xlsx'), release_dir / 'templates'),
]
# 复制完整的条码映射文件
barcode_mapping_file = Path('config/barcode_mappings.json')
if barcode_mapping_file.exists():
shutil.copy2(barcode_mapping_file, release_dir / 'config')
print(f"复制条码映射文件: {barcode_mapping_file} -> {release_dir / 'config'}")
else:
print(f"警告: 条码映射文件不存在: {barcode_mapping_file}")
# 复制根目录的config.ini文件
root_config_file = Path('config.ini')
if root_config_file.exists():
shutil.copy2(root_config_file, release_dir)
print(f"已复制根配置文件: {root_config_file} -> {release_dir}")
else:
print(f"警告: 根配置文件不存在: {root_config_file}")
# 复制模板文件
template_file = Path('templates/银豹-采购单模板.xls')
if template_file.exists():
shutil.copy2(template_file, release_dir / 'templates')
print(f"已复制模板文件: {template_file} -> {release_dir / 'templates'}")
else:
print(f"警告: 模板文件不存在: {template_file}")
item_file = Path('templates/商品资料.xlsx')
if item_file.exists():
try:
(Path('dist') / 'templates').mkdir(exist_ok=True)
shutil.copy2(item_file, Path('dist') / 'templates')
except Exception:
pass
shutil.copy2(item_file, release_dir / 'templates')
print(f"已复制商品资料: {item_file} -> {release_dir / 'templates'}")
else:
print(f"警告: 商品资料文件不存在: {item_file}")
# 创建README文件
for src, dst_dir in files_to_copy:
if src.exists():
dst_dir.mkdir(parents=True, exist_ok=True)
shutil.copy2(src, dst_dir)
print(f"更新文件: {src} -> {dst_dir}")
else:
print(f"警告: 文件不存在,跳过更新: {src}")
# 3. 创建/更新 README
readme_content = '''
# OCR订单处理系统 - 便携版
## 使用说明
1. 双击 "OCR订单处理系统.exe" 启动程序
2. 将需要处理的图片文件放入 data/input 目录
3. 处理结果将保存在 data/output 目录
4. 日志文件保存在 logs 目录
3. 处理结果将保存在 data/result 目录 (采购单 Excel)
4. 中间过程文件在 data/output 目录
5. 日志文件保存在 logs 目录
## 注意事项
- 首次运行时需要配置百度OCR API密钥
- 支持的图片格式:jpg, jpeg, png, bmp
- 单个文件大小不超过4MB
- 单个文件大小建议不超过 4MB
## 目录结构
- OCR订单处理系统.exe - 主程序
- data/input/ - 输入图片目录
- data/output/ - 输出结果目录
- data/result/ - 最终采购单目录
- logs/ - 日志目录
'''
with open(release_dir / 'README.txt', 'w', encoding='utf-8') as f:
f.write(readme_content)
print("已创建README.txt")
# 4. 同步到桌面
try:
# 用户指定的特殊桌面路径
desktop_path = Path(r"F:\Administrator\桌面")
if not desktop_path.exists():
# 兜底:如果 F 盘路径不存在,尝试系统默认路径
desktop_path = Path(os.path.join(os.path.expanduser("~"), "Desktop"))
desktop_release = desktop_path / "OCR系统_Release"
print(f"正在同步到桌面: {desktop_release}")
# 使用自定义的同步逻辑,避免删除目标目录中的其他文件
def sync_dir(src_root, dst_root):
if not dst_root.exists():
dst_root.mkdir(parents=True)
for item in src_root.iterdir():
dst_item = dst_root / item.name
if item.is_dir():
sync_dir(item, dst_item)
else:
# 如果是文件,直接覆盖更新
shutil.copy2(item, dst_item)
sync_dir(release_dir, desktop_release)
print(f"同步成功!桌面位置: {desktop_release.absolute()}")
except Exception as e:
print(f"同步到桌面失败: {e}")
print(f"便携版打包完成,位置: {release_dir.absolute()}")
print(f"本地便携版更新完成,位置: {release_dir.absolute()}")
def main():
"""主函数"""