summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.go8
-rw-r--r--d1pkgweb.go91
2 files changed, 69 insertions, 30 deletions
diff --git a/config.go b/config.go
index c71d287..72a5665 100644
--- a/config.go
+++ b/config.go
@@ -11,15 +11,15 @@ type CompCfg struct {
URL string `yaml:"URL"`
}
-type Suite struct {
+type SuiteCfg struct {
Name string `yaml:"Name"`
Components []CompCfg `yaml:"Components"`
}
type ReleaseCfg struct {
- Release string `yaml:"Release"`
- RepoURL string `yaml:"RepoURL"`
- Suites []Suite `yaml:"Suites"`
+ Release string `yaml:"Release"`
+ RepoURL string `yaml:"RepoURL"`
+ Suites []SuiteCfg `yaml:"Suites"`
}
type PkgwebCfg struct {
diff --git a/d1pkgweb.go b/d1pkgweb.go
index b8b048f..d78f004 100644
--- a/d1pkgweb.go
+++ b/d1pkgweb.go
@@ -9,6 +9,57 @@ import (
"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) {
+
+ c := make(chan error)
+ numWorkers := 0
+
+ for _, suiteCfg := range relCfg.Suites { // For each suite of the release
+ numWorkers++
+ go processSuite(suiteCfg, relCfg, baseDir, c)
+ }
+
+ select {
+ case e := <-c:
+ numWorkers--
+ if numWorkers == 0 {
+ result <- e
+ return
+ }
+ }
+ result <- nil
+ return
+}
+
func main() {
args := os.Args
@@ -21,34 +72,22 @@ func main() {
confFile := args[1]
conf := readConfig(confFile)
- //fmt.Printf("Got config: %s\n", *conf)
+ c := make(chan error)
+ numWorkers := 0
for _, relCfg := range conf.PkgSets { // For each release...
- relName := relCfg.Release
- for _, suiteCfg := range relCfg.Suites { // For each suite of the 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, ".", relName, suiteName, component.Name)
- } else {
- fmt.Printf("error: %s\n", err)
- }
- }
- }
- }
+ numWorkers++
+ go processRelease(relCfg, ".", c)
+ }
+ var err = make([]error, numWorkers)
+
+ select {
+ case e := <-c:
+ numWorkers--
+ err[numWorkers] = e
+ if numWorkers == 0 {
+ fmt.Fprintf(os.Stderr, "Exiting from main....")
+ os.Exit(0)
}
}
}