1 import ConfigParser
# knm config
4 import dbus
# maybe reduce deps and postprocess dbus.Byte?
7 "Parse ~/.kde/share/config/knetworkmanagerrc"
10 p
= ConfigParser
.RawConfigParser()
11 ok
= p
.read(os
.getenv("HOME") + "/.kde/share/config/knetworkmanagerrc")
14 for s
in p
.sections():
17 if path
[0] in ["ConnectionSetting", "ConnectionSecrets"]:
19 self
.conmaps_d
.setdefault(cid
, {})
23 for (n
, v
) in p
.items(s
):
24 # WTF, Value_ is transformed to value_
27 v
= self
.ParseValue(v
)
28 #print "# %s:%s" % (n, v)
29 # do not overwrite ConnectionSecrets
30 # with empty ConnectionSettings field
32 vv
= self
.conmaps_d
[cid
][part
][n
]
37 if len(values
) != 0: # empty 802-1x confuses NM!?
38 self
.conmaps_d
[cid
].setdefault(part
, {})
39 self
.conmaps_d
[cid
][part
].update(**values
)
40 #print "PARSED", cid, part, values
43 return self
.conmaps_d
.values()
45 def ParseValue(self
, v
):
46 v
= eval('"%s"' % v
) # unescape backslashes
47 dom
= xml
.dom
.minidom
.parseString(v
)
48 return self
.ParseNode(dom
.documentElement
)
50 def ParseNode(self
, n
):
58 return dbus
.Byte(int(v
))
61 elif t
== "int32" or t
== "uint32":
67 if c
.localName
!= None: # whitespace
68 v
.append(self
.ParseNode(c
))
72 def NodeText(self
, n
):
74 return n
.firstChild
.wholeText