]> git.ipfire.org Git - thirdparty/systemd.git/blob - hwdb.d/acpi-update.py
Merge pull request #16344 from keszybz/update-utmp-erofs
[thirdparty/systemd.git] / hwdb.d / acpi-update.py
1 #!/usr/bin/env python3
2
3 from html.parser import HTMLParser
4 from enum import Enum
5
6 class State(Enum):
7 NOWHERE = 0
8 COMPANY = 1
9 AFTER_COMPANY = 2
10 PNPID = 3
11 AFTER_PNPID = 4
12 DATE = 5
13
14 class PNPTableParser(HTMLParser):
15
16 def __init__(self):
17 HTMLParser.__init__(self)
18 self.state = State.NOWHERE
19 self.data = ""
20 self.pnpid = None
21 self.company = None
22 self.table = []
23
24 def handle_starttag(self, tag, attrs):
25
26 if tag == "td":
27 if self.state == State.NOWHERE:
28 self.state = State.COMPANY
29 elif self.state == State.AFTER_COMPANY:
30 self.state = State.PNPID
31 elif self.state == State.AFTER_PNPID:
32 self.state = State.DATE
33 else:
34 raise ValueError
35
36 self.data = ""
37
38 def handle_endtag(self, tag):
39
40 if tag == "td":
41 if self.state == State.COMPANY:
42 self.company = ' '.join(self.data.strip().split())
43 self.state = State.AFTER_COMPANY
44 elif self.state == State.PNPID:
45 self.pnpid = self.data.strip()
46 self.state = State.AFTER_PNPID
47 self.table.append((self.pnpid, self.company))
48 elif self.state == State.DATE:
49 self.state = State.NOWHERE
50 else:
51 raise ValueError
52
53 def handle_data(self, data):
54 self.data += data
55
56 def read_table(a):
57
58 parser = PNPTableParser()
59
60 for line in a:
61 parser.feed(line)
62
63 parser.close()
64 parser.table.sort()
65
66 for pnpid, company in parser.table:
67 print("\nacpi:{0}*:\n ID_VENDOR_FROM_DATABASE={1}".format(pnpid, company))
68
69 a = open("acpi_id_registry.html")
70 b = open("pnp_id_registry.html")
71
72 print('# This file is part of systemd.\n'
73 '#\n'
74 '# Data imported from:\n'
75 '# https://uefi.org/uefi-pnp-export\n'
76 '# https://uefi.org/uefi-acpi-export')
77
78 read_table(a)
79 read_table(b)