添加命令行选项及tracer
This commit is contained in:
parent
eac7311e45
commit
1e01289d53
|
@ -9,7 +9,16 @@
|
||||||
"type": "debugpy",
|
"type": "debugpy",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"program": "main.py",
|
"program": "main.py",
|
||||||
|
"args": "--debug",
|
||||||
"console": "integratedTerminal"
|
"console": "integratedTerminal"
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
"name": "Python 包含参数",
|
||||||
|
"type": "debugpy",
|
||||||
|
"request": "launch",
|
||||||
|
"program": "main.py",
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"args": "${command:pickArgs}"
|
||||||
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -14,10 +14,10 @@ levels = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def init() -> None:
|
def log_init() -> None:
|
||||||
logging.basicConfig(filename=config.LOGPATH,
|
logging.basicConfig(filename=config.LOGPATH,
|
||||||
format='[%(asctime)s][%(levelname)s] %(message)s',
|
format='[%(asctime)s][%(levelname)s] %(message)s',
|
||||||
level=levels[config.LOGLEVEL])
|
level=levels[config.LOGLEVEL], filemode='w')
|
||||||
|
|
||||||
|
|
||||||
def info(msg: str) -> None:
|
def info(msg: str) -> None:
|
||||||
|
@ -53,3 +53,7 @@ def print(*args, end="\n") -> None:
|
||||||
if (10 >= levels[config.LOGLEVEL]):
|
if (10 >= levels[config.LOGLEVEL]):
|
||||||
sys.stdout.write(msg + end)
|
sys.stdout.write(msg + end)
|
||||||
logging.debug(msg)
|
logging.debug(msg)
|
||||||
|
|
||||||
|
|
||||||
|
def trace_sys(msg: str) -> None:
|
||||||
|
logging.info(msg)
|
||||||
|
|
2
main.py
2
main.py
|
@ -1,3 +1,3 @@
|
||||||
from ui import win
|
from ui import win
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
win.main()
|
win.run()
|
||||||
|
|
105
ui/win.py
105
ui/win.py
|
@ -1,6 +1,8 @@
|
||||||
|
from doctest import debug
|
||||||
from tkinter import messagebox
|
from tkinter import messagebox
|
||||||
from magictk import mtk
|
from magictk import mtk
|
||||||
from logger.logger import *
|
from logger.logger import *
|
||||||
|
from logger import config
|
||||||
from ui import nav
|
from ui import nav
|
||||||
from ui import installer
|
from ui import installer
|
||||||
from lib import get_disk
|
from lib import get_disk
|
||||||
|
@ -11,31 +13,81 @@ import platform
|
||||||
import ctypes
|
import ctypes
|
||||||
import os
|
import os
|
||||||
import locale
|
import locale
|
||||||
|
import traceback
|
||||||
init()
|
import textwrap
|
||||||
|
|
||||||
nlang = locale.getdefaultlocale()[0].lower()
|
nlang = locale.getdefaultlocale()[0].lower()
|
||||||
|
|
||||||
|
|
||||||
|
def check_args(arg, check):
|
||||||
|
if len(arg) >= len(check):
|
||||||
|
if (arg[:len(check)] == check):
|
||||||
|
return 1
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
DISPERMISSION = 0
|
||||||
|
DEBUG = 0
|
||||||
|
NOTRACE = 0
|
||||||
|
for i in sys.argv[1:]:
|
||||||
|
if (check_args(i, "--lang")):
|
||||||
|
nlang = i.split("=")[-1]
|
||||||
|
if (check_args(i, "--dis-permission-error")):
|
||||||
|
DISPERMISSION = 1
|
||||||
|
if (check_args(i, "--log-level")):
|
||||||
|
config.LOGLEVEL = i.split("=")[-1]
|
||||||
|
if (check_args(i, "--debug")):
|
||||||
|
DEBUG = 1
|
||||||
|
if (check_args(i, "--no-trace")):
|
||||||
|
NOTRACE = 1
|
||||||
if (nlang+".toml" not in os.listdir("lang")):
|
if (nlang+".toml" not in os.listdir("lang")):
|
||||||
nlang = "en_us"
|
nlang = "en_us"
|
||||||
load_lang(nlang)
|
|
||||||
|
|
||||||
disk_res = get_disk.find_hub_disk()
|
|
||||||
errno = disk_res[0]
|
def main():
|
||||||
root_disk = disk_res[1]
|
log_init()
|
||||||
if (errno == 1):
|
if (DEBUG == 1):
|
||||||
|
info("[win]< debug mode >")
|
||||||
|
|
||||||
|
if (NOTRACE == 0):
|
||||||
|
info("[trace]open trace")
|
||||||
|
trace_sys(f"[trace]OS={platform.system()}")
|
||||||
|
trace_sys(f"[trace]VER={platform.version()}")
|
||||||
|
trace_sys(f"[trace]CPU={platform.processor()}")
|
||||||
|
trace_sys(f"[trace]ARCH={str(platform.architecture()[0])}")
|
||||||
|
trace_sys(f"[trace]PYVER={platform.python_version()}")
|
||||||
|
trace_sys(f"[trace]PYIMP={platform.python_implementation()}")
|
||||||
|
load_lang(nlang)
|
||||||
|
|
||||||
|
disk_res = get_disk.find_hub_disk()
|
||||||
|
errno = disk_res[0]
|
||||||
|
root_disk = disk_res[1]
|
||||||
|
if (errno == 1):
|
||||||
messagebox.showerror("Injector Hub Error", root_disk)
|
messagebox.showerror("Injector Hub Error", root_disk)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
elif (errno == 2):
|
elif (errno == 2):
|
||||||
info("[win]cannot find installed disk")
|
info("[win]cannot find installed disk")
|
||||||
|
if DISPERMISSION == 0:
|
||||||
if (platform.system() == "Linux" and getpass.getuser() != "root"):
|
if (platform.system() == "Linux" and getpass.getuser() != "root"):
|
||||||
messagebox.showerror("Injector Hub Error", l("PermissionDeniedLinux"))
|
err("permission denied in linux")
|
||||||
|
messagebox.showerror("Injector Hub Error",
|
||||||
|
l("PermissionDeniedLinux"))
|
||||||
|
if (DEBUG == 0):
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
sys.exit()
|
||||||
if (platform.system() == "Windows" and ctypes.windll.shell32.IsUserAnAdmin() == False):
|
if (platform.system() == "Windows" and ctypes.windll.shell32.IsUserAnAdmin() == False):
|
||||||
messagebox.showerror("Injector Hub Error", l("PermissionDeniedWin"))
|
err("permission denied in windows")
|
||||||
|
messagebox.showerror("Injector Hub Error",
|
||||||
|
l("PermissionDeniedWin"))
|
||||||
|
if (DEBUG == 0):
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
sys.exit()
|
||||||
nav_list = [
|
nav_list = [
|
||||||
{"icon": "lightning", "frame": installer.installer_ui, "side": "top"}
|
{"icon": "lightning", "frame": installer.installer_ui, "side": "top"}
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
info(f"[win]found installed disk \"{root_disk}\"")
|
info(f"[win]found installed disk \"{root_disk}\"")
|
||||||
nav_list = [
|
nav_list = [
|
||||||
{"icon": "home-filled", "frame": None, "side": "top"},
|
{"icon": "home-filled", "frame": None, "side": "top"},
|
||||||
|
@ -44,15 +96,30 @@ else:
|
||||||
{"icon": "setting", "frame": None, "side": "bottom"}
|
{"icon": "setting", "frame": None, "side": "bottom"}
|
||||||
]
|
]
|
||||||
|
|
||||||
info("[win]init window")
|
info("[win]init window")
|
||||||
mtk.load_icon_pack("res/icon.pack")
|
mtk.load_icon_pack("res/icon.pack")
|
||||||
main_win = mtk.Tk(title="Injector Hub", w=1000, h=800)
|
main_win = mtk.Tk(title="Injector Hub", w=1000, h=800)
|
||||||
|
|
||||||
main_frame = mtk.Frame(main_win, w=10000)
|
main_frame = mtk.Frame(main_win, w=10000)
|
||||||
nav.pack_nav(main_win, main_frame, nav_list)
|
nav.pack_nav(main_win, main_frame, nav_list)
|
||||||
main_frame.pack(side="left", fill="both", expand=True)
|
main_frame.pack(side="left", fill="both", expand=True)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
info("[win]mainloop")
|
info("[win]mainloop")
|
||||||
main_win.mainloop()
|
main_win.mainloop()
|
||||||
|
|
||||||
|
|
||||||
|
def run():
|
||||||
|
try:
|
||||||
|
main()
|
||||||
|
except Exception as exp:
|
||||||
|
err("[errtrace] caught err:"+repr(exp))
|
||||||
|
for i in traceback.format_exc().split("\n"):
|
||||||
|
firstlen_flag = "* "
|
||||||
|
lastlen = ""
|
||||||
|
for j in textwrap.wrap(i, width=40):
|
||||||
|
err("[errtrace]"+" "+firstlen_flag+" " *
|
||||||
|
(len(lastlen)-len(lastlen.lstrip()))+j)
|
||||||
|
lastlen = " " * (len(lastlen)-len(lastlen.lstrip()))+j
|
||||||
|
firstlen_flag = " "
|
||||||
|
if (DEBUG == 1):
|
||||||
|
raise
|
||||||
|
|
Loading…
Reference in New Issue