summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.go43
-rw-r--r--d1pkgweb.go48
-rw-r--r--deb822/package.go12
3 files changed, 76 insertions, 27 deletions
diff --git a/config.go b/config.go
new file mode 100644
index 0000000..c71d287
--- /dev/null
+++ b/config.go
@@ -0,0 +1,43 @@
+package main
+
+import (
+ "gopkg.in/yaml.v2"
+ "io/ioutil"
+ "log"
+)
+
+type CompCfg struct {
+ Name string `yaml:"Name"`
+ URL string `yaml:"URL"`
+}
+
+type Suite struct {
+ Name string `yaml:"Name"`
+ Components []CompCfg `yaml:"Components"`
+}
+
+type ReleaseCfg struct {
+ Release string `yaml:"Release"`
+ RepoURL string `yaml:"RepoURL"`
+ Suites []Suite `yaml:"Suites"`
+}
+
+type PkgwebCfg struct {
+ PkgSets []ReleaseCfg `yaml:"PkgSets"`
+}
+
+func readConfig(fname string) *PkgwebCfg {
+
+ data, err := ioutil.ReadFile(fname)
+ if err != nil {
+ log.Fatal("Error while reading file: ", err)
+ }
+
+ cfg := new(PkgwebCfg)
+
+ err = yaml.Unmarshal(data, cfg)
+ if err != nil {
+ log.Fatal("Error while reading configuration: ", err)
+ }
+ return cfg
+}
diff --git a/d1pkgweb.go b/d1pkgweb.go
index 89fa764..09fe675 100644
--- a/d1pkgweb.go
+++ b/d1pkgweb.go
@@ -2,10 +2,11 @@ package main
import (
"bufio"
+ "compress/gzip"
"d1pkgweb/deb822"
"fmt"
+ "net/http"
"os"
- "strings"
)
func main() {
@@ -17,29 +18,34 @@ func main() {
return
}
- fnames := args[1:]
- for _, fname := range fnames {
- nameComps := strings.Split(fname, "_")
- suite := nameComps[3]
- component := nameComps[4]
- f, err := os.Open(fname)
- if err != nil {
- defer f.Close()
- }
- if err != nil {
- fmt.Printf("Error opening file %s\n", fname)
+ confFile := args[1]
+ conf := readConfig(confFile)
- } else {
- r := bufio.NewScanner(f)
+ //fmt.Printf("Got config: %s\n", *conf)
- if r != nil {
- for s, err := deb822.ScanStanza(r); s["Package"] != ""; s, err = deb822.ScanStanza(r) {
- if err == nil {
- deb822.Stanza2HtmlPage(s, pkgTempl, ".", suite, component)
- } else {
- fmt.Printf("error: %s\n", err)
+ for _, relCfg := range conf.PkgSets { // For each release...
+ for _, suiteCfg := range relCfg.Suites { // For each suite of the release
+ suite := 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, ".", suite, component.Name)
+ } else {
+ fmt.Printf("error: %s\n", err)
+ }
}
- //WriteFiles(s, num, "./files/")
}
}
}
diff --git a/deb822/package.go b/deb822/package.go
index 9eae85c..41a9613 100644
--- a/deb822/package.go
+++ b/deb822/package.go
@@ -92,23 +92,23 @@ func Stanza2HtmlPage(s Stanza, templ string, baseDir string, suite string, compo
log.Fatal("empty package!!!")
}
nameVersion := fmt.Sprintf("%s_%s", p.Name, p.Version)
- fmt.Printf(" nameVersion: %s\n", nameVersion)
- fmt.Printf(" baseDir: %s\n", baseDir)
+ //fmt.Printf(" nameVersion: %s\n", nameVersion)
+ //fmt.Printf(" baseDir: %s\n", baseDir)
fname = regexpRemove.ReplaceAllString(fname, "")
- fmt.Printf(" fname: %s\n", fname)
+ //fmt.Printf(" fname: %s\n", fname)
/// FIXME!!!! ERROR IN DETECTION OF PACKAGE NAME!!!!
dirName := fmt.Sprintf("%s/%s", baseDir, strings.Split(fname, nameVersion)[0])
err = os.MkdirAll(dirName, 0755)
if err == nil {
- fmt.Printf(" dirName: %s\n Package: %s\n Version: %s\n", dirName, p.Name, p.Version)
+ //fmt.Printf(" dirName: %s\n Package: %s\n Version: %s\n", dirName, p.Name, p.Version)
htmlFile := fmt.Sprintf("%s%s_%s.html", dirName, p.Name, p.Version)
- fmt.Printf("Creating file: %s\n---------\n", htmlFile)
+ //fmt.Printf("Creating file: %s\n---------\n", htmlFile)
if f, err := os.Open(htmlFile); err == nil {
f.Close()
- fmt.Printf("File %s exists -- skipping\n", htmlFile)
+ fmt.Fprintf(os.Stderr, " Skipping %s -- it exists\n", htmlFile)
return err
}
file, err := os.Create(htmlFile)