1 Star 0 Fork 0

yypqc/Email

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.py 2.74 KB
一键复制 编辑 原始数据 按行查看 历史
yyp 提交于 2024-11-07 13:15 . fix
# -*- coding: utf-8 -*-
"""
@Tool : PyCharm
@User : 21407
@File : main.py
@Email: yypqcaa@163.com
@Date : 2023/2/26 21:47
@Desc :
"""
import sys
import shutil
import psutil
import traceback
from pathlib import Path
from loguru import logger
from PyQt5 import QtWidgets, QtCore
from PyQt5.QtWidgets import QApplication
from ui.main_ui import MainUi
def handleException(exc_type, exc_value, exc_traceback):
if issubclass(exc_type, KeyboardInterrupt):
return sys.__excepthook__(exc_type, exc_value, exc_traceback)
exception = str("".join(traceback.format_exception(exc_type, exc_value, exc_traceback)))
dialog = QtWidgets.QDialog()
# close对其进行删除操作
dialog.setAttribute(QtCore.Qt.WA_DeleteOnClose)
msg = QtWidgets.QMessageBox(dialog)
msg.setIcon(QtWidgets.QMessageBox.Critical)
msg.setText(exception)
msg.setWindowTitle("系统异常提示")
msg.setDetailedText(exception)
msg.setStandardButtons(QtWidgets.QMessageBox.Ok)
msg.exec_()
class MyTool:
def __init__(self):
from constant import LOG_PATH, EMAIL_CHECK_PATH, EMAIL_SEARCH_PATH, EXE_NAME, DRIVER_PATH, DATA_PATH, \
CONFIG_DEST_PATH, CONFIG_SOURCE_PATH, TEMPLATE_PATH, STATIC_PATH, EMAIL_SHOP_PATH, EMAIL_CNH_PATH
self.close_program(EXE_NAME)
for str_path in [LOG_PATH, EMAIL_CHECK_PATH, EMAIL_SEARCH_PATH, DATA_PATH, DRIVER_PATH,
CONFIG_DEST_PATH, TEMPLATE_PATH, EMAIL_SHOP_PATH, EMAIL_CNH_PATH]:
if not Path(str_path).is_dir():
Path(str_path).mkdir(exist_ok=True)
# 复制配置文件
for str_file in ['config.json', 'email.json']:
if not Path(CONFIG_DEST_PATH, str_file).exists():
shutil.copy(Path(CONFIG_SOURCE_PATH, str_file).__str__(), Path(CONFIG_DEST_PATH, str_file).__str__())
# 复制初始模板
if not Path(TEMPLATE_PATH, 'templates.html').exists():
shutil.copy(Path(STATIC_PATH, 'template', 'templates.html').__str__(),
Path(TEMPLATE_PATH, 'templates.html').__str__())
logger.add(Path(LOG_PATH).joinpath("log.log").__str__(), rotation="500MB", encoding="utf-8", enqueue=True, retention="10 days")
# 自定义异常
sys.excepthook = handleException
@staticmethod
def close_program(exec_name: str):
"""关闭软件"""
try:
lst_ps = [proc.name() for proc in psutil.process_iter() if proc.name() == exec_name]
if len(lst_ps) > 2:
sys.exit(0)
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
sys.exit(0)
if __name__ == '__main__':
obj_init = MyTool()
app = QApplication([])
obj_a = MainUi()
sys.exit(app.exec_())
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/yypqc/email.git
git@gitee.com:yypqc/email.git
yypqc
email
Email
master

搜索帮助