Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions if-l-run.py
Original file line number Diff line number Diff line change
@@ -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 <cmd> <args>"
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)
20 changes: 20 additions & 0 deletions if-l-runt.py
Original file line number Diff line number Diff line change
@@ -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 <cmd> <args>"
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)
68 changes: 68 additions & 0 deletions iface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}

Expand Down Expand Up @@ -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())
Expand Down