2015-07-22 19:41:13 +00:00
|
|
|
package main
|
|
|
|
|
2015-07-23 15:05:21 +00:00
|
|
|
import (
|
2015-08-08 16:01:44 +00:00
|
|
|
"bytes"
|
2015-07-23 15:05:21 +00:00
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2015-08-08 16:01:44 +00:00
|
|
|
"html/template"
|
2019-08-12 21:46:36 +00:00
|
|
|
"io"
|
2015-07-23 15:05:21 +00:00
|
|
|
"io/ioutil"
|
2019-11-10 01:05:59 +00:00
|
|
|
"log"
|
2019-08-12 21:46:36 +00:00
|
|
|
"os"
|
|
|
|
"path"
|
2015-07-23 15:05:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Package struct {
|
|
|
|
Repo string
|
|
|
|
Path string
|
|
|
|
Packages []string
|
2015-08-08 16:01:44 +00:00
|
|
|
Url string
|
2015-07-23 15:05:21 +00:00
|
|
|
}
|
|
|
|
|
2019-08-12 21:46:36 +00:00
|
|
|
func writePage(w io.Writer, path string, pkg Package) error {
|
2021-03-16 03:12:27 +00:00
|
|
|
t, err := template.ParseFiles("layouts/gorepos.html")
|
2015-08-08 16:01:44 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
pkg.Path = path
|
|
|
|
var page bytes.Buffer
|
|
|
|
err = t.Execute(&page, pkg)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-07-23 15:05:21 +00:00
|
|
|
|
2019-08-12 21:46:36 +00:00
|
|
|
_, err = io.Copy(w, &page)
|
|
|
|
return err
|
|
|
|
}
|
2015-07-23 15:05:21 +00:00
|
|
|
|
2020-03-05 22:42:29 +00:00
|
|
|
func loadConfig(namespace string) (ret []Package, err error) {
|
|
|
|
content, err := ioutil.ReadFile(fmt.Sprintf("%s.json", namespace))
|
2015-07-23 15:05:21 +00:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
err = json.Unmarshal(content, &ret)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-07-22 19:41:13 +00:00
|
|
|
func main() {
|
2020-03-29 02:23:39 +00:00
|
|
|
if len(os.Args) != 3 {
|
|
|
|
fmt.Printf("main.go namespace fs-root-dir\n")
|
|
|
|
}
|
|
|
|
|
2020-03-05 22:42:29 +00:00
|
|
|
namespace := os.Args[1]
|
2020-03-29 02:23:39 +00:00
|
|
|
root := os.Args[2]
|
2020-03-05 22:42:29 +00:00
|
|
|
|
|
|
|
packages, err := loadConfig(namespace)
|
2015-07-23 15:05:21 +00:00
|
|
|
if err != nil {
|
2019-11-10 01:05:59 +00:00
|
|
|
log.Fatalf("%s\n", err)
|
2015-07-23 15:05:21 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-08-12 21:46:36 +00:00
|
|
|
for _, pkg := range packages {
|
|
|
|
packages := pkg.Packages
|
|
|
|
packages = append(packages, "")
|
|
|
|
for _, subpackage := range packages {
|
|
|
|
pkgpath := path.Join(namespace, pkg.Path)
|
|
|
|
|
2020-03-29 02:23:39 +00:00
|
|
|
root := path.Join(root, pkg.Path, subpackage)
|
2019-08-12 21:46:36 +00:00
|
|
|
|
|
|
|
if err := os.MkdirAll(root, 0755); err != nil {
|
|
|
|
fmt.Errorf("%s\n", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
fd, err := os.Create(path.Join(root, "index.html"))
|
|
|
|
if err != nil {
|
|
|
|
fmt.Errorf("%s\n", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer fd.Close()
|
|
|
|
writePage(fd, pkgpath, pkg)
|
|
|
|
fd.Close()
|
2015-07-23 15:05:21 +00:00
|
|
|
}
|
2019-08-12 21:46:36 +00:00
|
|
|
}
|
2015-07-22 19:41:13 +00:00
|
|
|
}
|
2015-07-23 15:05:21 +00:00
|
|
|
|
|
|
|
// vim: foldmethod=marker
|