Fix path to python script
[fedora-mingw.git] / compare / compare.py
1 #!/usr/bin/python
2
3 import sys
4 from tempfile import mkdtemp
5 from os import mkdir, system
6 import rpm
7
8
9 def compare_header(refspec, altspec):
10     refhdr = refspec.packages()[0].header()
11     althdr = altspec.packages()[0].header()
12
13     refname = refhdr[rpm.RPMTAG_NAME]
14     altname = althdr[rpm.RPMTAG_NAME]
15
16     refver = refhdr[rpm.RPMTAG_VERSION]
17     altver = althdr[rpm.RPMTAG_VERSION]
18
19     reflic = refhdr[rpm.RPMTAG_LICENSE]
20     altlic = althdr[rpm.RPMTAG_LICENSE]
21
22     refurl = refhdr[rpm.RPMTAG_URL]
23     alturl = althdr[rpm.RPMTAG_URL]
24
25     if refver != altver:
26         print "WARNING: different version: '%s': '%s' != '%s': '%s'" % (refname, refver, altname, altver)
27
28     if refver != altver:
29         print "WARNING: different license: '%s': '%s' != '%s': '%s'" % (refname, reflic, altname, altlic)
30
31     if refver != altver:
32         print "WARNING: different URL: '%s': '%s' != '%s': '%s'" % (refname, refurl, altname, alturl)
33
34 def compare_sources(refspec, altspec):
35     refsrc = []
36     altsrc = []
37     refsrcname = []
38     altsrcname = []
39     for src in refspec.sources():
40         if src[2] == rpm.RPMBUILD_ISSOURCE:
41             uri = src[0]
42             offset = uri.rfind("/")
43             if offset != -1:
44                 baseuri = uri[0:offset]
45                 srcname = uri[offset+1:]
46             else:
47                 baseuri = ""
48                 srcname = uri
49             refsrc.append([baseuri, srcname])
50             refsrcname.append(srcname)
51
52     for src in altspec.sources():
53         if src[2] == rpm.RPMBUILD_ISSOURCE:
54             uri = src[0]
55             offset = uri.rfind("/")
56             if offset != -1:
57                 baseuri = uri[0:offset]
58                 srcname = uri[offset+1:]
59             else:
60                 baseuri = ""
61                 srcname = uri
62             altsrc.append([baseuri, srcname])
63             altsrcname.append(srcname)
64
65
66     for s in refsrc:
67         if not s[1] in altsrcname:
68             print "WARNING: missing source: '%s'" % s[1]
69     for s in altsrc:
70         if not s[1] in refsrcname:
71             print "WARNING: extra source: '%s'" % s[1]
72
73     for s1 in refsrc:
74         for s2 in altsrc:
75             if s1[1] != s2[1]:
76                 continue
77             if s1[0] != s2[0]:
78                 print "WARNING: different base URI for source '%s': '%s' != '%s'" % (s1[1], s1[0], s2[0])
79
80
81 def compare_patches(refspec, altspec):
82     refpatch = []
83     altpatch = []
84     for src in refspec.sources():
85         if src[2] == rpm.RPMBUILD_ISPATCH:
86             refpatch.append(src[0])
87     for src in altspec.sources():
88         if src[2] == rpm.RPMBUILD_ISPATCH:
89             altpatch.append(src[0])
90
91     for p in refpatch:
92         if not p in altpatch:
93             print "WARNING missing patch '%s'" % p
94
95     for p in altpatch:
96         if not p in refpatch:
97             print "WARNING extra patch '%s'" % p
98
99 scratchdir = mkdtemp("rpm-source-compare")
100
101 if len(sys.argv) != 3:
102     print "syntax: %s REFERENCE-SPEC ALTERNATE-SPEC" % sys.argv[0]
103     sys.exit(1)
104
105 refspecfile = sys.argv[1]
106 altspecfile = sys.argv[2]
107
108 ts = rpm.ts()
109
110 refspec = ts.parseSpec(refspecfile)
111 altspec = ts.parseSpec(altspecfile)
112
113 compare_header(refspec, altspec)
114 compare_sources(refspec, altspec)
115 compare_patches(refspec, altspec)
116