Add util script parsing go.mod file to create EGO_VENDOR
This commit is contained in:
parent
fec37c29f6
commit
ef0e9b4bd6
33
scripts/parse_gomod.py
Normal file
33
scripts/parse_gomod.py
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
import re
|
||||||
|
|
||||||
|
url_map = {
|
||||||
|
"golang.org": "github.com/golang",
|
||||||
|
"google.golang.org": "github.com/golang",
|
||||||
|
"docker.io": "github.com/docker",
|
||||||
|
"k8s.io": "github.com/kubernetes",
|
||||||
|
"sigs.k8s.io": "github.com/kubernetes-sigs",
|
||||||
|
"gopkg.in": "github.com/go-"
|
||||||
|
}
|
||||||
|
with open("go.mod", "r") as data:
|
||||||
|
print("EGO_VENDOR=(")
|
||||||
|
for line in data:
|
||||||
|
pkg = re.match(r"\t(?P<pkg>[^ ]*) (?P<version>[^ ]*)\s.*", line)
|
||||||
|
if pkg:
|
||||||
|
ver = re.match(r"v\d.\d.\d-.*-(?P<commit>[^ ]*)", pkg.group('version'))
|
||||||
|
if ver:
|
||||||
|
commit = ver.group('commit')
|
||||||
|
else:
|
||||||
|
commit = pkg.group('version')
|
||||||
|
commit = re.sub("\+incompatible", "", commit)
|
||||||
|
|
||||||
|
pkg_tokens = pkg.group('pkg').split("/")
|
||||||
|
if pkg_tokens[0] in url_map.keys():
|
||||||
|
if pkg_tokens[0] == "gopkg.in":
|
||||||
|
(pkg_name, branch) = pkg_tokens[-1].split(".")
|
||||||
|
print("\t\"{}/{} {} {}{}/{}\"".format("/".join(pkg_tokens[:-1]), pkg_tokens[-1], commit, url_map[pkg_tokens[0]], pkg_name, pkg_name))
|
||||||
|
else:
|
||||||
|
print("\t\"{}/{} {} {}/{}\"".format("/".join(pkg_tokens[:-1]), pkg_tokens[-1], commit, url_map[pkg_tokens[0]], pkg_tokens[-1]))
|
||||||
|
else:
|
||||||
|
print("\t\"{} {}\"".format(pkg.group('pkg'), commit))
|
||||||
|
print("\t)")
|
Loading…
Reference in New Issue
Block a user