4 from tempfile import mkdtemp
5 from os import mkdir, system
10 def compare_header(refspec, altspec):
13 refhdr = refspec.packages()[0].header()
14 althdr = altspec.packages()[0].header()
16 refname = refhdr[rpm.RPMTAG_NAME]
17 altname = althdr[rpm.RPMTAG_NAME]
19 refver = refhdr[rpm.RPMTAG_VERSION]
20 altver = althdr[rpm.RPMTAG_VERSION]
22 reflic = refhdr[rpm.RPMTAG_LICENSE]
23 altlic = althdr[rpm.RPMTAG_LICENSE]
25 refurl = refhdr[rpm.RPMTAG_URL]
26 alturl = althdr[rpm.RPMTAG_URL]
29 warnings.append("different version: '%s': '%s' != '%s': '%s'" % (refname, refver, altname, altver))
32 warnings.append("different license: '%s': '%s' != '%s': '%s'" % (refname, reflic, altname, altlic))
35 warnings.append("different URL: '%s': '%s' != '%s': '%s'" % (refname, refurl, altname, alturl))
39 def compare_sources(refspec, altspec):
45 for src in refspec.sources():
46 if src[2] == rpm.RPMBUILD_ISSOURCE:
48 offset = uri.rfind("/")
50 baseuri = uri[0:offset]
51 srcname = uri[offset+1:]
55 refsrc.append([baseuri, srcname])
56 refsrcname.append(srcname)
58 for src in altspec.sources():
59 if src[2] == rpm.RPMBUILD_ISSOURCE:
61 offset = uri.rfind("/")
63 baseuri = uri[0:offset]
64 srcname = uri[offset+1:]
68 altsrc.append([baseuri, srcname])
69 altsrcname.append(srcname)
73 if not s[1] in altsrcname:
74 warnings.append("missing source: '%s'" % s[1])
76 if not s[1] in refsrcname:
77 warnings.append("extra source: '%s'" % s[1])
84 warnings.append("different base URI for source '%s': '%s' != '%s'" % (s1[1], s1[0], s2[0]))
89 def compare_patches(refspec, altspec):
93 for src in refspec.sources():
94 if src[2] == rpm.RPMBUILD_ISPATCH:
95 refpatch.append(src[0])
96 for src in altspec.sources():
97 if src[2] == rpm.RPMBUILD_ISPATCH:
98 altpatch.append(src[0])
101 if not p in altpatch:
102 warnings.append("missing patch '%s'" % p)
105 if not p in refpatch:
106 warnings.append("extra patch '%s'" % p)
111 def compare_specs(refspec, altspec):
114 for w in compare_header(refspec, altspec):
116 for w in compare_sources(refspec, altspec):
118 for w in compare_patches(refspec, altspec):
123 def load_suppressions(file):
124 if not os.path.exists(file):
128 s = open(suppressionfile)
146 scratchdir = mkdtemp("rpm-source-compare")
148 if len(sys.argv) != 4:
149 print "syntax: %s REFERENCE-SPEC ALTERNATE-SPEC SUPPRESSIONS" % sys.argv[0]
152 refspecfile = sys.argv[1]
153 altspecfile = sys.argv[2]
154 suppressionfile = sys.argv[3]
158 refspec = ts.parseSpec(refspecfile)
159 altspec = ts.parseSpec(altspecfile)
160 suppressions = load_suppressions(suppressionfile)
164 for w in compare_specs(refspec, altspec):
165 if not w in suppressions:
168 if len(warnings) == 0:
172 print "WARNING %s" % w