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