-
Notifications
You must be signed in to change notification settings - Fork 5
/
osg-pkgs-behind-tag
executable file
·127 lines (96 loc) · 3.13 KB
/
osg-pkgs-behind-tag
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
#!/usr/bin/env python
"""
Usage:
{0} [options] tag1 tag2 [-- pkglist...]
Shows packages present in both tag1 and tag2, with a newer NVR in tag2.
If "-- pkglist..." is provided, limit results to packages in pkglist.
Examples:
{0} osg-3.3-el6-{{release,testing}}
{0} osg-3.3-el6-{{testing,development}}
{0} osg-{{3.2,3.3}}-el6-release
{0} osg-3.3-el6-{{testing,development}} -- pkg1 pkg2 pkg3
Options:
--[no-]color colorize version differences (default = True if tty)
--show-all show versions even for non-outdated packages
"""
from __future__ import print_function
import sys
import os
import re
import rpm
from vendor.miscutils import stringToVersion
use_color = sys.stdout.isatty()
show_all = False
pkgset = None
tags = []
tagpat = (r'^osg-(([2-9]\.?\d|[2-9]\d)(-main)?(-upcoming)?)'
r'-el[5-9]-(development|testing|release)'
r'(-([2-9]\.?\d|[2-9]\d)\.\d+)?$')
def usage():
print(__doc__.format(os.path.basename(__file__)))
sys.exit()
for arg in sys.argv[1:]:
if pkgset is not None:
pkgset.add(arg)
elif arg == '--':
pkgset = set()
elif re.search(tagpat, arg):
tags.append(arg)
elif arg == '--color':
use_color = True
elif arg == '--no-color':
use_color = False
elif arg in ('--all', '--show-all'):
show_all = True
else:
usage()
if len(tags) != 2:
usage()
def strip_dist_tag(seq, dist_pfx):
pat = r'\.%s[^-]*$' % dist_pfx
return [ re.sub(pat, '', nvr) for nvr in seq ]
def get_osg_list(osg_tag):
cmd = "osg-koji list-tagged --latest --rpms %s" % osg_tag
handle = os.popen(cmd)
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 )
osg_map1 = nvrmap(get_osg_list(tags[0]))
osg_map2 = nvrmap(get_osg_list(tags[1]))
pkgs1 = set(osg_map1)
pkgs2 = set(osg_map2)
pkgs = pkgs1 & pkgs2
if pkgset is not None:
pkgs &= pkgset
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;31', v1, v2)
elif r1 != r2:
r1,r2 = colorize('1;33', r1, r2)
return map('-'.join, [[v1,r1],[v2,r2]])
pkg_diffs = []
for pkg in sorted(pkgs):
vrcmp = rpmvercmp(osg_map1[pkg], osg_map2[pkg])
if vrcmp < 0 or show_all:
pkg_diffs.append([pkg, osg_map1[pkg], osg_map2[pkg]])
if pkg_diffs:
pkg_diffs[:0] = [["Package"] + tags]
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 packages in '%s' behind version in '%s'" % tuple(tags))