1
0
mirror of https://github.com/vcrhonek/hwdata synced 2025-10-14 02:43:35 +08:00

Add script to process CSV PNP list

The new CSV format of the PNP UEFI export includes trailing spaces in
few ID stringss, which thus end up in the generated pnp.ids file.
This may potentially break readers of pnp.ids, which will not get
exactly a 3-length string after splitting by Tab.

To solve the problem, introduce a simply helper Python script to process
the CSV UEFI file, trimming both the ID and also the company name (few
had trailing spaces).
This commit is contained in:
Pino Toscano
2023-12-04 09:56:32 +01:00
committed by Vitezslav Crhonek
parent 7c46440af0
commit fee5fd22f5
2 changed files with 36 additions and 1 deletions

View File

@@ -142,7 +142,7 @@ iab.txt: iab.txt.utf8
dos2unix -n $? $@
pnp.ids.orig: pnp.ids.csv
tail -n +2 $? | csvtool format '%(2)\t%(1)\n' - | sort -u >$@
./process-pnp-ids.py $? $@
pnp.ids: pnp.ids.orig pnp.ids.patch
patch -p1 -o $@ pnp.ids.orig pnp.ids.patch

35
process-pnp-ids.py Executable file
View File

@@ -0,0 +1,35 @@
#!/usr/bin/env python3
import argparse
import csv
import sys
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Process UEFI CSV output.")
parser.add_argument(
"csv_file", metavar="INPUT", type=argparse.FileType("r"), help="input CSV file"
)
parser.add_argument(
"output_file", metavar="OUTPUT", type=argparse.FileType("w"), help="output file"
)
args = parser.parse_args()
output_lines = []
reader = csv.DictReader(args.csv_file)
for row in reader:
if len(row) != 3:
print(f"Invalid line: {row}", file=sys.stderr)
continue
pnp_id = row["PNP ID"].strip()
company_name = row["Company"].strip()
if len(pnp_id) != 3:
print(f"PNP ID: {pnp_id}", file=sys.stderr)
continue
output_lines.append(f"{pnp_id}\t{company_name}\n")
output_lines.sort(key=str.lower)
for line in output_lines:
args.output_file.write(line)