From 6c615633073e8f70197b82e1237c1764621ceebd Mon Sep 17 00:00:00 2001 From: yungwine Date: Tue, 21 May 2024 16:22:53 +0700 Subject: [PATCH] run installer commands in mtc console --- mytonctrl/mytonctrl.py | 6 ++++-- mytoninstaller/mytoninstaller.py | 21 +++++++++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/mytonctrl/mytonctrl.py b/mytonctrl/mytonctrl.py index 138aee8d..272d6b65 100755 --- a/mytonctrl/mytonctrl.py +++ b/mytonctrl/mytonctrl.py @@ -249,8 +249,10 @@ def PreUp(local, ton): def Installer(args): # args = ["python3", "/usr/src/mytonctrl/mytoninstaller.py"] - args = ["python3", "-m", "mytoninstaller"] - subprocess.run(args) + cmd = ["python3", "-m", "mytoninstaller"] + if args: + cmd += ["-c", *args] + subprocess.run(cmd) #end define diff --git a/mytoninstaller/mytoninstaller.py b/mytoninstaller/mytoninstaller.py index d8c51cca..160b9210 100644 --- a/mytoninstaller/mytoninstaller.py +++ b/mytoninstaller/mytoninstaller.py @@ -238,12 +238,29 @@ def Event(local, name): #end define -def General(local): +def Command(local, args, console): + cmd = args[0] + args = args[1:] + for item in console.menu_items: + if cmd == item.cmd: + console._try(item.func, args) + print() + local.exit() + print(console.unknown_cmd) + local.exit() +#end define + + +def General(local, console): if "-u" in sys.argv: ux = sys.argv.index("-u") user = sys.argv[ux+1] local.buffer.user = user Refresh(local) + if "-c" in sys.argv: + cx = sys.argv.index("-c") + args = sys.argv[cx+1:] + Command(local, args, console) if "-e" in sys.argv: ex = sys.argv.index("-e") name = sys.argv[ex+1] @@ -282,7 +299,7 @@ def mytoninstaller(): Init(local, console) if len(sys.argv) > 1: - General(local) + General(local, console) else: console.Run() local.exit()