From 80c6bf0fd770417a2c38cbc6a3d005d0104c4499 Mon Sep 17 00:00:00 2001
From: Matthieu Gonnet <matthieu.gonnet@smartjog.com>
Date: Mon, 23 May 2011 18:43:10 +0200
Subject: [PATCH] Add watch command

---
 cccli/commands/watch.py | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100644 cccli/commands/watch.py

diff --git a/cccli/commands/watch.py b/cccli/commands/watch.py
new file mode 100644
index 0000000..7f8a00e
--- /dev/null
+++ b/cccli/commands/watch.py
@@ -0,0 +1,36 @@
+#!/usr/bin/env python
+#coding=utf8
+
+'''
+CloudControl watch command
+'''
+
+import time as systime
+
+from cccli.exception import *
+from sjrpc.core.exceptions import *
+from cccli.printer import Printer, color
+from cccli.command import OptionCommand
+
+
+class Command_watch(OptionCommand):
+    '''Show output of a repeated command'''
+
+    def __init__(self, cli, argv0):
+        OptionCommand.__init__(self, cli, argv0)
+        self.set_usage("%prog [options] command [options]")
+        self.add_option("-n", "--interval", dest="seconds", type="float", default=1.0,
+                        help="Define interval in seconds")
+
+    def __call__(self, argv):
+        # Parse argline
+        self.parse_args(argv)
+        if len(self.args) == 0:
+            raise cmdBadArgument()
+        while True:
+            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)
-- 
GitLab