1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
import dbus
import xml.etree.ElementTree as ET
BUS_PREFIX = 'org.openbmc'
GPIO_DEV = '/sys/class/gpio'
FRU_TYPES = {
'CPU' : 1,
'DIMM' : 2,
'BACKPLANE' : 3,
'RISER_CARD' : 4,
'FAN' : 5
}
ENUMS = {
'org.openbmc.SensorIntegerThreshold.state' :
['NOT_SET','NORMAL','LOWER_CRITICAL','LOWER_WARNING','UPPER_WARNING','UPPER_CRITICAL'],
'org.openbmc.Fru.type' :
['NONE','CPU','DIMM','BACKPLANE','RISER_CARD','FAN']
}
def object_to_bus_name(obj):
parts = obj.split('/')
parts.pop(0)
parts.pop()
return ".".join(parts)
def bus_to_object_name(bus_name):
return "/"+bus_name.replace('.','/')
def get_methods(obj):
methods = {}
introspect_iface = dbus.Interface(obj,"org.freedesktop.DBus.Introspectable")
tree = ET.ElementTree(ET.fromstring(introspect_iface.Introspect()))
root = tree.getroot()
for intf in root.iter('interface'):
intf_name = intf.attrib['name']
if (intf_name.find(BUS_PREFIX)==0):
methods[intf_name] = {}
for method in intf.iter('method'):
methods[intf_name][method.attrib['name']] = True
return methods
class DbusProperty:
def __init__(self,name,value):
self.dbusBaseType = {
'dbus.Byte' : 'int',
'dbus.Double' : 'float',
'dbus.Int32' : 'int',
'dbus.UInt32' : 'long',
'dbus.String' : 'str',
'dbus.UInt64' : 'long',
}
self.name = str(name)
self.dbusType = str(type(value)).split("'")[1]
self.variant_level = value.variant_level
self.value = None
try:
self.value = eval(self.dbusBaseType[self.dbusType]+"(value)")
except:
raise Exception("Unknown dbus type: "+self.dbusType)
def setValue(self,value):
try:
self.value = eval(self.dbusBaseType[self.dbusType]+"(value)")
except:
raise Exception("Unknown dbus type: "+self.dbusType)
def setVariant(self,variant_level):
self.variant_level = variant_level
def getName(self):
return self.name
def getValue(self):
e = self.dbusType+"(self.value, variant_level="+str(self.variant_level)+")"
return eval(e)
#def __getstate__(self):
# odict = self.__dict__.copy() # copy the dict since we change it
# return odict
##def __setstate__(self, dict):
# self.__dict__.update(dict) # update attributes
def __str__(self):
return self.dbusType+":"+str(self.value)
|