forked from gofed/gofed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkDeps.py
124 lines (93 loc) · 2.76 KB
/
checkDeps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import json
import sys
import modules.Repos
import modules.Utils
import optparse
import os
from modules.Utils import GREEN, RED, ENDC, YELLOW
from modules.Repos import Repos, IPMap
from modules.RemoteSpecParser import RemoteSpecParser
def getGoDeps(path):
deps = {}
try:
with open(path, 'r') as file:
json_deps = json.loads(file.read())
except IOError, e:
sys.stderr.write("%s\n" % e)
return {}
if "Deps" not in json_deps:
return {}
for dep in json_deps["Deps"]:
if "ImportPath" not in dep or "Rev" not in dep:
continue
ip = str(dep["ImportPath"])
rev = str(dep["Rev"])
deps[ip] = rev
return deps
if __name__ == "__main__":
parser = optparse.OptionParser("%prog [-l] [-v] [Godeps.json]")
parser.add_option_group( optparse.OptionGroup(parser, "Godeps.json", "JSON file with golang deps") )
parser.add_option(
"", "-l", "--dontpull", dest="pull", action = "store_false", default = True,
help = "Dont pull repositories (use only local)"
)
parser.add_option(
"", "-v", "--verbose", dest="verbose", action = "store_true", default = False,
help = "Verbose mode"
)
options, args = parser.parse_args()
if len(args) == 0:
json_file = "%s/%s" % (os.getcwd(), "Godeps.json")
else:
json_file = args[0]
# json file exists?
if not os.path.exists(json_file):
print "JSON file %s not found" % json_file
exit(1)
deps = getGoDeps(json_file)
if deps == {}:
print "%s is corrupted or has no dependencies" % json_file
exit(1)
repos_obj = Repos()
im = IPMap().loadIMap()
repos = repos_obj.parseReposInfo()
keys = sorted(deps.keys())
cache = []
for dep in keys:
ip = dep
commit = deps[dep]
pkg = ''
if 'golang(%s)' % ip in im:
pkg, _ = im['golang(%s)' % ip]
else:
print "import path %s not found" % ip
continue
if pkg not in repos:
print "package %s not found in golang.repos" % pkg
continue
if pkg in cache:
continue
cache.append(pkg)
path, upstream = repos[pkg]
ups_commits = modules.Repos.getRepoCommits(path, upstream, pull=options.pull)
rsp_obj = RemoteSpecParser('master', pkg)
if not rsp_obj.parse():
continue
pkg_commit = rsp_obj.getPackageCommits()
# now fedora and commit, up to date?
if commit not in ups_commits:
print "%s: upstream commit %s not found" % (pkg, commit)
continue
if pkg_commit not in ups_commits:
print "%s: package commit %s not found" % (pkg, pkg_commit)
continue
commit_ts = int(ups_commits[commit])
pkg_commit_ts = int(ups_commits[pkg_commit])
if commit == pkg_commit:
if options.verbose:
print "%spackage %s up2date%s" % (GREEN, pkg, ENDC)
elif commit_ts > pkg_commit_ts:
print "%spackage %s outdated%s" % (RED, pkg, ENDC)
else:
if options.verbose:
print "%spackage %s has newer commit%s" % (YELLOW, pkg, ENDC)