diff --git a/if-l-run.py b/if-l-run.py new file mode 100644 index 0000000..5f894bf --- /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, os +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] +args = " ".join(sys.argv[2:]) +cwd = ifaceclientlib.Invoke("translate-path", os.getcwd()) +print ifaceclientlib.Invoke("iface-l-run", cwd, cmd, args) diff --git a/if-l-runt.py b/if-l-runt.py new file mode 100644 index 0000000..7a3e363 --- /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, os +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] +args = " ".join(sys.argv[2:]) +cwd = ifaceclientlib.Invoke("translate-path", os.getcwd()) +print ifaceclientlib.Invoke("iface-l-runt", cwd, cmd, args) diff --git a/iface.py b/iface.py index 82cd3cc..0f5df92 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,72 @@ def CMD_l_cmd(info, cwd): else: return "0" +# CMD_l_run +def CMD_l_run(info, cwd, cmd, *args): + global IFACE + + # If we are the HOST, we don't handle this. + if IFACE == IFACE_HOST: + return Invoke(IFACE_VM, "iface-l-run", cwd, cmd, args) + + if len(args) == 0: + args = "" + + # 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 + + # Spawn the terminal. + cwd = cwd.replace("'", "\\'") + 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. + # 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, cwd, cmd, *args): + global IFACE + + # If we are the HOST, we don't handle this. + if IFACE == IFACE_HOST: + return Invoke(IFACE_VM, "iface-l-runt", cwd, cmd, args) + + if len(args) == 0: + args = "" + + # 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 + + # Spawn the terminal. + cwd = cwd.replace("'", "\\'") + 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: + # 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" + # ------------------------------------------------------------------- # Everything else is in main. sys.exit(Main())