-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathosg-outdated-epel-pkgs
executable file
·208 lines (168 loc) · 5.45 KB
/
osg-outdated-epel-pkgs
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/usr/bin/python
"""
Usage:
%s [3.4|3.5] [el6|el7] [development|testing|release]
Or:
%s [devops] [el7] [itb|production]
Default is:
%s el%s %s
Options:
--make-cache save epelX.html and osg-3.X-elX-XXX.list for offline use
--cached used cached files instead of pulling live versions
--[no-]color colorize version differences (default = True if tty)
--html generate html output (implies --color)
--preamble=text print some preamble text before the report
--show-all show versions even for non-outdated packages
"""
import sys
import os
import re
import rpm
import urllib2
try:
from rpmUtils.miscutils import stringToVersion
except ImportError:
from miscutils import stringToVersion
SERIES = '3.5'
EL = '7'
TAG = 'release'
use_cached = False
make_cache = False
use_color = sys.stdout.isatty()
show_all = False
html_out = False
preamble = None
def usage():
script = os.path.basename(__file__)
print __doc__ % (script, script, SERIES, EL, TAG)
sys.exit()
for arg in sys.argv[1:]:
if re.search(r'^el[5-9]$', arg):
EL = arg[2]
elif re.search(r'^[3-9]\.[0-9]$', arg) or arg == 'devops':
SERIES = arg
elif re.search(r'^(upcoming-)?(development|testing|release)$', arg) \
or arg in ('itb', 'production'):
TAG = arg
elif arg == '--cached':
use_cached = True
elif arg == '--make-cache':
make_cache = True
elif arg == '--color':
use_color = True
elif arg == '--no-color':
use_color = False
elif arg == '--html':
html_out = True
use_color = True
elif arg.startswith('--preamble='):
preamble = arg[len('--preamble='):]
elif arg == '--show-all':
show_all = True
else:
usage()
if use_cached and make_cache:
usage()
if SERIES == 'devops' and TAG == 'release':
TAG = 'production'
def strip_dist_tag(seq, dist_pfx):
pat = r'\.%s[^-]*$' % dist_pfx
return [ re.sub(pat, '', nvr) for nvr in seq ]
def extract_href_rpm(line):
m = re.search(r'<a href="([^"]+(-[^-"]+){2})\.src\.rpm"', line)
if m:
return m.groups()[0]
m = re.search(r'<a href="(\w)/"', line)
if m:
return get_epel_list(m.groups()[0])
def get_handle(fn, arg, cache_name):
if use_cached:
handle = open(cache_name)
else:
handle = fn(arg)
if make_cache:
open(cache_name, 'w').write(handle.read())
print "Wrote:", cache_name
handle = []
return handle
def get_epel_list(subdir=None):
epel_url = "http://dl.fedoraproject.org/pub/epel/%s/SRPMS/Packages/" % EL
if subdir is None:
cache_name = 'epel%s.html' % EL
else:
cache_name = 'epel%s_%s.html' % (EL,subdir)
epel_url += "%s/" % subdir
handle = get_handle(urllib2.urlopen, epel_url, cache_name)
nvrs = filter(None, map(extract_href_rpm, handle))
if nvrs and type(nvrs[0]) is list:
nvrs = [ nvr for nvrlist in nvrs for nvr in nvrlist ]
return strip_dist_tag(nvrs, 'el%s' % EL)
def get_osg_list():
if SERIES == 'devops':
osg_tag = "%s-el%s-%s" % (SERIES, EL, TAG)
else:
osg_tag = "osg-%s-el%s-%s" % (SERIES, EL, TAG)
cmd = "osg-koji list-tagged --latest --rpms %s" % osg_tag
cache_name = osg_tag + '.list'
handle = get_handle(os.popen, cmd, cache_name)
nvrs = [ line[:-5] for line in handle if line.endswith(".src\n") ]
return strip_dist_tag(nvrs, 'osg')
def rpmvercmp(a,b):
return rpm.labelCompare(*[stringToVersion(x) for x in (a,b)])
def n_vr(nvr):
n,v,r = nvr.rsplit("-",2)
return n, v+'-'+r
def nvrmap(seq):
return dict( n_vr(nvr) for nvr in seq )
if make_cache:
get_epel_list()
get_osg_list()
sys.exit()
epel_map = nvrmap(get_epel_list())
osg_map = nvrmap(get_osg_list())
def colorize(color, *seq):
return [ "\x1b[%sm%s\x1b[0m" % (color, x) for x in seq ]
def colorize_vr(vr1, vr2):
v1,r1 = vr1.split('-')
v2,r2 = vr2.split('-')
if v1 != v2:
v1,v2 = colorize('1;32', v1, v2)
elif r1 != r2:
r1,r2 = colorize('1;34', r1, r2)
return map('-'.join, [[v1,r1],[v2,r2]])
def colorize_html(color, *seq):
return [ '<span class="%s">%s</span>' % (color, x) for x in seq ]
def colorize_html_vr(vr1, vr2):
v1,r1 = vr1.split('-')
v2,r2 = vr2.split('-')
if v1 != v2:
v1,v2 = colorize_html('vdiff', v1, v2)
elif r1 != r2:
r1,r2 = colorize_html('rdiff', r1, r2)
return map('-'.join, [[v1,r1],[v2,r2]])
if html_out:
colorize_vr = colorize_html_vr
print ("<html>\n<head>\n<style type='text/css'>\n.vdiff {color:green}\n"
".rdiff {color:blue}\n</style>\n</head>\n<body>\n<pre>")
if preamble:
print preamble
print
pkg_diffs = []
for pkg in sorted(osg_map):
if pkg in epel_map:
vrcmp = rpmvercmp(osg_map[pkg], epel_map[pkg])
if vrcmp < 0 or show_all:
pkg_diffs.append([pkg, osg_map[pkg], epel_map[pkg]])
if pkg_diffs:
pkg_diffs[:0] = [["Package", "OSG " + SERIES, "EPEL " + EL]]
widths = [ max(map(len,col)) for col in zip(*pkg_diffs) ]
pkg_diffs[1:1] = [[ '-' * n for n in widths ]]
for i,row in enumerate(pkg_diffs):
spacing = [ w-len(x) for x,w in zip(row,widths) ]
if use_color and i > 1:
row[1:] = colorize_vr(*row[1:])
print ' '.join( r + ' ' * s for r,s in zip(row,spacing) ).rstrip()
else:
print "No package version differences"
if html_out:
print "</pre>\n</body>\n</html>"