def _get_build_arches_from_srpm(srpm, arches): """Given the path to an srpm, determine the possible build arches Use supplied arches as a filter, only return compatible arches """ archlist = arches hdr = koji.get_rpm_header(srpm) if hdr[rpm.RPMTAG_SOURCEPACKAGE] != 1: raise FedpkgError('%s is not a source package.' % srpm) buildarchs = hdr[rpm.RPMTAG_BUILDARCHS] exclusivearch = hdr[rpm.RPMTAG_EXCLUSIVEARCH] excludearch = hdr[rpm.RPMTAG_EXCLUDEARCH] # Reduce by buildarchs if buildarchs: archlist = [a for a in archlist if a in buildarchs] # Reduce by exclusive arches if exclusivearch: archlist = [a for a in archlist if a in exclusivearch] # Reduce by exclude arch if excludearch: archlist = [a for a in archlist if a not in excludearch] # do the noarch thing if 'noarch' not in excludearch and ('noarch' in buildarchs or \ 'noarch' in exclusivearch): archlist.append('noarch') # See if we have anything compatible. Should we raise here? if not archlist: raise FedpkgError('No compatible build arches found in %s' % srpm) return archlist
def test_explode_cpio(tmpdir): """explode_srpm_cpio correctly unpacks files in the typical case.""" srpm = os.path.join(RPMS_PATH, "fake-1.1-22.src.rpm") # Simulate that we're exploding into an existing git checkout. tmpdir.mkdir(".git") tmpdir.join(".git").join("config").write("foobar") # SRPM can be exploded without raising header = koji.get_rpm_header(srpm) explode_srpm_cpio(srpm, header, str(tmpdir)) # Destination directory contains expected files output_files = [] for (dirpath, dirnames, filenames) in os.walk(str(tmpdir)): dirpath = os.path.relpath(dirpath, str(tmpdir)) for filename in filenames: output_files.append(os.path.join(dirpath, filename)) # It should extract exactly the expected files and should not touch unrelated files assert sorted(output_files) == [ ".git/config", "SOURCES/foo.txt", "SPECS/fake.spec", ]
def _extract_filesigs(rpm_path, output_path): sighdr = rip_rpm_sighdr(rpm_path) sighdr = RawHeader(sighdr) filesigs = _get_header_type_8(sighdr, RPMSIGTAG_FILESIGNATURES) rpm_hdr = get_rpm_header(rpm_path) diridxs = rpm_hdr[rpm.RPMTAG_DIRINDEXES] dirnames = rpm_hdr[rpm.RPMTAG_DIRNAMES] basenames = rpm_hdr[rpm.RPMTAG_BASENAMES] if len(basenames) != len(filesigs): raise Exception("Invalid number of file signatures (%d) for basenames (%d)" % (len(filesigs), len(basenames))) if len(diridxs) != len(basenames): raise Exception("Invalid number of diridxs (%d) for basenames (%d)" % (len(diridxs), len(basenames))) for i in range(len(basenames)): basename = basenames[i] dirname = dirnames[diridxs[i]] if dirname.startswith('/'): dirname = dirname[1:] full_path = os.path.join(output_path, dirname, basename) filesig = filesigs[i] if sys.version_info.major == 2: filesig = bytes(filesig) xattr.setxattr(full_path, 'user.ima', filesig)
def test_get_header_fields(self): # incorrect self.assertRaises(IOError, koji.get_header_fields, 'nonexistent_path', []) self.assertRaises(koji.GenericError, koji.get_header_fields, self.rpm_path, 'nonexistent_header') self.assertEqual(koji.get_header_fields(self.rpm_path, []), {}) # correct self.assertEqual(['REQUIRES'], list(koji.get_header_fields(self.rpm_path, ['REQUIRES']).keys())) self.assertEqual(['PROVIDES', 'REQUIRES'], sorted(koji.get_header_fields(self.rpm_path, ['REQUIRES', 'PROVIDES']))) hdr = koji.get_rpm_header(self.rpm_path) self.assertEqual(['REQUIRES'], list(koji.get_header_fields(hdr, ['REQUIRES']).keys()))
def extract_header(input_path, header_out_path, digest_out_path): (sig_start, sig_size) = find_rpm_sighdr(input_path) hdr_start = sig_start + sig_size hdr_size = rpm_hdr_size(input_path, hdr_start) rpm_hdr = get_rpm_header(input_path) file_digestalgo, file_digests = _get_filedigests(rpm_hdr) file_digests = set(file_digests) with open(digest_out_path, "at") as df: for digest in file_digests: digest = digest.strip() if not digest: continue df.write("%s %s\n" % (file_digestalgo, digest)) with open(input_path, "rb") as f: f.seek(hdr_start) with open(header_out_path, "wb") as of: of.write(f.read(hdr_size))
def test_get_rpm_header(self): self.assertRaises(IOError, koji.get_rpm_header, 'nonexistent_path') self.assertRaises(AttributeError, koji.get_rpm_header, None) self.assertIsInstance(koji.get_rpm_header(self.rpm_path), rpm.hdr) self.assertIsInstance(koji.get_rpm_header(self.fd), rpm.hdr)