consolidator
/
main.py
45 строк · 1.9 Кб
1import sys
2import os
3from PySide6.QtWidgets import QApplication,QStyle
4from PySide6 import QtCore
5from ConsWindow import ConsWindow
6from MyLogger import MyLogger
7from MyConfig import MyConfig
8from VersionChecker import VersionChecker
9import yaml
10
11if __name__=="__main__":
12
13cur_path = os.path.dirname(os.path.realpath(__file__))+"\\"
14try:
15cur_path = sys._MEIPASS+"\\"
16except : pass
17settings = MyConfig(cur_path+"config.json")
18logFile = settings.get("LogFile",defaultValue="default.log")
19if os.path.isfile(logFile): os.remove(logFile)
20logger=MyLogger(__name__,log_file=logFile,outStream=sys.stdout)
21try:
22if not os.path.isfile(cur_path+"metadata.yml"): raise Exception("Отсутствует файл metadata.yml")
23metadata:dict = {}
24with open(cur_path+"metadata.yml",mode="r",encoding="UTF-8") as f: metadata = yaml.load(f, Loader=yaml.FullLoader)
25vc = VersionChecker(metadata)
26update_exists = vc.update_exists()
27logger.info(f"start application version({vc.current_version})")
28logger.info(f"update exists: {update_exists}. Update version {vc.update_version}. [{vc.distr_url}]")
29need_update=False
30if update_exists:
31need_update = vc.show_update_dialog()
32logger.info(f"need update: {need_update}")
33os.environ["PYSIDE_DESIGNER_PLUGINS"]="."
34os.environ["QTWEBENGINE_DISABLE_SANDBOX"]="1"
35QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_ShareOpenGLContexts)
36app = QApplication(sys.argv) if not QApplication.instance() else QApplication.instance()
37style = settings.get("AppStyle",defaultValue="Windows")
38app.setStyle(style)
39window = ConsWindow(metadata,need_update,vc.distr_url)
40window.MainWindow.show()
41res=app.exec()
42# print(res)
43sys.exit(res)
44except Exception as exp:
45logger.error(f"general error",exc_info=True)