-
Notifications
You must be signed in to change notification settings - Fork 561
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8ef2e3e
commit 49d48ba
Showing
3 changed files
with
81 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"os" | ||
"path/filepath" | ||
"regexp" | ||
) | ||
|
||
func downloadLicense(url, packageName string) error { | ||
folderPath := filepath.Join(".", "internal", "embedded", "_data", "licenses", packageName) | ||
licenseFileName := filepath.Join(folderPath, "LICENSE") | ||
|
||
err := os.MkdirAll(folderPath, 0755) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
resp, err := http.Get(url) | ||
if err != nil { | ||
return err | ||
} | ||
defer resp.Body.Close() | ||
|
||
if resp.StatusCode != http.StatusOK { | ||
return fmt.Errorf("failed to download license: %s (status code: %d)", url, resp.StatusCode) | ||
} | ||
|
||
licenseFile, err := os.Create(licenseFileName) | ||
if err != nil { | ||
return err | ||
} | ||
defer licenseFile.Close() | ||
|
||
_, err = io.Copy(licenseFile, resp.Body) | ||
return err | ||
} | ||
|
||
func main() { | ||
pattern := regexp.MustCompile("(?i)COPYING|LICENSE|NOTICE.*") | ||
|
||
licenses := []struct { | ||
url string | ||
packageName string | ||
}{ | ||
{"https://raw.githubusercontent.com/davecgh/go-spew/master/LICENSE", "github.com/davecgh/go-spew"}, | ||
{"https://raw.githubusercontent.com/alexbrainman/sspi/master/LICENSE", "github.com/alexbrainman/sspi"}, | ||
{"https://raw.githubusercontent.com/pmezard/go-difflib/master/LICENSE", "github.com/pmezard/go-difflib"}, | ||
{"https://go.dev/LICENSE?m=text", "go.dev"}, | ||
} | ||
|
||
for _, license := range licenses { | ||
err := downloadLicense(license.url, license.packageName) | ||
if err != nil { | ||
fmt.Printf("Error downloading license for %s: %v\n", license.packageName, err) | ||
} | ||
} | ||
|
||
licensePath := filepath.Join(".", "internal", "embedded", "_data", "licenses") | ||
err := filepath.Walk(licensePath, func(path string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if !info.IsDir() && !pattern.MatchString(path) { | ||
if err := os.Remove(path); err != nil && !os.IsNotExist(err) { | ||
return err | ||
} | ||
} else { | ||
fmt.Println(path) | ||
} | ||
return nil | ||
}) | ||
|
||
if err != nil { | ||
fmt.Println("Error cleaning up licenses:", err) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,5 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
BASEDIR=$(dirname "$0") | ||
PYTHON_VERSION="" | ||
|
||
if python3 -c 'print("python3")' > /dev/null 2>&1; then | ||
PYTHON_VERSION="3" | ||
fi | ||
|
||
python$PYTHON_VERSION $BASEDIR/prepare_licenses.py | ||
go run $BASEDIR/prepare_licenses.go |