tools/qvm-run: factor out print_no_color function
Will be useful for other messages that should not be in red.
This commit is contained in:
parent
32cbc59ba9
commit
d34b1bfc4f
@ -128,6 +128,16 @@ def copy_stdin(stream):
|
|||||||
break
|
break
|
||||||
stream.close()
|
stream.close()
|
||||||
|
|
||||||
|
def print_no_color(msg, file, color):
|
||||||
|
'''Print a *msg* to *file* without coloring it.
|
||||||
|
Namely reset to base color first, print a message, then restore color.
|
||||||
|
'''
|
||||||
|
if color:
|
||||||
|
print('\033[0m{}\033[0;{}m'.format(msg, color), file=file)
|
||||||
|
else:
|
||||||
|
print(msg, file=file)
|
||||||
|
|
||||||
|
|
||||||
def main(args=None, app=None):
|
def main(args=None, app=None):
|
||||||
'''Main function of qvm-run tool'''
|
'''Main function of qvm-run tool'''
|
||||||
args = parser.parse_args(args, app=app)
|
args = parser.parse_args(args, app=app)
|
||||||
@ -200,13 +210,9 @@ def main(args=None, app=None):
|
|||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
if verbose > 0:
|
if verbose > 0:
|
||||||
if args.color_output:
|
print_no_color(
|
||||||
print('\033[0mRunning \'{}\' on {}\033[0;{}m'.format(
|
'Running \'{}\' on {}'.format(args.cmd, vm.name),
|
||||||
args.cmd, vm.name, args.color_stderr),
|
file=sys.stderr, color=args.color_stderr)
|
||||||
file=sys.stderr)
|
|
||||||
else:
|
|
||||||
print('Running \'{}\' on {}'.format(args.cmd, vm.name),
|
|
||||||
file=sys.stderr)
|
|
||||||
if args.gui and not args.dispvm:
|
if args.gui and not args.dispvm:
|
||||||
wait_session = vm.run_service('qubes.WaitForSession',
|
wait_session = vm.run_service('qubes.WaitForSession',
|
||||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||||
|
Loading…
Reference in New Issue
Block a user