summaryrefslogtreecommitdiffstats
path: root/scripts/generate-licenses.go
diff options
context:
space:
mode:
authorThomas Boerger <thomas@webhippie.de>2017-03-15 13:30:16 +0100
committerGitHub <noreply@github.com>2017-03-15 13:30:16 +0100
commit42032fdecf81c25cb4aa477ddf9a0207e85f571a (patch)
treef7cf4207da34eb4eeb9b57caaaa78e7aba461130 /scripts/generate-licenses.go
parenta06c3ad2c02a5473184711be6dbf1b30f0299e11 (diff)
downloadgitea-42032fdecf81c25cb4aa477ddf9a0207e85f571a.tar.gz
gitea-42032fdecf81c25cb4aa477ddf9a0207e85f571a.zip
Synced licenses with github repo (#1246)
* Added script to download licenses from github * Synced licenses with github repo
Diffstat (limited to 'scripts/generate-licenses.go')
-rw-r--r--scripts/generate-licenses.go109
1 files changed, 109 insertions, 0 deletions
diff --git a/scripts/generate-licenses.go b/scripts/generate-licenses.go
new file mode 100644
index 0000000000..c99cdb3651
--- /dev/null
+++ b/scripts/generate-licenses.go
@@ -0,0 +1,109 @@
+// +build !build
+
+package main
+
+import (
+ "archive/tar"
+ "compress/gzip"
+ "flag"
+ "fmt"
+ "io"
+ "io/ioutil"
+ "log"
+ "net/http"
+ "os"
+ "path"
+ "path/filepath"
+ "strings"
+)
+
+var (
+ prefix = "gitea-licenses"
+ url = "https://api.github.com/repos/spdx/license-list/tarball"
+ destination = ""
+)
+
+func init() {
+ flag.StringVar(&destination, "dest", "options/license/", "destination for the licenses")
+}
+
+func main() {
+ flag.Parse()
+
+ file, err := ioutil.TempFile(os.TempDir(), prefix)
+
+ if err != nil {
+ log.Fatalf("Failed to create temp file. %s", err)
+ }
+
+ defer os.Remove(file.Name())
+
+ resp, err := http.Get(url)
+
+ if err != nil {
+ log.Fatalf("Failed to download archive. %s", err)
+ }
+
+ defer resp.Body.Close()
+
+ if _, err := io.Copy(file, resp.Body); err != nil {
+ log.Fatalf("Failed to copy archive to file. %s", err)
+ }
+
+ if _, err := file.Seek(0, 0); err != nil {
+ log.Fatalf("Failed to reset seek on archive. %s", err)
+ }
+
+ gz, err := gzip.NewReader(file)
+
+ if err != nil {
+ log.Fatalf("Failed to gunzip the archive. %s", err)
+ }
+
+ tr := tar.NewReader(gz)
+
+ for {
+ hdr, err := tr.Next()
+
+ if err == io.EOF {
+ break
+ }
+
+ if err != nil {
+ log.Fatalf("Failed to iterate archive. %s", err)
+ }
+
+ fmt.Println(hdr.Name)
+ fmt.Println(filepath.Ext(hdr.Name))
+
+ if filepath.Ext(hdr.Name) != ".txt" {
+ continue
+ }
+
+ if strings.HasPrefix(filepath.Base(hdr.Name), "README") {
+ continue
+ }
+
+ if strings.HasPrefix(filepath.Base(hdr.Name), "deprecated_") {
+ continue
+ }
+
+ fmt.Println(path.Join(destination, strings.TrimSuffix(filepath.Base(hdr.Name), ".txt")))
+
+ out, err := os.Create(path.Join(destination, strings.TrimSuffix(filepath.Base(hdr.Name), ".txt")))
+
+ if err != nil {
+ log.Fatalf("Failed to create new file. %s", err)
+ }
+
+ defer out.Close()
+
+ if _, err := io.Copy(out, tr); err != nil {
+ log.Fatalf("Failed to write new file. %s", err)
+ } else {
+ fmt.Printf("Written %s\n", out.Name())
+ }
+ }
+
+ fmt.Println("Done")
+}