From 097f25fb007330cae1b36eb91312bad2db0f0cc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Wed, 12 Jan 2022 05:40:12 +0100 Subject: Remove python3.10 dependency for machined facts. --- facts.d/main.py | 63 ++++++++++++++++++++++++++++----------------------------- 1 file 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 -- cgit v1.2.3