summaryrefslogtreecommitdiffstats
path: root/pytools
diff options
context:
space:
mode:
authorAndrew Jeffery <andrew@aj.id.au>2017-10-11 16:57:31 +1030
committerBrad Bishop <bradleyb@fuzziesquirrel.com>2017-10-16 13:11:41 +0000
commit44e6d9c42f8f34cbdda112354b347aa0784233f9 (patch)
tree3be4e5e8bb82d66995e7d127f15df2fd8fe6b205 /pytools
parent076aa1f7b591b66402b1aecd02fbf07a5a36238e (diff)
downloadtalos-skeleton-44e6d9c42f8f34cbdda112354b347aa0784233f9.tar.gz
talos-skeleton-44e6d9c42f8f34cbdda112354b347aa0784233f9.zip
pytools: obmcutil: Put script into a main() method
This is more python hygiene than anything required - it makes the module importable without running arbitrary code at import time. Change-Id: I7f5d8056fa553f484076299823716f73e5c7ead2 Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Diffstat (limited to 'pytools')
-rw-r--r--pytools/obmcutil102
1 files changed, 53 insertions, 49 deletions
diff --git a/pytools/obmcutil b/pytools/obmcutil
index 814ff58..3c083d3 100644
--- a/pytools/obmcutil
+++ b/pytools/obmcutil
@@ -65,63 +65,67 @@ dbus_objects = {
},
}
-# Commands that need to run multiple objects above
-multicmd_objects = { 'state' : ['bmcstate', 'chassisstate', 'hoststate'] }
+def main():
+ # Commands that need to run multiple objects above
+ multicmd_objects = { 'state' : ['bmcstate', 'chassisstate', 'hoststate'] }
-bus = dbus.SystemBus()
+ bus = dbus.SystemBus()
-if (len(sys.argv) == 1 or sys.argv[1] == "-h" or
- (not(dbus_objects.has_key(sys.argv[1])) and
- (not(multicmd_objects.has_key(sys.argv[1]))))):
- print "Usage: obmcutil [command]"
- print "Available commands:"
- for name in sorted(dbus_objects.keys()):
- m = ""
- if (dbus_objects[name].has_key('property') == True):
- m = " (" + dbus_objects[name]['interface_name'] + "->" + \
- dbus_objects[name]['property'] + ")"
+ if (len(sys.argv) == 1 or sys.argv[1] == "-h" or
+ (not(dbus_objects.has_key(sys.argv[1])) and
+ (not(multicmd_objects.has_key(sys.argv[1]))))):
+ print "Usage: obmcutil [command]"
+ print "Available commands:"
+ for name in sorted(dbus_objects.keys()):
+ m = ""
+ if (dbus_objects[name].has_key('property') == True):
+ m = " (" + dbus_objects[name]['interface_name'] + "->" + \
+ dbus_objects[name]['property'] + ")"
- print "\t" + name + m
- print "Multi-Commands:"
- for name in sorted(multicmd_objects.keys()):
- print "\t" + name + " -> " + ",".join(multicmd_objects[name])
- exit(0)
+ print "\t" + name + m
+ print "Multi-Commands:"
+ for name in sorted(multicmd_objects.keys()):
+ print "\t" + name + " -> " + ",".join(multicmd_objects[name])
+ exit(0)
-property_name = ""
+ property_name = ""
-sys.argv.pop(0)
-cmd = [sys.argv.pop(0)]
+ sys.argv.pop(0)
+ cmd = [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]]
+ # Check if this is a multicmd command and update if it is
+ if(multicmd_objects.has_key(cmd[0])):
+ cmd = multicmd_objects[cmd[0]]
-for c in cmd:
- objinfo = dbus_objects[c]
- if (objinfo.has_key('property')):
- property_name = objinfo['property']
+ for c in cmd:
+ objinfo = dbus_objects[c]
+ if (objinfo.has_key('property')):
+ property_name = objinfo['property']
- bus_name = objinfo['bus_name']
- obj_path = objinfo['object_name']
- intf_name = objinfo['interface_name']
- obj = bus.get_object(bus_name, obj_path)
+ bus_name = objinfo['bus_name']
+ obj_path = objinfo['object_name']
+ intf_name = objinfo['interface_name']
+ obj = bus.get_object(bus_name, obj_path)
- if (property_name != ""):
- intf = dbus.Interface(obj, "org.freedesktop.DBus.Properties")
- if (objinfo.has_key('value')):
- property_value = objinfo['value']
- else:
- if(len(sys.argv) > 0):
- property_value = eval(sys.argv.pop(0))
+ if (property_name != ""):
+ intf = dbus.Interface(obj, "org.freedesktop.DBus.Properties")
+ if (objinfo.has_key('value')):
+ property_value = objinfo['value']
+ else:
+ if(len(sys.argv) > 0):
+ property_value = eval(sys.argv.pop(0))
+ else:
+ property_value = None
+ if(property_value is not None):
+ intf.Set(intf_name, property_name, property_value)
else:
- property_value = None
- if(property_value is not None):
- intf.Set(intf_name, property_name, property_value)
+ prop = intf.Get(intf_name,property_name)
+ print '{:<20}'.format(property_name+": ") + str(prop)
else:
- prop = intf.Get(intf_name,property_name)
- print '{:<20}'.format(property_name+": ") + str(prop)
- else:
- intf = dbus.Interface(obj, "org.freedesktop.DBus.Properties")
- props = intf.GetAll(intf_name)
- for p in props:
- print p + " = " + str(props[p])
+ intf = dbus.Interface(obj, "org.freedesktop.DBus.Properties")
+ props = intf.GetAll(intf_name)
+ for p in props:
+ print p + " = " + str(props[p])
+
+if __name__ == "__main__":
+ main()
OpenPOWER on IntegriCloud