python: reformat using black
Code cannot currently be submitted to this repo because it fails
in the unit-test phase. Attempt to reformat the code using `black`
to hopefully make pycodestyle happier.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I17aa506471ceade224bcab5b2fa0dc8cd7a88c0a
diff --git a/pyinventorymgr/inventory_items.py b/pyinventorymgr/inventory_items.py
index 168e3d6..1c0a5f7 100644
--- a/pyinventorymgr/inventory_items.py
+++ b/pyinventorymgr/inventory_items.py
@@ -2,6 +2,7 @@
import os
import sys
+
# TODO: openbmc/openbmc#2994 remove python 2 support
try: # python 2
import gobject
@@ -14,81 +15,76 @@
from obmc.dbuslib.bindings import get_dbus, DbusProperties, DbusObjectManager
-INTF_NAME = 'org.openbmc.InventoryItem'
-DBUS_NAME = 'org.openbmc.Inventory'
+INTF_NAME = "org.openbmc.InventoryItem"
+DBUS_NAME = "org.openbmc.Inventory"
FRUS = {}
class Inventory(DbusProperties, DbusObjectManager):
def __init__(self, bus, name):
- super(Inventory, self).__init__(
- conn=bus,
- object_path=name)
+ super(Inventory, self).__init__(conn=bus, object_path=name)
class InventoryItem(DbusProperties):
def __init__(self, bus, name, data):
- super(InventoryItem, self).__init__(
- conn=bus,
- object_path=name)
+ super(InventoryItem, self).__init__(conn=bus, object_path=name)
self.name = name
- if 'present' not in data:
- data['present'] = 'False'
- if 'fault' not in data:
- data['fault'] = 'False'
- if 'version' not in data:
- data['version'] = ''
+ if "present" not in data:
+ data["present"] = "False"
+ if "fault" not in data:
+ data["fault"] = "False"
+ if "version" not in data:
+ data["version"] = ""
self.SetMultiple(INTF_NAME, data)
# this will load properties from cache
PropertyCacher.load(name, INTF_NAME, self.properties)
- @dbus.service.method(
- INTF_NAME, in_signature='a{sv}', out_signature='')
+ @dbus.service.method(INTF_NAME, in_signature="a{sv}", out_signature="")
def update(self, data):
self.SetMultiple(INTF_NAME, data)
PropertyCacher.save(self.name, INTF_NAME, self.properties)
- @dbus.service.method(
- INTF_NAME, in_signature='s', out_signature='')
+ @dbus.service.method(INTF_NAME, in_signature="s", out_signature="")
def setPresent(self, present):
- self.Set(INTF_NAME, 'present', present)
+ self.Set(INTF_NAME, "present", present)
PropertyCacher.save(self.name, INTF_NAME, self.properties)
- @dbus.service.method(
- INTF_NAME, in_signature='s', out_signature='')
+ @dbus.service.method(INTF_NAME, in_signature="s", out_signature="")
def setFault(self, fault):
- self.Set(INTF_NAME, 'fault', fault)
+ self.Set(INTF_NAME, "fault", fault)
PropertyCacher.save(self.name, INTF_NAME, self.properties)
def getVersion():
version = "Error"
- with open('/etc/os-release', 'r') as f:
+ with open("/etc/os-release", "r") as f:
for line in f:
- p = line.rstrip('\n')
- parts = line.rstrip('\n').split('=')
- if (parts[0] == "VERSION_ID"):
+ p = line.rstrip("\n")
+ parts = line.rstrip("\n").split("=")
+ if parts[0] == "VERSION_ID":
version = parts[1]
version = version.strip('"')
return version
-if __name__ == '__main__':
+if __name__ == "__main__":
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = get_dbus()
mainloop = gobject.MainLoop()
- obj_parent = Inventory(bus, '/org/openbmc/inventory')
- INVENTORY_FILE = os.path.join(sys.prefix, 'share',
- 'inventory', 'inventory.json')
+ obj_parent = Inventory(bus, "/org/openbmc/inventory")
+ INVENTORY_FILE = os.path.join(
+ sys.prefix, "share", "inventory", "inventory.json"
+ )
if os.path.exists(INVENTORY_FILE):
import json
- with open(INVENTORY_FILE, 'r') as f:
+
+ with open(INVENTORY_FILE, "r") as f:
try:
inv = json.load(f)
except ValueError:
@@ -98,21 +94,23 @@
else:
try:
import obmc_system_config as System
+
FRUS = System.FRU_INSTANCES
except ImportError:
pass
for f in list(FRUS.keys()):
import obmc.inventory
+
obj_path = f.replace("<inventory_root>", obmc.inventory.INVENTORY_ROOT)
obj = InventoryItem(bus, obj_path, FRUS[f])
obj_parent.add(obj_path, obj)
# TODO: this is a hack to update bmc inventory item with version
# should be done by flash object
- if (FRUS[f]['fru_type'] == "BMC"):
+ if FRUS[f]["fru_type"] == "BMC":
version = getVersion()
- obj.update({'version': version})
+ obj.update({"version": version})
obj_parent.unmask_signals()
name = dbus.service.BusName(DBUS_NAME, bus)