status-to-html.go
 1  package main
 2  
 3  import (
 4  	"embed"
 5  	"errors"
 6  	"flag"
 7  	"fmt"
 8  	"html/template"
 9  	"io/fs"
10  	"os"
11  	"path/filepath"
12  )
13  
14  //go:embed templates
15  var templates embed.FS
16  
17  var data = TemplateData{
18  	Categories: []Category{
19  		"laptop",
20  		"server",
21  		"desktop",
22  		"half",
23  		"mini",
24  		"settop",
25  		"eval",
26  		"sbc",
27  		"emulation",
28  		"misc",
29  		"unclass",
30  	},
31  	CategoryNiceNames: map[Category]string{
32  		"desktop":   "Desktops / Workstations",
33  		"server":    "Servers",
34  		"laptop":    "Laptops",
35  		"half":      "Embedded / PC/104 / Half-size boards",
36  		"mini":      "Mini-ITX / Micro-ITX / Nano-ITX",
37  		"settop":    "Set-top-boxes / Thin clients",
38  		"eval":      "Devel/Eval Boards",
39  		"sbc":       "Single-Board computer",
40  		"emulation": "Emulation",
41  		"misc":      "Miscellaneous",
42  		"unclass":   "Unclassified",
43  	},
44  	BoardsByCategory: map[Category][]Board{},
45  }
46  
47  var (
48  	cbdirFS fs.FS
49  	cbdir   string
50  	bsdirFS fs.FS
51  )
52  
53  func main() {
54  	var cbDir, bsDir string
55  	flag.StringVar(&cbDir, "coreboot-dir", filepath.Join("..", "coreboot.git"), "coreboot.git checkout")
56  	flag.StringVar(&bsDir, "board-status-dir", filepath.Join("..", "board-status.git"), "board-status.git checkout")
57  	flag.Parse()
58  
59  	tpls, err := template.ParseFS(templates, filepath.Join("templates", "*"))
60  	if err != nil {
61  		fmt.Fprintf(os.Stderr, "Parsing templates failed: %v\n", err)
62  		os.Exit(1)
63  	}
64  
65  	if _, err := os.Stat(cbDir); errors.Is(err, os.ErrNotExist) {
66  		fmt.Fprintf(os.Stderr, "coreboot root %s does not exist\n", cbDir)
67  		os.Exit(1)
68  	}
69  
70  	if _, err := os.Stat(bsDir); errors.Is(err, os.ErrNotExist) {
71  		fmt.Fprintf(os.Stderr, "board-status dir %s does not exist\n", bsDir)
72  		os.Exit(1)
73  	}
74  
75  	cbdirFS = os.DirFS(cbDir)
76  	cbdir = cbDir
77  	bsdirFS = os.DirFS(bsDir)
78  
79  	dirs := make(chan NamedFS)
80  	go fetchLogs(dirs)
81  	collectLogs(dirs)
82  
83  	dirs = make(chan NamedFS)
84  	go fetchBoards(dirs)
85  	collectBoards(dirs)
86  
87  	err = tpls.ExecuteTemplate(os.Stdout, "board-status.html", data)
88  	if err != nil {
89  		fmt.Fprintf(os.Stderr, "Executing template failed: %v\n", err)
90  		os.Exit(1)
91  	}
92  }