SF.net SVN: gar:[24753] csw/mgar/gar/v2/go

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Sun Mar 22 19:25:43 CET 2015


Revision: 24753
          http://sourceforge.net/p/gar/code/24753
Author:   wahwah
Date:     2015-03-22 18:25:43 +0000 (Sun, 22 Mar 2015)
Log Message:
-----------
Generate Markdown.

Modified Paths:
--------------
    csw/mgar/gar/v2/go/Makefile
    csw/mgar/gar/v2/go/src/package-gar-status/package-gar-status.go

Modified: csw/mgar/gar/v2/go/Makefile
===================================================================
--- csw/mgar/gar/v2/go/Makefile	2015-03-22 16:11:17 UTC (rev 24752)
+++ csw/mgar/gar/v2/go/Makefile	2015-03-22 18:25:43 UTC (rev 24753)
@@ -7,6 +7,7 @@
 # BINARIES += bin/crashtest
 BINARIES += bin/gen-catalog-index
 BINARIES += bin/promote-packages
+BINARIES += bin/package-gar-status
 
 # On GNU/Linux, 'install'
 INSTALL = ginstall
@@ -31,6 +32,9 @@
 bin/promote-packages: src/promote-packages/promote-packages.go opencsw/diskformat.o opencsw/mantis.o
 	gccgo -g -o $@ $^
 
+bin/package-gar-status: src/package-gar-status/package-gar-status.go opencsw/diskformat.o opencsw/mantis.o
+	gccgo -g -o $@ $^
+
 opencsw/diskformat.o: opencsw src/opencsw/diskformat/diskformat.o
 	$(INSTALL) -m 755 src/opencsw/diskformat/diskformat.o opencsw/diskformat.o
 

Modified: csw/mgar/gar/v2/go/src/package-gar-status/package-gar-status.go
===================================================================
--- csw/mgar/gar/v2/go/src/package-gar-status/package-gar-status.go	2015-03-22 16:11:17 UTC (rev 24752)
+++ csw/mgar/gar/v2/go/src/package-gar-status/package-gar-status.go	2015-03-22 18:25:43 UTC (rev 24753)
@@ -1,5 +1,8 @@
 // We're only including fields that are relevant now. Fields that are present in
 // JSON data but are not in structs, are ignored by the unmarshaller.
+//
+// The script fetches every package every time. It could store a local cache
+// to speed up execution.
 
 package main
 
@@ -16,17 +19,24 @@
 )
 
 var outputFile string
+var testingRun bool
 
-const tmpl = `GAR package status report
-Generated on {{ .Date }}
+const markdownTmpl = `# GAR package status report
 
-{{ range .Pkgs }}
-{{ .Pkg.Catalogname }} is {{ if .InGar }} in GAR {{ else }} NOT in GAR {{ end }}{{ end }}
+Generated on {{ .Date }} by v2/go/src/package-gar-status/package-gar-status.go
+
+## Packages not in GAR
+{{ range .Pkgs }}{{ if .InGar }}{{ else }}
+* [{{ .Pkg.Catalogname }}](http://www.opencsw.org/packages/{{ .Pkg.Catalogname }})
+  --
+  [{{ .Pkg.Md5_sum }}](http://buildfarm.opencsw.org/pkgdb/srv4/{{ .Pkg.Md5_sum }}/){{ end }}{{ end }}
 `
 
 func init() {
-  flag.StringVar(&outputFile, "output-file", "gar-package-status.txt",
+  flag.StringVar(&outputFile, "output-file", "gar-package-status.md",
                  "Where to write output.")
+  flag.BoolVar(&testingRun, "testing", false,
+               "Run for testing, only a few packages")
 }
 
 type BasicStatsType struct {
@@ -45,9 +55,14 @@
 func FindOutIfPackageIsInGar(md5 diskformat.Md5Sum) (bool, error) {
   url := fmt.Sprintf("%s/srv4/%s/pkg-stats/", diskformat.PkgdbUrl, md5)
   log.Println("Fetching", url)
+  var resp *http.Response
   resp, err := http.Get(url)
   if err != nil {
-    return false, err
+    // Try again maybe?
+    resp, err = http.Get(url)
+    if err != nil {
+      return false, err
+    }
   }
   defer resp.Body.Close()
 
@@ -73,21 +88,28 @@
 
 func main() {
   log.Println("Program start")
+  // Without flag.Parse(), -h doesn't work.
+  flag.Parse()
+
+  // Parse the template early.
+  t := template.Must(template.New("tmpl").Parse(markdownTmpl))
+
   spec := diskformat.CatalogSpec {
     "unstable",
     "i386",
     "SunOS5.10",
   }
-  log.Println("spec:", spec)
+  log.Println("Looking at catalog ", spec, " only.")
 
   inGarByPkgname := make(map[string]PackageWithExtraData)
   if cws, err := diskformat.GetCatalogWithSpec(spec); err != nil {
     log.Fatalln("Error unmarshalling JSON data:", err)
   } else {
+    var count = 0
     for _, pkg := range cws.Pkgs {
       log.Println("Processing", fmt.Sprintf("%+v", pkg))
       if inGar, err := FindOutIfPackageIsInGar(pkg.Md5_sum); err != nil {
-        log.Fatalln(pkg.Md5_sum, "boo", err)
+        log.Fatalln("Failed to fetch: ", pkg.Md5_sum, " because ", err)
       } else {
         log.Println("Result: ", pkg.Md5_sum, "is", inGar)
         var pwed PackageWithExtraData
@@ -95,6 +117,10 @@
         pwed.InGar = inGar
         inGarByPkgname[pkg.Catalogname] = pwed
       }
+      count += 1
+      if testingRun && count > 10 {
+        break
+      }
     }
   }
   f, err := os.Create(outputFile)
@@ -108,8 +134,8 @@
     td.Pkgs = append(td.Pkgs, pkg)
   }
   td.Date = time.Now()
-  t := template.Must(template.New("tmpl").Parse(tmpl))
   if err := t.Execute(f, td); err != nil {
     log.Fatal(err)
   }
+  log.Println("Finished, potentially successfully.")
 }

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the devel mailing list