qvm-run: add color output and filtering escape sequences
This makes VM output clearly distinguishable
This commit is contained in:
parent
5cbfb64a57
commit
ac7746feed
@ -1435,7 +1435,11 @@ class QubesVm(object):
|
|||||||
print >>sys.stderr, "Failed to detach PCI device on the fly " \
|
print >>sys.stderr, "Failed to detach PCI device on the fly " \
|
||||||
"(%s), changes will be seen after VM restart" % str(e)
|
"(%s), changes will be seen after VM restart" % str(e)
|
||||||
|
|
||||||
def run(self, command, user = None, verbose = True, autostart = False, notify_function = None, passio = False, passio_popen = False, passio_stderr=False, ignore_stderr=False, localcmd = None, wait = False, gui = True):
|
def run(self, command, user = None, verbose = True, autostart = False,
|
||||||
|
notify_function = None,
|
||||||
|
passio = False, passio_popen = False, passio_stderr=False,
|
||||||
|
ignore_stderr=False, localcmd = None, wait = False, gui = True,
|
||||||
|
filter_esc = False):
|
||||||
"""command should be in form 'cmdline'
|
"""command should be in form 'cmdline'
|
||||||
When passio_popen=True, popen object with stdout connected to pipe.
|
When passio_popen=True, popen object with stdout connected to pipe.
|
||||||
When additionally passio_stderr=True, stderr also is connected to pipe.
|
When additionally passio_stderr=True, stderr also is connected to pipe.
|
||||||
@ -1473,6 +1477,10 @@ class QubesVm(object):
|
|||||||
args = [system_path["qrexec_client_path"], "-d", str(xid), "%s:%s" % (user, command)]
|
args = [system_path["qrexec_client_path"], "-d", str(xid), "%s:%s" % (user, command)]
|
||||||
if localcmd is not None:
|
if localcmd is not None:
|
||||||
args += [ "-l", localcmd]
|
args += [ "-l", localcmd]
|
||||||
|
if filter_esc:
|
||||||
|
args += ["-t"]
|
||||||
|
if os.isatty(sys.stderr.fileno()):
|
||||||
|
args += ["-T"]
|
||||||
if passio:
|
if passio:
|
||||||
os.execv(system_path["qrexec_client_path"], args)
|
os.execv(system_path["qrexec_client_path"], args)
|
||||||
exit(1)
|
exit(1)
|
||||||
|
@ -76,6 +76,8 @@ def vm_run_cmd(vm, cmd, options):
|
|||||||
|
|
||||||
if options.verbose:
|
if options.verbose:
|
||||||
print >> sys.stderr, "Running command on VM: '{0}'...".format(vm.name)
|
print >> sys.stderr, "Running command on VM: '{0}'...".format(vm.name)
|
||||||
|
if options.passio and options.color_output:
|
||||||
|
print "\033[0;31m",
|
||||||
|
|
||||||
try:
|
try:
|
||||||
def tray_notify_generic(level, str):
|
def tray_notify_generic(level, str):
|
||||||
@ -88,13 +90,19 @@ def vm_run_cmd(vm, cmd, options):
|
|||||||
verbose = options.verbose,
|
verbose = options.verbose,
|
||||||
user = options.user,
|
user = options.user,
|
||||||
notify_function = tray_notify_generic if options.tray else None,
|
notify_function = tray_notify_generic if options.tray else None,
|
||||||
passio = options.passio, localcmd = options.localcmd, gui = options.gui)
|
wait = options.passio, localcmd = options.localcmd,
|
||||||
|
gui = options.gui, filter_esc = options.filter_esc)
|
||||||
except QubesException as err:
|
except QubesException as err:
|
||||||
|
if options.passio and options.color_output:
|
||||||
|
print "\033[0m",
|
||||||
if options.tray:
|
if options.tray:
|
||||||
tray_notify_error(str(err))
|
tray_notify_error(str(err))
|
||||||
notify_error_qubes_manager(vm.name, str(err))
|
notify_error_qubes_manager(vm.name, str(err))
|
||||||
print >> sys.stderr, "ERROR(%s): %s" % (str(vm.name), str(err))
|
print >> sys.stderr, "ERROR(%s): %s" % (str(vm.name), str(err))
|
||||||
return 1
|
return 1
|
||||||
|
finally:
|
||||||
|
if options.passio and options.color_output:
|
||||||
|
print "\033[0m",
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
usage = "usage: %prog [options] [<vm-name>] [<cmd>]"
|
usage = "usage: %prog [options] [<vm-name>] [<cmd>]"
|
||||||
@ -106,7 +114,7 @@ def main():
|
|||||||
help="Run command in a VM as a specified user")
|
help="Run command in a VM as a specified user")
|
||||||
parser.add_option ("--tray", action="store_true", dest="tray", default=False,
|
parser.add_option ("--tray", action="store_true", dest="tray", default=False,
|
||||||
help="Use tray notifications instead of stdout" )
|
help="Use tray notifications instead of stdout" )
|
||||||
|
|
||||||
parser.add_option ("--all", action="store_true", dest="run_on_all_running", default=False,
|
parser.add_option ("--all", action="store_true", dest="run_on_all_running", default=False,
|
||||||
help="Run command on all currently running VMs (or all paused, in case of --unpause)")
|
help="Run command on all currently running VMs (or all paused, in case of --unpause)")
|
||||||
|
|
||||||
@ -138,6 +146,21 @@ def main():
|
|||||||
parser.add_option ("--nogui", action="store_false", dest="gui", default=True,
|
parser.add_option ("--nogui", action="store_false", dest="gui", default=True,
|
||||||
help="Run command without gui")
|
help="Run command without gui")
|
||||||
|
|
||||||
|
parser.add_option ("--filter-escape-chars", action="store_true",
|
||||||
|
dest="filter_esc",
|
||||||
|
default=os.isatty(sys.stdout.fileno()),
|
||||||
|
help="Filter terminal escape sequences (default if "
|
||||||
|
"output is terminal)")
|
||||||
|
parser.add_option("--no-filter-escape-chars", action="store_false",
|
||||||
|
dest="filter_esc",
|
||||||
|
help="Do not filter terminal escape sequences - "
|
||||||
|
"overrides --filter-escape-chars, DANGEROUS when "
|
||||||
|
"output is terminal")
|
||||||
|
|
||||||
|
parser.add_option("--no-color-output", action="store_false",
|
||||||
|
dest="color_output", default=None,
|
||||||
|
help="Disable marking VM output with red color")
|
||||||
|
|
||||||
(options, args) = parser.parse_args ()
|
(options, args) = parser.parse_args ()
|
||||||
|
|
||||||
if options.passio and options.run_on_all_running:
|
if options.passio and options.run_on_all_running:
|
||||||
@ -146,6 +169,9 @@ def main():
|
|||||||
if options.passio:
|
if options.passio:
|
||||||
options.verbose = False
|
options.verbose = False
|
||||||
|
|
||||||
|
if options.color_output is None:
|
||||||
|
options.color_output = os.isatty(sys.stdout.fileno())
|
||||||
|
|
||||||
if options.shutdown:
|
if options.shutdown:
|
||||||
print >>sys.stderr, "WARNING: --shutdown is deprecated. Use qvm-shutdown instead."
|
print >>sys.stderr, "WARNING: --shutdown is deprecated. Use qvm-shutdown instead."
|
||||||
|
|
||||||
@ -213,7 +239,7 @@ def main():
|
|||||||
|
|
||||||
while len (vms_list):
|
while len (vms_list):
|
||||||
if options.verbose:
|
if options.verbose:
|
||||||
print >> sys.stderr, "Waiting for VMs: ", [vm.name for vm in vms_list]
|
print >> sys.stderr, "Waiting for VMs: ", [vm.name for vm in vms_list]
|
||||||
for vm in vms_list:
|
for vm in vms_list:
|
||||||
if not vm.is_running():
|
if not vm.is_running():
|
||||||
vms_list.remove (vm)
|
vms_list.remove (vm)
|
||||||
|
Loading…
Reference in New Issue
Block a user