summaryrefslogtreecommitdiff
path: root/d1pkgweb.go
blob: 4fde25710bc842e3211c363fb3f7d6057b1a0007 (plain)
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
package main

import (
	"bufio"
	"compress/gzip"
	"d1pkgweb/deb822"
	"fmt"
	"net/http"
	"os"
)

func processSuite(suiteCfg SuiteCfg, relCfg ReleaseCfg, baseDir string, result chan error) {

	relName := relCfg.Release
	suiteName := suiteCfg.Name
	for _, component := range suiteCfg.Components { // For each component in the suite
		fullURL := fmt.Sprintf("%s/%s", relCfg.RepoURL, component.URL)
		fmt.Fprintf(os.Stderr, "Processing: %s\n", fullURL)
		f, err := http.Get(fullURL)
		if err != nil {
			fmt.Fprintf(os.Stderr, "...Ignoring %s\n", fullURL)
		} else {
			uncompressed, err := gzip.NewReader(f.Body)
			if err != nil {
				fmt.Fprintf(os.Stderr, "error uncompressing %s\n", fullURL)
				continue
			}
			r := bufio.NewScanner(uncompressed)
			for s, err := deb822.ScanStanza(r); s["Package"] != ""; s, err = deb822.ScanStanza(r) {
				if err == nil {
					deb822.Stanza2HtmlPage(s, pkgTempl, baseDir, relName, suiteName, component.Name)
				} else {
					fmt.Printf("error: %s\n", err)
				}
			}
		}
	}
	result <- nil
}

func processRelease(relCfg ReleaseCfg, baseDir string, result chan error) {

	children := make(chan error)
	numWorkers := 0

	for _, suiteCfg := range relCfg.Suites { // For each suite in the release, run a processSuite
		numWorkers++
		go processSuite(suiteCfg, relCfg, baseDir, children)
	}

	for {
		<-children
		numWorkers--
		if numWorkers == 0 {
			break
		}
	}
	result <- nil
	return
}

func main() {

	args := os.Args

	if len(args) < 2 {
		fmt.Printf("Usage: %s <filein>\n", args[0])
		return
	}

	confFile := args[1]
	conf := readConfig(confFile)

	children := make(chan error)
	numWorkers := 0

	for _, relCfg := range conf.PkgSets { // For each release, run a new processRelease...
		numWorkers++
		go processRelease(relCfg, ".", children)
	}

	for {
		<-children
		numWorkers--
		if numWorkers == 0 {
			fmt.Fprintf(os.Stderr, "Exiting from main....")
			break
		}
	}
}