summaryrefslogtreecommitdiffstats
path: root/pychassisctl
diff options
context:
space:
mode:
authorCamVan Nguyen <ctnguyen@us.ibm.com>2018-02-27 15:14:41 -0600
committerCamVan Nguyen <ctnguyen@us.ibm.com>2018-03-12 12:44:32 -0500
commitd65b2d501ba69c8371634ffc4907d85dc614074f (patch)
treeae19a691b1a4659a2a08423f36e5d2766c73b2ad /pychassisctl
parentc182e5ece4a7a4079c935d381ea787390cf0feb5 (diff)
downloadtalos-skeleton-d65b2d501ba69c8371634ffc4907d85dc614074f.tar.gz
talos-skeleton-d65b2d501ba69c8371634ffc4907d85dc614074f.zip
Port to python 3
Port code to python 3 yet remain backward compatible to python 2. This port is in preparation for yocto 2.4 upgrade. Partially resolves openbmc/openbmc#2920 Change-Id: If174ce9444bde4e21fb086764f4def017e423201 Signed-off-by: CamVan Nguyen <ctnguyen@us.ibm.com>
Diffstat (limited to 'pychassisctl')
-rw-r--r--pychassisctl/chassis_control.py26
1 files changed, 15 insertions, 11 deletions
diff --git a/pychassisctl/chassis_control.py b/pychassisctl/chassis_control.py
index 0abd422..2a6f175 100644
--- a/pychassisctl/chassis_control.py
+++ b/pychassisctl/chassis_control.py
@@ -1,6 +1,10 @@
#!/usr/bin/env python
-import gobject
+# TODO: openbmc/openbmc#2994 remove python 2 support
+try: # python 2
+ import gobject
+except ImportError: # python 3
+ from gi.repository import GObject as gobject
import dbus
import dbus.service
import dbus.mainloop.glib
@@ -27,9 +31,9 @@ class ChassisControlObject(DbusProperties, DbusObjectManager):
if (len(data) == 32):
uuid = data
else:
- print "ERROR: UUID is not formatted correctly: " + data
+ print("ERROR: UUID is not formatted correctly: " + data)
except Exception:
- print "ERROR: Unable to open uuid file: " + MACHINE_ID
+ print("ERROR: Unable to open uuid file: " + MACHINE_ID)
return uuid
@@ -86,7 +90,7 @@ class ChassisControlObject(DbusProperties, DbusObjectManager):
@dbus.service.method(DBUS_NAME,
in_signature='', out_signature='')
def powerOn(self):
- print "Turn on power and boot"
+ print("Turn on power and boot")
self.Set(DBUS_NAME, "reboot", 0)
intf = self.getInterface('systemd')
f = getattr(intf, 'StartUnit')
@@ -96,7 +100,7 @@ class ChassisControlObject(DbusProperties, DbusObjectManager):
@dbus.service.method(DBUS_NAME,
in_signature='', out_signature='')
def powerOff(self):
- print "Turn off power"
+ print("Turn off power")
intf = self.getInterface('systemd')
f = getattr(intf, 'StartUnit')
f.call_async('obmc-chassis-hard-poweroff@0.target', 'replace')
@@ -105,7 +109,7 @@ class ChassisControlObject(DbusProperties, DbusObjectManager):
@dbus.service.method(DBUS_NAME,
in_signature='', out_signature='')
def softPowerOff(self):
- print "Soft off power"
+ print("Soft off power")
intf = self.getInterface('systemd')
f = getattr(intf, 'StartUnit')
f.call_async('obmc-host-shutdown@0.target', 'replace')
@@ -114,7 +118,7 @@ class ChassisControlObject(DbusProperties, DbusObjectManager):
@dbus.service.method(DBUS_NAME,
in_signature='', out_signature='')
def reboot(self):
- print "Rebooting"
+ print("Rebooting")
if self.getPowerState() == POWER_OFF:
self.powerOn()
else:
@@ -125,7 +129,7 @@ class ChassisControlObject(DbusProperties, DbusObjectManager):
@dbus.service.method(DBUS_NAME,
in_signature='', out_signature='')
def softReboot(self):
- print "Soft Rebooting"
+ print("Soft Rebooting")
if self.getPowerState() == POWER_OFF:
self.powerOn()
else:
@@ -158,14 +162,14 @@ class ChassisControlObject(DbusProperties, DbusObjectManager):
self.softPowerOff()
def long_power_button_signal_handler(self):
- print "Long-press button, hard power off"
+ print("Long-press button, hard power off")
self.powerOff()
def softreset_button_signal_handler(self):
self.softReboot()
def host_watchdog_signal_handler(self):
- print "Watchdog Error, Going to quiesce"
+ print("Watchdog Error, Going to quiesce")
self.quiesce()
@@ -179,7 +183,7 @@ if __name__ == '__main__':
obj.unmask_signals()
name = dbus.service.BusName(DBUS_NAME, bus)
- print "Running ChassisControlService"
+ print("Running ChassisControlService")
mainloop.run()
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
OpenPOWER on IntegriCloud