pytools: obmcutil: Introduce run_all_commands()

This implements the partner for-loop to the run_one_command() function,
moving the implementation out of main(). Again this is to elevate the
main() implementation to a higher level of abstraction and reduce
cyclomatic complexity.

Change-Id: I0abe5ee026750efd10dafb6f113359f035ba5bd8
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/pytools/obmcutil b/pytools/obmcutil
index 77398e3..677d997 100644
--- a/pytools/obmcutil
+++ b/pytools/obmcutil
@@ -85,6 +85,15 @@
         for p in props:
             print p + " = " + str(props[p])
 
+def run_all_commands(dbus_bus, commands):
+    if isinstance(commands, dict):
+        run_one_command(dbus_bus, commands)
+        return
+
+    assert isinstance(commands, list)
+    for command in commands:
+        run_one_command(dbus_bus, dbus_objects[command])
+
 def main():
     # Commands that need to run multiple objects above
     multicmd_objects = { 'state' : ['bmcstate', 'chassisstate', 'hoststate'] }
@@ -109,14 +118,13 @@
         exit(0)
 
     sys.argv.pop(0)
-    cmd = [sys.argv.pop(0)]
+    recipe = sys.argv.pop(0)
 
     # Check if this is a multicmd command and update if it is
-    if(multicmd_objects.has_key(cmd[0])):
-        cmd = multicmd_objects[cmd[0]]
+    if(multicmd_objects.has_key(recipe)):
+        recipe = multicmd_objects[recipe]
 
-    for c in cmd:
-        run_one_command(dbus_bus, dbus_objects[c])
+    run_all_commands(dbus_bus, recipe)
 
 if __name__ == "__main__":
     main()