Convert ListOS to use the all helper function.
authorGuido Trotter <ultrotter@google.com>
Mon, 29 Oct 2007 15:20:29 +0000 (15:20 +0000)
committerGuido Trotter <ultrotter@google.com>
Mon, 29 Oct 2007 15:20:29 +0000 (15:20 +0000)
The predicate function gets build by a lambda function.
Also add a bit of debugging information to the 'unknown OS diagnose type'.

Reviewed-by: iustinp

scripts/gnt-os

index 82c2671..a13d2ca 100755 (executable)
@@ -45,7 +45,7 @@ def _DiagnoseOSValid(obj):
   elif isinstance(obj, errors.InvalidOS):
     return False
   else:
-    raise errors.ProgrammerError('unknown OS diagnose type')
+    raise errors.ProgrammerError("unknown OS diagnose type: '%s'" % type(obj))
 
 
 def _DiagnoseOSName(obj):
@@ -126,12 +126,8 @@ def ListOS(opts, args):
   for os_name, os_node_data in all_os.iteritems():
     if len(os_node_data) != num_nodes:
       continue
-    valid = True
-    for l in os_node_data.values():
-      if not _DiagnoseOSValid(l[0]):
-        valid = False
-        break
-    if valid:
+
+    if utils.all(os_node_data.values(), lambda l: _DiagnoseOSValid(l[0])):
       valid_os.append(os_name)
 
   if not opts.no_headers: