diff options
author | Andrew Jeffery <andrew@aj.id.au> | 2017-10-11 18:12:05 +1030 |
---|---|---|
committer | Andrew Jeffery <andrew@aj.id.au> | 2017-10-17 11:46:06 +1030 |
commit | 7b376e7b5678154d7f9873d5e518c17e3f548f3f (patch) | |
tree | e98e8b820d52710820c95aeae3153852faf43b0e /pytools | |
parent | e4dcaef2605c87302d5826fc8d34a25ca8613c43 (diff) | |
download | talos-skeleton-7b376e7b5678154d7f9873d5e518c17e3f548f3f.tar.gz talos-skeleton-7b376e7b5678154d7f9873d5e518c17e3f548f3f.zip |
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>
Diffstat (limited to 'pytools')
-rw-r--r-- | pytools/obmcutil | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/pytools/obmcutil b/pytools/obmcutil index 77398e3..677d997 100644 --- a/pytools/obmcutil +++ b/pytools/obmcutil @@ -85,6 +85,15 @@ def run_one_command(dbus_bus, objinfo): 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 @@ def main(): 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() |