diff options
author | CamVan Nguyen <ctnguyen@us.ibm.com> | 2018-02-27 15:18:58 -0600 |
---|---|---|
committer | CamVan Nguyen <ctnguyen@us.ibm.com> | 2018-03-12 13:20:20 -0500 |
commit | 9172f3e7a0fd5c7cd53160391640fab29ea5f051 (patch) | |
tree | afd06a8a388a5e4f9e93a0335b61708a0168026e | |
parent | d67740e7167dd2b40c4263c5fd94e874a6a91693 (diff) | |
download | pyphosphor-9172f3e7a0fd5c7cd53160391640fab29ea5f051.tar.gz pyphosphor-9172f3e7a0fd5c7cd53160391640fab29ea5f051.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.
Change-Id: I564824b00c106a2c7ebd2f4a9607cd01eabf1322
Signed-off-by: CamVan Nguyen <ctnguyen@us.ibm.com>
-rw-r--r-- | obmc/dbuslib/bindings.py | 4 | ||||
-rw-r--r-- | obmc/dbuslib/introspection.py | 2 | ||||
-rw-r--r-- | obmc/dbuslib/propertycacher.py | 23 | ||||
-rw-r--r-- | obmc/sensors.py | 8 |
4 files changed, 21 insertions, 16 deletions
diff --git a/obmc/dbuslib/bindings.py b/obmc/dbuslib/bindings.py index 3eea6a5..8a04447 100644 --- a/obmc/dbuslib/bindings.py +++ b/obmc/dbuslib/bindings.py @@ -187,7 +187,7 @@ class DbusObjectManager(dbus.service.Object): obj = self.objects.pop(object_path, None) obj.remove_from_connection() if self._export: - self.InterfacesRemoved(object_path, obj.properties.keys()) + self.InterfacesRemoved(object_path, list(obj.properties.keys())) def get(self, object_path, default=None): return self.objects.get(object_path, default) @@ -197,7 +197,7 @@ class DbusObjectManager(dbus.service.Object): in_signature='', out_signature='a{oa{sa{sv}}}') def GetManagedObjects(self): data = {} - for objpath in self.objects.keys(): + for objpath in list(self.objects.keys()): data[objpath] = self.objects[objpath].properties return data diff --git a/obmc/dbuslib/introspection.py b/obmc/dbuslib/introspection.py index 9ec9c05..5288bcb 100644 --- a/obmc/dbuslib/introspection.py +++ b/obmc/dbuslib/introspection.py @@ -104,7 +104,7 @@ class IntrospectionParser: def _discover_flat(self, path, parser): items = {} - interfaces = parser.get_interfaces().keys() + interfaces = list(parser.get_interfaces().keys()) if interfaces: items[path] = {} items[path]['interfaces'] = interfaces diff --git a/obmc/dbuslib/propertycacher.py b/obmc/dbuslib/propertycacher.py index 7888b46..875b164 100644 --- a/obmc/dbuslib/propertycacher.py +++ b/obmc/dbuslib/propertycacher.py @@ -15,7 +15,12 @@ # permissions and limitations under the License. import os -import cPickle +# TODO: openbmc/openbmc#2994 remove python 2 support +import sys +if sys.version_info[0] < 3: + import cPickle as pickle +else: + import pickle import json CACHE_PATH = '/var/cache/obmc/' @@ -28,7 +33,7 @@ def getCacheFilename(obj_path, iface_name): def save(obj_path, iface_name, properties): - print "Caching: "+obj_path + print("Caching: "+obj_path) filename = getCacheFilename(obj_path, iface_name) parent = os.path.dirname(filename) try: @@ -39,11 +44,11 @@ def save(obj_path, iface_name, properties): ## use json module to convert dbus datatypes props = json.dumps(properties[iface_name]) prop_obj = json.loads(props) - cPickle.dump(prop_obj, output) + pickle.dump(prop_obj, output) except Exception as e: - print "ERROR: "+str(e) + print("ERROR: "+str(e)) except: - print "ERROR opening cache file: "+filename + print("ERROR opening cache file: "+filename) def load(obj_path, iface_name, properties): @@ -52,14 +57,14 @@ def load(obj_path, iface_name, properties): if (os.path.isfile(filename)): if iface_name in properties: properties[iface_name] = {} - print "Loading from cache: "+filename + print("Loading from cache: "+filename) try: p = open(filename, 'rb') - data = cPickle.load(p) - for prop in data.keys(): + data = pickle.load(p) + for prop in list(data.keys()): properties[iface_name][prop] = data[prop] except Exception as e: - print "ERROR: Loading cache file: " + str(e) + print("ERROR: Loading cache file: " + str(e)) finally: p.close() diff --git a/obmc/sensors.py b/obmc/sensors.py index ca48525..e61ddac 100644 --- a/obmc/sensors.py +++ b/obmc/sensors.py @@ -91,7 +91,7 @@ class BootCountSensor(VirtualSensor): @dbus.service.method( SensorValue.IFACE_NAME, in_signature='v', out_signature='') def setValue(self, value): - print "Setting boot count to " + str(value) + print("Setting boot count to " + str(value)) SensorValue.setValue(self, value) @@ -129,7 +129,7 @@ class PowerSupplyRedundancySensor(VirtualSensor): intf = self.getPowerSupplyInterface() intf.Set(self.iface, self.property_name, False) else: - print "Invalid Power Supply Redundancy value" + print("Invalid Power Supply Redundancy value") return super(PowerSupplyRedundancySensor, self).setValue(value) @@ -144,7 +144,7 @@ class PowerSupplyRedundancySensor(VirtualSensor): elif (value == 0): return "Disabled" else: - print "Unable to determine Power Supply Redundancy value" + print("Unable to determine Power Supply Redundancy value") return "" def getPowerSupplyInterface(self): @@ -162,7 +162,7 @@ class PowerSupplyDeratingSensor(VirtualSensor): @dbus.service.method( SensorValue.IFACE_NAME, in_signature='v', out_signature='') def setValue(self, value): - print "Setting Power Supply Derating is not allowed" + print("Setting Power Supply Derating is not allowed") class TurboAllowedSensor(VirtualSensor): |