summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2022-01-12 05:40:12 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2022-01-12 05:44:42 +0100
commit097f25fb007330cae1b36eb91312bad2db0f0cc9 (patch)
tree1eaa84da84d1763ddde60439b0ce510add350cc1
parentnetworking (diff)
downloadnspawn-097f25fb007330cae1b36eb91312bad2db0f0cc9.tar.gz
nspawn-097f25fb007330cae1b36eb91312bad2db0f0cc9.tar.xz
Remove python3.10 dependency for machined facts.
-rwxr-xr-xfacts.d/main.py63
1 files changed, 31 insertions, 32 deletions
diff --git a/facts.d/main.py b/facts.d/main.py
index 0db37f3..042052f 100755
--- a/facts.d/main.py
+++ b/facts.d/main.py
@@ -20,38 +20,37 @@ for (machine_name, *_) in machines:
out_dict = {}
for key, value in ii.GetAll('org.freedesktop.machine1.Machine').items():
# see help(dbus.types)
- match type(value):
- case dbus.ByteArray:
- raise NotImplementedError('Byte array')
- case dbus.Double:
- v = float(value)
- case dbus.Boolean:
- v = bool(value)
- case dbus.Byte | dbus.Int16 | dbus.Int32 | dbus.Int64 | dbus.UInt16 | dbus.UInt32 | dbus.UInt64:
- v = int(value)
- case dbus.ObjectPath | dbus.Signature:
- # string likes
- v = str(value)
- case dbus.Dictionary:
- # dict like
- raise NotImplementedError('Dictionary')
- case dbus.Array:
- match value.signature:
- case dbus.Signature('y'):
- v = bytes(int(x) for x in value)
- case dbus.Signature('i'):
- v = [int(x) for x in value]
- case _:
- print(repr(value))
- print(repr(value.signature))
- raise NotImplementedError('Array')
- # case dbus.UnixFd:
- # raise NotImplementedError()
- case dbus.String:
- v = str(value)
- case dbus.Struct:
- # tuple like
- raise NotImplementedError('Struct')
+ t = type(value)
+ if t == dbus.ByteArray:
+ raise NotImplementedError('Byte array')
+ elif t == dbus.Double:
+ v = float(value)
+ elif t == dbus.Boolean:
+ v = bool(value)
+ elif t in [ dbus.Byte, dbus.Int16, dbus.Int32, dbus.Int64, dbus.UInt16, dbus.UInt32, dbus.UInt64 ]:
+ v = int(value)
+ elif t in [ dbus.ObjectPath, dbus.Signature ]:
+ # string likes
+ v = str(value)
+ elif t == dbus.Dictionary:
+ # dict like
+ raise NotImplementedError('Dictionary')
+ elif t == dbus.Array:
+ if value.signature == dbus.Signature('y'):
+ v = bytes(int(x) for x in value)
+ elif value.signature == dbus.Signature('i'):
+ v = [int(x) for x in value]
+ else:
+ print(repr(value))
+ print(repr(value.signature))
+ raise NotImplementedError('Array')
+ # case dbus.UnixFd:
+ # raise NotImplementedError()
+ elif t == dbus.String:
+ v = str(value)
+ elif t == dbus.Struct:
+ # tuple like
+ raise NotImplementedError('Struct')
out_dict[str(key)] = v
machine_names.append(str(machine_name))
machines_info[str(machine_name)] = out_dict