-
Notifications
You must be signed in to change notification settings - Fork 2
/
rpmdev-vercmp
executable file
·87 lines (75 loc) · 2.66 KB
/
rpmdev-vercmp
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
#!/usr/bin/python
#
# rpmdev-vercmp -- compare rpm versions
#
# Copyright (c) Seth Vidal
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import sys
import rpm
def usage():
print ("""
rpmdev-vercmp <epoch1> <ver1> <release1> <epoch2> <ver2> <release2>
rpmdev-vercmp <EVR1> <EVR2> # if rpmUtils.miscutils is available
rpmdev-vercmp # with no arguments, prompt
Exit status is 0 if the EVR's are equal, 11 if EVR1 is newer, and 12 if EVR2
is newer. Other exit statuses indicate problems.
""")
def vercmp((e1, v1, r1), (e2, v2, r2)):
rc = rpm.labelCompare((e1, v1, r1), (e2, v2, r2))
return rc
def askforstuff(thingname):
thing = raw_input('%s :' % thingname)
return thing
def main():
if len(sys.argv) > 1 and sys.argv[1] in ['-h', '--help', '-help', '--usage']:
usage()
sys.exit(0)
elif len(sys.argv) == 3:
try:
from rpmUtils.miscutils import stringToVersion
except:
print ("""
Sorry, the 2-argument form is available only if rpmUtils.miscutils (which
ships eg. with yum) is available.""")
usage()
sys.exit(1)
(e1, v1, r1) = stringToVersion(sys.argv[1])
(e2, v2, r2) = stringToVersion(sys.argv[2])
# stringToVersion in yum < 3.1.2 may return numeric (non-string)
# Epochs, and labelCompare does not like that.
if e1 is not None: e1 = str(e1)
if e2 is not None: e2 = str(e2)
elif len(sys.argv) < 7:
e1 = askforstuff('Epoch1')
v1 = askforstuff('Version1')
r1 = askforstuff('Release1')
e2 = askforstuff('Epoch2')
v2 = askforstuff('Version2')
r2 = askforstuff('Release2')
else:
(e1, v1, r1, e2, v2, r2) = sys.argv[1:]
rc = vercmp((e1, v1, r1), (e2, v2, r2))
if rc > 0:
print ("%s:%s-%s is newer" % (e1, v1, r1))
rc = 11
elif rc == 0:
print ("These are equal")
elif rc < 0:
print ("%s:%s-%s is newer" % (e2, v2, r2))
rc = 12
sys.exit(rc)
if __name__ == "__main__":
main()