devices: Add a wait-for-device command
It's kinda a pain to have to constantly run devices repeatedly until we get some
devices. Let's do a wait-for-device command to help with this.
Change-Id: Iae8c00109a0405235518533f30b9a94a95190dba
diff --git a/mdt/devices.py b/mdt/devices.py
index 459cf5a..8d67056 100644
--- a/mdt/devices.py
+++ b/mdt/devices.py
@@ -12,3 +12,19 @@
discoveries = self.discoverer.discoveries
for host, address in discoveries.items():
print('%s\t\t%s' % (host, address))
+
+class DevicesWaitCommand:
+ def __init__(self):
+ self.discoverer = Discoverer()
+
+ def run(self, args):
+ print('Waiting for device...')
+ found_device = False
+ while True:
+ sleep(1)
+ discoveries = self.discoverer.discoveries
+ if discoveries:
+ break
+ print('Devices found:')
+ for host, address in self.discoverer.discoveries.items():
+ print('%s\t\t%s' % (host, address))
diff --git a/mdt/mdt.py b/mdt/mdt.py
index 5e3c8bd..de0b198 100755
--- a/mdt/mdt.py
+++ b/mdt/mdt.py
@@ -10,7 +10,7 @@
import sys
import devices
-
+import keys
class HelpCommand:
def run(self, args):
@@ -20,6 +20,7 @@
COMMANDS = {
'help': HelpCommand(),
'devices': devices.DevicesCommand(),
+ 'wait-for-device': devices.DevicesWaitCommand(),
}