Debian Codegraph @

util/convert_hwdb_to_pnp_ids.py

raw
1 #!/usr/bin/env python
2 import codecs
3 import os
4 import sys
5
6
7 pnpidcache = {}
8
9
10 def convert_hwdb_to_pnp_ids(hwdb_filename):
11 with codecs.open(hwdb_filename, "r", "UTF-8", "replace") as hwdb:
12 pnpid, name = None, None
13 for line in hwdb:
14 if line.strip().startswith("acpi:"):
15 pnpid = line.split(":")[1][:3]
16 continue
17 elif line.strip().startswith("ID_VENDOR_FROM_DATABASE"):
18 name = line.split("=", 1)[1].strip()
19 else:
20 continue
21 if not pnpid or not name or pnpid in pnpidcache:
22 continue
23 pnpidcache[pnpid] = name
24 if pnpidcache:
25 with codecs.open(
26 os.path.join(os.path.dirname(__file__), "..", "DisplayCAL", "pnp.ids"),
27 "w",
28 "UTF-8",
29 "replace",
30 ) as pnpids:
31 for item in sorted(pnpidcache.items()):
32 pnpids.write("%s\t%s\n" % item)
33
34
35 if __name__ == "__main__":
36 convert_hwdb_to_pnp_ids(sys.argv[1])