process-pnp-ids.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #!/usr/bin/env python3
  2. import argparse
  3. import csv
  4. import sys
  5. if __name__ == "__main__":
  6. parser = argparse.ArgumentParser(description="Process UEFI CSV output.")
  7. parser.add_argument(
  8. "csv_file", metavar="INPUT", type=argparse.FileType("r"), help="input CSV file"
  9. )
  10. parser.add_argument(
  11. "output_file", metavar="OUTPUT", type=argparse.FileType("w"), help="output file"
  12. )
  13. args = parser.parse_args()
  14. output_lines = []
  15. reader = csv.DictReader(args.csv_file)
  16. for row in reader:
  17. if len(row) != 3:
  18. print(f"Invalid line: {row}", file=sys.stderr)
  19. continue
  20. pnp_id = row["PNP ID"].strip()
  21. company_name = row["Company"].strip()
  22. if len(pnp_id) != 3:
  23. print(f"PNP ID: {pnp_id}", file=sys.stderr)
  24. continue
  25. if f"{pnp_id}\t{company_name}\n" not in output_lines:
  26. output_lines.append(f"{pnp_id}\t{company_name}\n")
  27. output_lines.sort(key=str.lower)
  28. for line in output_lines:
  29. args.output_file.write(line)