-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pnp_gen.go
109 lines (94 loc) · 2.14 KB
/
pnp_gen.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//go:build generate
//go:generate go run pnp_gen.go
package main
import (
"encoding/csv"
"errors"
"fmt"
"io"
"log"
"net/http"
"os"
"strings"
"text/template"
"time"
)
func main() {
// https://uefi.org/PNP_ID_List?search=&order=field_pnp_id&sort=asc&page=1
resp, err := http.Get(`https://uefi.org/uefi-pnp-export`)
if err != nil {
log.Fatal(err)
}
rdr := csv.NewReader(resp.Body)
rdr.FieldsPerRecord = 3
rdr.LazyQuotes = true
pnpEntries := make(map[PNPID]*PNPEntry)
isFirst := true
for {
rec, err := rdr.Read()
if errors.Is(err, io.EOF) {
break
}
if err != nil {
log.Fatal(err)
}
if isFirst {
isFirst = false
continue
}
if len(rec) != 3 {
log.Fatal(errors.New(`column count is not 3`))
}
id, err := NewPNPID(rec[1])
if err != nil {
log.Fatal(err)
}
entry := &PNPEntry{
Company: rec[0],
DateOfApproval: rec[2],
}
pnpEntries[id] = entry
}
tmpl := "// Code generated by \"pnp_gen.go\" DO NOT EDIT.\n\n" +
"// Entries were copied from `https://uefi.org/uefi-pnp-export on " + time.Now().Format(`2006.01.02`) + ".\n\n" +
"package edid\n\n" +
"var pnpIDEntries = map[string]PNPEntry{\n{{range $id, $val := .}}\t`{{$id}}`: {" + /*"ID: `{{$id}}`, "+*/ "DateOfApproval: `{{$val.DateOfApproval}}`, Company: `{{$val.Company}}`},\n{{end}}}\n"
t := template.Must(template.New("tmpl").Parse(tmpl))
f, err := os.OpenFile(`pnpids.go`, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
log.Fatal(err)
}
defer f.Close()
t.Execute(f, pnpEntries)
/*
for id, entry := range pnpEntries {
fmt.Println(id, entry.DateOfApproval, entry.Company)
}
*/
}
type PNPEntry struct {
ID string
DateOfApproval string
Company string
}
type PNPID [3]byte
func NewPNPID(s string) (PNPID, error) {
var ret PNPID
// ARMSTEL, Inc. AMS 02/25/2011
// AMS ends with '\u00a0' ('NO-BREAK SPACE')
s = strings.TrimSpace(s)
if len(s) != 3 {
fmt.Printf("%q\n", s)
return ret, errors.New(`id char length is not 3`)
}
copy(ret[:], s[:3])
/*
non-upper case ids:
Vision Quest VQ@
Inovatec S.p.A. inu
*/
return ret, nil
}
func (p PNPID) String() string {
return string(p[:])
}