Repository navigation
Expand file tree
/
Copy pathradar.py
More file actions
128 lines (113 loc) · 3.94 KB
/
Copy pathradar.py
File metadata and controls
128 lines (113 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# -*- coding: utf-8 -*-
#Application startup file
import os
import sys
import simpleDialog
import requests.exceptions
import traceback
import winsound
from views.mpvPlayer import shutdown_global_mpv_player
#64bitのPythonでは起動させない
if sys.maxsize > (2 ** 32):
print("64 bit環境では起動できません。")
exit()
#カレントディレクトリを設定
if hasattr(sys,"frozen"): os.chdir(os.path.dirname(sys.executable))
else: os.chdir(os.path.abspath(os.path.dirname(__file__)))
def exchandler(type, exc, tb):
msg=traceback.format_exception(type, exc, tb)
print(msg)
# 異常終了時のクリーンアップ処理
try:
from recorder import schedule_manager
schedule_manager.cleanup_on_error()
except Exception as cleanup_error:
print(f"Error during emergency cleanup: {cleanup_error}")
# 番組キャッシュのクリーンアップ
try:
if hasattr(globalVars, 'app') and hasattr(globalVars.app, 'hMainView'):
if hasattr(globalVars.app.hMainView, 'program_cache_controller'):
globalVars.app.hMainView.program_cache_controller.cleanup()
except Exception as cache_cleanup_error:
try:
shutdown_log.get_shutdown_logger().error(
"Fatal: program cache cleanup failed: %s", cache_cleanup_error, exc_info=True
)
shutdown_log.flush_app_log_handlers()
except Exception:
print(f"Error during cache cleanup: {cache_cleanup_error}")
try:
shutdown_global_mpv_player()
except Exception as mpv_cleanup_error:
print(f"Error during mpv cleanup: {mpv_cleanup_error}")
if type == requests.exceptions.ConnectionError:
simpleDialog.errorDialog(_("通信に失敗しました。インターネット接続を確認してください。プログラムを終了します。"))
os._exit(1)
return
elif type == requests.exceptions.ProxyError:
simpleDialog.errorDialog(_("通信に失敗しました。プロキシサーバーの設定を確認してください。プログラムを終了します。"))
os._exit(1)
return
if not hasattr(sys, "frozen"):
print("".join(msg))
winsound.Beep(1000, 1100)
try:
globalVars.app.say(str(msg[-1]))
except:
pass
else:
simpleDialog.winDialog("error", "An error has occurred. Contact to the developer for further assistance. Detail:" + "\n".join(msg[-2:]))
try:
f=open("errorLog.txt", "a")
f.writelines(msg)
f.close()
except:
pass
os._exit(1)
sys.excepthook=exchandler
#Python3.8対応
#dllやモジュールをカレントディレクトリから読み込むように設定
if sys.version_info.major>=3 and sys.version_info.minor>=8:
os.add_dll_directory(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
import app as application
import globalVars
import shutdown_log
def main():
try:
if os.path.exists("errorLog.txt"):
os.remove("errorLog.txt")
except:
pass
app=application.Main()
globalVars.app=app
app.initialize()
app.MainLoop()
_sd = shutdown_log.get_shutdown_logger()
_sd.info(
"[Shutdown] Returned from MainLoop (wx.App.OnExit already ran); saving settings and closing DB"
)
app.config.write()
_sd.info("[Shutdown] Settings file saved")
try:
if hasattr(app, 'hMainView') and hasattr(app.hMainView, 'program_cache_controller'):
controller = app.hMainView.program_cache_controller
if not controller._cleanup_done:
_sd.info("[Shutdown] Calling ProgramCacheController.cleanup (sqlite)")
controller.cleanup()
else:
_sd.info("[Shutdown] Program cache already closed in Phase 2; skipping")
else:
_sd.warning("[Shutdown] program_cache_controller missing; skipping DB close")
except Exception as cleanup_error:
_sd.error(
"[Shutdown] Program cache cleanup failed on normal exit: %s",
cleanup_error,
exc_info=True,
)
_sd.info("[Shutdown] Flushing log handlers")
shutdown_log.flush_app_log_handlers()
_sd.info("[Shutdown] Shutdown log complete (atexit recording cleanup follows)")
shutdown_log.flush_app_log_handlers()
#global schope
if __name__ == "__main__": main()