Reorganize directory structure

Moving to directory per-application layout.  This facilitates
building single applications which is useful in the Yocto build
environment since different applications satisfy different OpenBMC
build requirements.

A number of issues are also addressed:
 - All applications were pulling in libsystemd and the gdbus libs
    irrespective of whether or not they were needed.
 - gpio.o duplicated in every application - moved to libopenbmc_intf
 - Added install target

Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/pystatemgr/Makefile b/pystatemgr/Makefile
new file mode 120000
index 0000000..76a90fc
--- /dev/null
+++ b/pystatemgr/Makefile
@@ -0,0 +1 @@
+../Makefile.python
\ No newline at end of file
diff --git a/pystatemgr/discover_system_state.py b/pystatemgr/discover_system_state.py
new file mode 100644
index 0000000..5bd8fdc
--- /dev/null
+++ b/pystatemgr/discover_system_state.py
@@ -0,0 +1,76 @@
+#!/usr/bin/python
+
+import sys
+import gobject
+import dbus
+import dbus.service
+import dbus.mainloop.glib
+
+
+dbus_objects = {
+	'power' : { 
+		'bus_name' : 'org.openbmc.control.Power',
+		'object_name' : '/org/openbmc/control/power0',
+		'interface_name' : 'org.openbmc.control.Power'
+	},
+	'occstatus0' : { 
+		'bus_name' : 'org.openbmc.Sensors',
+		'object_name' : '/org/openbmc/sensors/host/cpu0/OccStatus',
+		'interface_name' : 'org.openbmc.SensorValue'
+	},
+	'occstatus1' : { 
+		'bus_name' : 'org.openbmc.Sensors',
+		'object_name' : '/org/openbmc/sensors/host/cpu1/OccStatus',
+		'interface_name' : 'org.openbmc.SensorValue'
+	},
+	'bootprogress' : { 
+		'bus_name' : 'org.openbmc.Sensors',
+		'object_name' : '/org/openbmc/sensors/host/BootProgress',
+		'interface_name' : 'org.openbmc.SensorValue'
+	},
+	'chassis' : { 
+		'bus_name' : 'org.openbmc.control.Chassis',
+		'object_name' : '/org/openbmc/control/chassis0',
+		'interface_name' : 'org.openbmc.control.Chassis'
+	},
+	'settings' : {
+		'bus_name' : 'org.openbmc.settings.Host',
+		'object_name' : '/org/openbmc/settings/host0',
+		'interface_name' : 'org.freedesktop.DBus.Properties'
+	},
+}
+
+def getInterface(bus,objs,key):
+	obj = bus.get_object(objs[key]['bus_name'],objs[key]['object_name'],introspect=False)
+	return dbus.Interface(obj,objs[key]['interface_name'])
+
+def getProperty(bus,objs,key,prop):
+	obj = bus.get_object(objs[key]['bus_name'],objs[key]['object_name'],introspect=False)
+	intf = dbus.Interface(obj,dbus.PROPERTIES_IFACE)
+	return intf.Get(objs[key]['interface_name'],prop)
+
+
+bus = dbus.SystemBus()
+pgood = getProperty(bus,dbus_objects,'power','pgood')
+
+if (pgood == 1):
+	intf = getInterface(bus,dbus_objects,'bootprogress')
+	intf.setValue("FW Progress, Starting OS")
+	intf = getInterface(bus,dbus_objects,'occstatus0')
+	intf.setValue("Enabled")
+	intf = getInterface(bus,dbus_objects,'occstatus1')
+	intf.setValue("Enabled")
+else:
+	## Power is off, so check power policy
+	settings_intf = getInterface(bus,dbus_objects,'settings')
+	system_state = settings_intf.Get("org.openbmc.settings.Host","system_state")
+	power_policy = settings_intf.Get("org.openbmc.settings.Host","power_policy")
+
+	print "Last System State: "+system_state+";  Power Policy: "+power_policy
+	chassis_intf = getInterface(bus,dbus_objects,'chassis')
+	if (power_policy == "ALWAYS_POWER_ON" or
+	   (power_policy == "RESTORE_LAST_STATE" and 
+	    system_state =="HOST_POWERED_ON")):
+		chassis_intf.powerOn()
+
+
diff --git a/pystatemgr/goto_system_state.py b/pystatemgr/goto_system_state.py
new file mode 100644
index 0000000..4efa1c6
--- /dev/null
+++ b/pystatemgr/goto_system_state.py
@@ -0,0 +1,61 @@
+#!/usr/bin/env python
+
+# Contributors Listed Below - COPYRIGHT 2016
+# [+] International Business Machines Corp.
+#
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# permissions and limitations under the License.
+
+import sys
+import subprocess
+import dbus
+import dbus.service
+import dbus.mainloop.glib
+import gobject
+
+
+class Goto(dbus.service.Object):
+    def __init__(self, connection, path, loop, state, cmdline):
+        super(Goto, self).__init__(connection, path)
+        self.loop = loop
+        self.state = state
+        self.cmdline = cmdline
+        gobject.idle_add(self.go)
+
+    def go(self):
+        if self.cmdline:
+            subprocess.call(self.cmdline)
+
+        if self.state:
+            self.GotoSystemState(self.state)
+
+        self.loop.quit()
+
+    @dbus.service.signal('org.openbmc.Control', signature='s')
+    def GotoSystemState(self, state):
+        pass
+
+if __name__ == '__main__':
+    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+    bus = dbus.SystemBus()
+    cmdline = None
+    state = None
+
+    if len(sys.argv) > 1:
+        state = sys.argv[1]
+    if len(sys.argv) > 2:
+        cmdline = sys.argv[2:]
+
+    loop = gobject.MainLoop()
+    o = Goto(bus, '/org/openbmc/goto', loop, state, cmdline)
+    loop.run()
diff --git a/pystatemgr/setup.cfg b/pystatemgr/setup.cfg
new file mode 120000
index 0000000..29939b5
--- /dev/null
+++ b/pystatemgr/setup.cfg
@@ -0,0 +1 @@
+../setup.cfg
\ No newline at end of file
diff --git a/pystatemgr/setup.py b/pystatemgr/setup.py
new file mode 100644
index 0000000..86c7471
--- /dev/null
+++ b/pystatemgr/setup.py
@@ -0,0 +1,6 @@
+from distutils.core import setup
+
+setup(name='pystatemgr',
+      version='1.0',
+      scripts=['discover_system_state.py', 'goto_system_state.py'],
+      )