Skip to content
Snippets Groups Projects
Commit 9dd12283 authored by Matthieu Gonnet's avatar Matthieu Gonnet Committed by Seblu
Browse files

Fix blink in watch command

The watch command uses a buffer instead of the standard output. Using this the watch
command can execute commands and wait the end of the execution to clear and print the buffer.
The watch command also catch cliException and KeyboardInterrupt in order to proceed to clean exit.
parent 34e1cf38
No related branches found
No related tags found
No related merge requests found
......@@ -5,13 +5,14 @@
CloudControl watch command
'''
import time as systime
import sys
import time
from cccli.exception import *
from sjrpc.core.exceptions import *
from cccli.printer import Printer, color
from cccli.command import OptionCommand
from cStringIO import StringIO
class Command_watch(OptionCommand):
'''Show output of a repeated command'''
......@@ -28,9 +29,23 @@ class Command_watch(OptionCommand):
if len(self.args) == 0:
raise cmdBadArgument()
while True:
# Substitute aliases
self.args = self.cli.aliases.substitute(self.args)
# Clear tty
self.cli.commands(["clear"])
# Execute command
self.cli.commands(self.args)
systime.sleep(self.options.seconds)
# Put the fd of a buffer in sys.stdout and sys.err instead of the tty fd
sys.stderr = sys.stdout = StringIO()
try:
# Clear tty
self.printer.clear()
# Execute command and write output in the buffer
self.cli.commands(self.args)
# Print the buffer
self.printer.out(sys.stdout.getvalue(), fd=sys.__stdout__)
# Wait
time.sleep(self.options.seconds)
except KeyboardInterrupt:
raise
except cliException:
raise
finally:
sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment