SF.net SVN: gar:[23334] csw/mgar/gar/v2/go
wahwah at users.sourceforge.net
wahwah at users.sourceforge.net
Sat Apr 5 20:47:26 CEST 2014
Revision: 23334
http://sourceforge.net/p/gar/code/23334
Author: wahwah
Date: 2014-04-05 18:47:26 +0000 (Sat, 05 Apr 2014)
Log Message:
-----------
gen-catalog-index: A new utility
Generates the catalog file.
Modified Paths:
--------------
csw/mgar/gar/v2/go/Makefile
csw/mgar/gar/v2/go/src/opencsw/diskformat/diskformat.go
Added Paths:
-----------
csw/mgar/gar/v2/go/src/gen-catalog-index/
csw/mgar/gar/v2/go/src/gen-catalog-index/gen-catalog-index.go
Modified: csw/mgar/gar/v2/go/Makefile
===================================================================
--- csw/mgar/gar/v2/go/Makefile 2014-04-05 18:17:18 UTC (rev 23333)
+++ csw/mgar/gar/v2/go/Makefile 2014-04-05 18:47:26 UTC (rev 23334)
@@ -3,7 +3,7 @@
# 1. gmake
# 2. scp to the web host to replace the old binary
-all: bin bin/catalog-release-to-disk
+all: bin bin/catalog-release-to-disk bin/gen-catalog-index
bin:
mkdir -p bin
@@ -11,14 +11,22 @@
bin/catalog-release-to-disk: src/catalog-release-to-disk/catalog-release-to-disk.o src/opencsw/diskformat/diskformat.o
gccgo -g -o $@ $?
+bin/gen-catalog-index: src/gen-catalog-index/gen-catalog-index.o src/opencsw/diskformat/diskformat.o
+ gccgo -g -o $@ $?
+
# This is a poor hack, but it gets it to compile.
src/catalog-release-to-disk/catalog-release-to-disk.o: src/opencsw/diskformat/diskformat.o
mkdir -p opencsw
ln -sf ../src/opencsw/diskformat/diskformat.o opencsw/diskformat.o
gccgo -o $@ -g -c src/catalog-release-to-disk/catalog-release-to-disk.go
+src/gen-catalog-index/gen-catalog-index.o: src/opencsw/diskformat/diskformat.o
+ mkdir -p opencsw
+ ln -sf ../src/opencsw/diskformat/diskformat.o opencsw/diskformat.o
+ gccgo -o $@ -g -c src/gen-catalog-index/gen-catalog-index.go
+
%.o: %.go
gccgo -o $@ -g -c $<
clean:
- rm -f src/opencsw/diskformat/diskformat.o bin/catalog-release-to-disk
+ rm -f src/opencsw/diskformat/diskformat.o bin/catalog-release-to-disk bin/gen-catalog-index
Added: csw/mgar/gar/v2/go/src/gen-catalog-index/gen-catalog-index.go
===================================================================
--- csw/mgar/gar/v2/go/src/gen-catalog-index/gen-catalog-index.go (rev 0)
+++ csw/mgar/gar/v2/go/src/gen-catalog-index/gen-catalog-index.go 2014-04-05 18:47:26 UTC (rev 23334)
@@ -0,0 +1,53 @@
+package main
+
+import (
+ "bufio"
+ "flag"
+ "log"
+ "os"
+ "opencsw/diskformat"
+)
+
+// Command line flags
+var catrel_flag string
+var arch_flag string
+var osrel_flag string
+var out_file string
+
+func init() {
+ flag.StringVar(&out_file, "output", "catalog",
+ "The name of the file to generate.")
+ flag.StringVar(&catrel_flag, "catalog-release", "unstable",
+ "e.g. unstable, bratislava, kiel, dublin")
+ flag.StringVar(&osrel_flag, "os-release", "SunOS5.10",
+ "e.g. SunOS5.10")
+ flag.StringVar(&arch_flag, "arch", "sparc",
+ "{ sparc | i386 }")
+ flag.StringVar(&diskformat.PkgdbUrl, "pkgdb-url",
+ "http://buildfarm.opencsw.org/pkgdb/rest",
+ "Web address of the pkgdb app.")
+}
+
+func main() {
+ flag.Parse()
+ spec := diskformat.CatalogSpec{catrel_flag, arch_flag, osrel_flag}
+ cws, err := diskformat.GetCatalogWithSpec(spec)
+ if err != nil {
+ log.Fatalln("Could not fetch", spec, ":", err)
+ }
+
+ catalog_fd, err := os.Create(out_file)
+ if err != nil {
+ log.Fatalln("Could not open the output file for writing:", err)
+ }
+ defer catalog_fd.Close()
+ catbuf := bufio.NewWriter(catalog_fd)
+ defer catbuf.Flush()
+
+ log.Println("Writing", spec, "to", out_file)
+ if err = diskformat.WriteCatalogIndex(catbuf, cws); err != nil {
+ log.Fatalln("Error while writing:", err)
+ } else {
+ log.Println("Catalog index written successfully")
+ }
+}
Modified: csw/mgar/gar/v2/go/src/opencsw/diskformat/diskformat.go
===================================================================
--- csw/mgar/gar/v2/go/src/opencsw/diskformat/diskformat.go 2014-04-05 18:17:18 UTC (rev 23333)
+++ csw/mgar/gar/v2/go/src/opencsw/diskformat/diskformat.go 2014-04-05 18:47:26 UTC (rev 23334)
@@ -743,18 +743,32 @@
defer descbuf.Flush()
}
- // http://www.opencsw.org/manual/for-maintainers/catalog-format.html
- ts_line := fmt.Sprintf("# CREATIONDATE %s\n", time.Now().Format(time.RFC3339))
- catbuf.WriteString(ts_line)
+ if err := WriteCatalogIndex(catbuf, cws); err != nil {
+ log.Println("Failed while writing to", catalog_file_path,
+ ":", err)
+ }
for _, pkg := range cws.Pkgs {
- catbuf.WriteString(pkg.AsCatalogEntry())
- catbuf.WriteString("\n")
descbuf.WriteString(pkg.AsDescription())
descbuf.WriteString("\n")
}
}
+// Write the catalog file to given Writer. File format as defined by
+// http://www.opencsw.org/manual/for-maintainers/catalog-format.html
+func WriteCatalogIndex(w *bufio.Writer, cws CatalogWithSpec) error {
+ ts_line := fmt.Sprintf("# CREATIONDATE %s\n", time.Now().Format(time.RFC3339))
+ w.WriteString(ts_line)
+
+ for _, pkg := range cws.Pkgs{
+ _, err := w.WriteString(pkg.AsCatalogEntry())
+ if err != nil { return err }
+ _, err = w.WriteString("\n")
+ if err != nil { return err }
+ }
+ return nil
+}
+
// The main function of this package.
func GenerateCatalogRelease(catrel string, catalog_root string) {
log.Println("catrel:", catrel)
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