#!/usr/bin/python

import sys
import dbus
import json
import xml.etree.ElementTree as ET

dbus_objects = {
    'power': {
        'bus_name': 'org.openbmc.control.Power',
        'object_name': '/org/openbmc/control/power0',
        'interface_name': 'org.openbmc.control.Power'
    },
    'chassison': {
        'bus_name': 'xyz.openbmc_project.State.Chassis',
        'object_name': '/xyz/openbmc_project/state/chassis0',
        'interface_name': 'xyz.openbmc_project.State.Chassis',
        'property': 'RequestedPowerTransition',
        'value': 'xyz.openbmc_project.State.Chassis.Transition.On'
    },
    'chassisoff': {
        'bus_name': 'xyz.openbmc_project.State.Chassis',
        'object_name': '/xyz/openbmc_project/state/chassis0',
        'interface_name': 'xyz.openbmc_project.State.Chassis',
        'property': 'RequestedPowerTransition',
        'value': 'xyz.openbmc_project.State.Chassis.Transition.Off'
    },
    'poweron': {
        'bus_name': 'xyz.openbmc_project.State.Host',
        'object_name': '/xyz/openbmc_project/state/host0',
        'interface_name': 'xyz.openbmc_project.State.Host',
        'property': 'RequestedHostTransition',
        'value': 'xyz.openbmc_project.State.Host.Transition.On'
    },
    'poweroff': {
        'bus_name': 'xyz.openbmc_project.State.Host',
        'object_name': '/xyz/openbmc_project/state/host0',
        'interface_name': 'xyz.openbmc_project.State.Host',
        'property': 'RequestedHostTransition',
        'value': 'xyz.openbmc_project.State.Host.Transition.Off'
    },
    'bmcstate': {
        'bus_name': 'xyz.openbmc_project.State.BMC',
        'object_name': '/xyz/openbmc_project/state/bmc0',
        'interface_name': 'xyz.openbmc_project.State.BMC',
        'property': 'CurrentBMCState',
    },
    'chassisstate': {
        'bus_name': 'xyz.openbmc_project.State.Chassis',
        'object_name': '/xyz/openbmc_project/state/chassis0',
        'interface_name': 'xyz.openbmc_project.State.Chassis',
        'property': 'CurrentPowerState',
    },
    'hoststate': {
        'bus_name': 'xyz.openbmc_project.State.Host',
        'object_name': '/xyz/openbmc_project/state/host0',
        'interface_name': 'xyz.openbmc_project.State.Host',
        'property': 'CurrentHostState',
    },
    'bootprogress': {
        'bus_name': 'xyz.openbmc_project.State.Host',
        'object_name': '/xyz/openbmc_project/state/host0',
        'interface_name': 'xyz.openbmc_project.State.Boot.Progress',
        'property': 'BootProgress',
    },
}

def main():
    # Commands that need to run multiple objects above
    multicmd_objects = { 'state' : ['bmcstate', 'chassisstate', 'hoststate'] }

    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'] + ")"

            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 = ""

    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]]

    for c in cmd:
        objinfo = dbus_objects[c]
        if (objinfo.has_key('property')):
            property_name = objinfo['property']

        bus_name = objinfo['bus_name']
        obj = objinfo['object_name']
        intf_name = objinfo['interface_name']
        dbus_obj = bus.get_object(bus_name, obj)

        if (property_name != ""):
            dbus_iface = dbus.Interface(dbus_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):
                dbus_iface.Set(intf_name, property_name, property_value)
            else:
                prop = dbus_iface.Get(intf_name,property_name)
                print '{:<20}'.format(property_name+": ") + str(prop)
        else:
            dbus_iface = dbus.Interface(dbus_obj, "org.freedesktop.DBus.Properties")
            props = dbus_iface.GetAll(intf_name)
            for p in props:
                print p + " = " + str(props[p])

if __name__ == "__main__":
    main()
