From ac1c48776746b5bce65a72602e19e15b31070492 Mon Sep 17 00:00:00 2001 From: maryush Date: Mon, 15 Jan 2018 23:13:01 +0100 Subject: [PATCH 1/3] - added two other commands, run and runt (run just running command, runt run command in new terminal) --- if-l-run.py | 20 ++++++++++++++++++++ if-l-runt.py | 20 ++++++++++++++++++++ iface.py | 29 +++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 if-l-run.py create mode 100644 if-l-runt.py diff --git a/if-l-run.py b/if-l-run.py new file mode 100644 index 0000000..a2385d6 --- /dev/null +++ b/if-l-run.py @@ -0,0 +1,20 @@ +#!/usr/bin/python +# +# LICENSE: See LICENSE file. +# +# WARNING: The Windows/Linux iface by is EXPERIMENTAL and has nothing to do +# with good coding, security, etc. USE AT YOUR OWN RISK. +# +import ifaceclientlib, sys +ifaceclientlib.LOG_LEVEL = ifaceclientlib.LOG_WARNING + +# Check args. +if len(sys.argv) != 2: + print "usage: if-l-run.py " + sys.exit(1) + +# Invoke. +cmd = sys.argv[1] +print ifaceclientlib.Invoke("iface-l-run", cmd) + + diff --git a/if-l-runt.py b/if-l-runt.py new file mode 100644 index 0000000..733b5fe --- /dev/null +++ b/if-l-runt.py @@ -0,0 +1,20 @@ +#!/usr/bin/python +# +# LICENSE: See LICENSE file. +# +# WARNING: The Windows/Linux iface by is EXPERIMENTAL and has nothing to do +# with good coding, security, etc. USE AT YOUR OWN RISK. +# +import ifaceclientlib, sys +ifaceclientlib.LOG_LEVEL = ifaceclientlib.LOG_WARNING + +# Check args. +if len(sys.argv) != 2: + print "usage: if-l-runt.py " + sys.exit(1) + +# Invoke. +cmd = sys.argv[1] +print ifaceclientlib.Invoke("iface-l-runt", cmd) + + diff --git a/iface.py b/iface.py index 82cd3cc..85009b9 100644 --- a/iface.py +++ b/iface.py @@ -98,6 +98,8 @@ "iface-ping" : "CMD_ping", # Returns "pong" "iface-openurl" : "CMD_openurl", # Opens http or https url. "iface-l-cmd" : "CMD_l_cmd", # Spawns a linux console. + "iface-l-run" : "CMD_l_run", # Run linux command + "iface-l-runt" : "CMD_l_runt", # Run linux command in terminal "translate-path": "CMD_translate_path", # Translates path. } @@ -1475,6 +1477,33 @@ def CMD_l_cmd(info, cwd): else: return "0" +# CMD_l_run +def CMD_l_run(info, cmd): + global IFACE + + if IFACE == IFACE_HOST: + return Invoke(IFACE_VM, "iface-l-run", cmd) + + command = "(%s &)" % cmd + + if subprocess.call(command, shell=True) == 0: + return "1" + else: + return "0" + +# CMD_l_runt +def CMD_l_runt(info, cmd): + global IFACE + + if IFACE == IFACE_HOST: + return Invoke(IFACE_VM, "iface-l-runt", cmd) + + command = "(%s -e %s &)" % (TERMINAL_CMD, cmd) + + if subprocess.call(command, shell=True) == 0: + return "1" + else: + return "0" # ------------------------------------------------------------------- # Everything else is in main. sys.exit(Main()) From cbcfb02b2e354d447da447c2c7c8734bb3e8f629 Mon Sep 17 00:00:00 2001 From: maryush Date: Tue, 16 Jan 2018 10:21:23 +0100 Subject: [PATCH 2/3] - some fixes in l-run i l-runt commands, now started in current directory --- if-l-run.py | 7 +++---- if-l-runt.py | 7 +++---- iface.py | 52 +++++++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 51 insertions(+), 15 deletions(-) diff --git a/if-l-run.py b/if-l-run.py index a2385d6..e1ae54a 100644 --- a/if-l-run.py +++ b/if-l-run.py @@ -5,7 +5,7 @@ # WARNING: The Windows/Linux iface by is EXPERIMENTAL and has nothing to do # with good coding, security, etc. USE AT YOUR OWN RISK. # -import ifaceclientlib, sys +import ifaceclientlib, sys, os ifaceclientlib.LOG_LEVEL = ifaceclientlib.LOG_WARNING # Check args. @@ -15,6 +15,5 @@ # Invoke. cmd = sys.argv[1] -print ifaceclientlib.Invoke("iface-l-run", cmd) - - +cwd = ifaceclientlib.Invoke("translate-path", os.getcwd()) +print ifaceclientlib.Invoke("iface-l-run", cmd, cwd) diff --git a/if-l-runt.py b/if-l-runt.py index 733b5fe..8231d45 100644 --- a/if-l-runt.py +++ b/if-l-runt.py @@ -5,7 +5,7 @@ # WARNING: The Windows/Linux iface by is EXPERIMENTAL and has nothing to do # with good coding, security, etc. USE AT YOUR OWN RISK. # -import ifaceclientlib, sys +import ifaceclientlib, sys, os ifaceclientlib.LOG_LEVEL = ifaceclientlib.LOG_WARNING # Check args. @@ -15,6 +15,5 @@ # Invoke. cmd = sys.argv[1] -print ifaceclientlib.Invoke("iface-l-runt", cmd) - - +cwd = ifaceclientlib.Invoke("translate-path", os.getcwd()) +print ifaceclientlib.Invoke("iface-l-runt", cmd, cwd) diff --git a/iface.py b/iface.py index 85009b9..a52a9e0 100644 --- a/iface.py +++ b/iface.py @@ -99,7 +99,7 @@ "iface-openurl" : "CMD_openurl", # Opens http or https url. "iface-l-cmd" : "CMD_l_cmd", # Spawns a linux console. "iface-l-run" : "CMD_l_run", # Run linux command - "iface-l-runt" : "CMD_l_runt", # Run linux command in terminal + "iface-l-runt" : "CMD_l_runt", # Run linux command in terminal "translate-path": "CMD_translate_path", # Translates path. } @@ -1478,29 +1478,67 @@ def CMD_l_cmd(info, cwd): return "0" # CMD_l_run -def CMD_l_run(info, cmd): +def CMD_l_run(info, cmd, *args): global IFACE + cwd = None + # If we are the HOST, we don't handle this. if IFACE == IFACE_HOST: - return Invoke(IFACE_VM, "iface-l-run", cmd) + return Invoke(IFACE_VM, "iface-l-run", cmd, args) + + if len(args) > 0: + cwd = args[0][0] + + # If this is not a linux cwd, we need to convert it. + if cwd[0] != '/': + cwd = Invoke(IFACE_HOST, "translate-path", cwd) + + # Default? + if not cwd: + cwd = HOME_PATH_ON_VM - command = "(%s &)" % cmd + # Spawn the terminal. + cwd = cwd.replace("'", "\\'") + command = "(cd '%s'; %s &)" % (cwd, cmd) + # Spawn. if subprocess.call(command, shell=True) == 0: + # subprocess.call by default returns 0 with process success return code. + # Unfortunately, ifaceclientlib will understand such status as a false and + # will thrown an exception as a result. return "1" else: return "0" # CMD_l_runt -def CMD_l_runt(info, cmd): +def CMD_l_runt(info, cmd, *args): global IFACE + cwd = None + # If we are the HOST, we don't handle this. if IFACE == IFACE_HOST: - return Invoke(IFACE_VM, "iface-l-runt", cmd) + return Invoke(IFACE_VM, "iface-l-runt", cmd, args) + + if len(args) > 0: + cwd = args[0][0] + + # If this is not a linux cwd, we need to convert it. + if cwd[0] != '/': + cwd = Invoke(IFACE_HOST, "translate-path", cwd) - command = "(%s -e %s &)" % (TERMINAL_CMD, cmd) + # Default? + if not cwd: + cwd = HOME_PATH_ON_VM + # Spawn the terminal. + cwd = cwd.replace("'", "\\'") + command = "(cd '%s'; %s -e %s &)" % (cwd, TERMINAL_CMD, cmd) + + # Spawn. if subprocess.call(command, shell=True) == 0: + # subprocess.call by default returns 0 with process success return code. + # Unfortunately, ifaceclientlib will understand such status as a false and + # will thrown an exception as a result. return "1" else: return "0" From 882f2d6ec3021deb270ff05508e40af4baaf3226 Mon Sep 17 00:00:00 2001 From: maryush Date: Tue, 16 Jan 2018 12:48:02 +0100 Subject: [PATCH 3/3] - added support for running command parameters --- if-l-run.py | 7 ++++--- if-l-runt.py | 9 +++++---- iface.py | 29 +++++++++++++++-------------- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/if-l-run.py b/if-l-run.py index e1ae54a..5f894bf 100644 --- a/if-l-run.py +++ b/if-l-run.py @@ -9,11 +9,12 @@ ifaceclientlib.LOG_LEVEL = ifaceclientlib.LOG_WARNING # Check args. -if len(sys.argv) != 2: - print "usage: if-l-run.py " +if len(sys.argv) < 2: + print "usage: if-l-run.py " sys.exit(1) # Invoke. cmd = sys.argv[1] +args = " ".join(sys.argv[2:]) cwd = ifaceclientlib.Invoke("translate-path", os.getcwd()) -print ifaceclientlib.Invoke("iface-l-run", cmd, cwd) +print ifaceclientlib.Invoke("iface-l-run", cwd, cmd, args) diff --git a/if-l-runt.py b/if-l-runt.py index 8231d45..7a3e363 100644 --- a/if-l-runt.py +++ b/if-l-runt.py @@ -9,11 +9,12 @@ ifaceclientlib.LOG_LEVEL = ifaceclientlib.LOG_WARNING # Check args. -if len(sys.argv) != 2: - print "usage: if-l-runt.py " +if len(sys.argv) < 2: + print "usage: if-l-runt.py " sys.exit(1) # Invoke. -cmd = sys.argv[1] +cmd = sys.argv[1] +args = " ".join(sys.argv[2:]) cwd = ifaceclientlib.Invoke("translate-path", os.getcwd()) -print ifaceclientlib.Invoke("iface-l-runt", cmd, cwd) +print ifaceclientlib.Invoke("iface-l-runt", cwd, cmd, args) diff --git a/iface.py b/iface.py index a52a9e0..0f5df92 100644 --- a/iface.py +++ b/iface.py @@ -99,7 +99,7 @@ "iface-openurl" : "CMD_openurl", # Opens http or https url. "iface-l-cmd" : "CMD_l_cmd", # Spawns a linux console. "iface-l-run" : "CMD_l_run", # Run linux command - "iface-l-runt" : "CMD_l_runt", # Run linux command in terminal + "iface-l-runt" : "CMD_l_runt", # Run linux command in terminal "translate-path": "CMD_translate_path", # Translates path. } @@ -1478,16 +1478,15 @@ def CMD_l_cmd(info, cwd): return "0" # CMD_l_run -def CMD_l_run(info, cmd, *args): +def CMD_l_run(info, cwd, cmd, *args): global IFACE - cwd = None # If we are the HOST, we don't handle this. if IFACE == IFACE_HOST: - return Invoke(IFACE_VM, "iface-l-run", cmd, args) + return Invoke(IFACE_VM, "iface-l-run", cwd, cmd, args) - if len(args) > 0: - cwd = args[0][0] + if len(args) == 0: + args = "" # If this is not a linux cwd, we need to convert it. if cwd[0] != '/': @@ -1499,8 +1498,9 @@ def CMD_l_run(info, cmd, *args): # Spawn the terminal. cwd = cwd.replace("'", "\\'") - command = "(cd '%s'; %s &)" % (cwd, cmd) - + args = " ".join(str(i[0]) for i in args) + command = "(cd '%s'; %s %s &)" % (cwd, cmd, args) + # Spawn. if subprocess.call(command, shell=True) == 0: # subprocess.call by default returns 0 with process success return code. @@ -1511,16 +1511,15 @@ def CMD_l_run(info, cmd, *args): return "0" # CMD_l_runt -def CMD_l_runt(info, cmd, *args): +def CMD_l_runt(info, cwd, cmd, *args): global IFACE - cwd = None # If we are the HOST, we don't handle this. if IFACE == IFACE_HOST: - return Invoke(IFACE_VM, "iface-l-runt", cmd, args) + return Invoke(IFACE_VM, "iface-l-runt", cwd, cmd, args) - if len(args) > 0: - cwd = args[0][0] + if len(args) == 0: + args = "" # If this is not a linux cwd, we need to convert it. if cwd[0] != '/': @@ -1532,7 +1531,8 @@ def CMD_l_runt(info, cmd, *args): # Spawn the terminal. cwd = cwd.replace("'", "\\'") - command = "(cd '%s'; %s -e %s &)" % (cwd, TERMINAL_CMD, cmd) + args = " ".join(str(i[0]) for i in args) + command = "(cd '%s'; %s -e '%s %s' &)" % (cwd, TERMINAL_CMD, cmd, args) # Spawn. if subprocess.call(command, shell=True) == 0: @@ -1542,6 +1542,7 @@ def CMD_l_runt(info, cmd, *args): return "1" else: return "0" + # ------------------------------------------------------------------- # Everything else is in main. sys.exit(Main())