From ee4abf959f1c2cec22d3d6592f21577869681ec1 Mon Sep 17 00:00:00 2001 From: Ed Bartosh Date: Sun, 22 Sep 2013 15:23:46 +0300 Subject: [PATCH] Skip packages for not specified architectures Output architectures are passed to repomaker API from caller. Packages with not specified architectures should not go to output repository. Change-Id: I370e1c67542ebda45a5185b50569821d37f0ac61 Signed-off-by: Ed Bartosh --- common/repomaker.py | 20 ++++++++++---------- tests/test_repomaker.py | 19 ++++++++++++------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/common/repomaker.py b/common/repomaker.py index 387a2dc..ee7534d 100644 --- a/common/repomaker.py +++ b/common/repomaker.py @@ -45,26 +45,27 @@ def find_files(topdir, prefix='', suffix='.rpm'): if item.startswith(prefix) and item.endswith(suffix): yield os.path.join(root, item) -def collect(in_dir): - """Collect files, binary archs and destinations.""" +def collect(in_dir, archs): + """Collect files, and destinations.""" files = [] - archs = set() for fname in find_files(in_dir): ftype = fname.split('.')[-2] # Unify arch name ftype = ARCH_MAP.get(ftype, ftype) - basename = os.path.basename(fname) if ftype not in ("src", "noarch"): - archs.add(ftype) + if ftype not in archs: + # skip packages for unknown architectures + continue + basename = os.path.basename(fname) is_debug = "-debugsource-" in fname or "-debuginfo-" in fname is_group = basename.startswith("package-groups-") and not is_debug is_imageconf = basename.startswith("image-configurations-") and \ not is_debug files.append((fname, ftype, is_debug, is_group, is_imageconf)) - return files, archs + return files def create_dirs(repo_dir, archs): """Create directory structure of the repos.""" @@ -147,15 +148,14 @@ class RepoMaker(object): if name not in self.repos: self.repos[name] = {'archs': set(archs)} - files, archs = collect(in_dir) - self.repos[name]['archs'].update(archs) + files = collect(in_dir, archs) # Create directory structure - dirs = create_dirs(repo_dir, self.repos[name]['archs']) + dirs = create_dirs(repo_dir, archs) for fpath, ftype, is_debug, is_group, is_imageconf in files: # Prepare list of target directories - target_dirs = gen_target_dirs(repo_dir, self.repos[name]['archs'], + target_dirs = gen_target_dirs(repo_dir, archs, ftype, is_debug) # Move or hardlink .rpm to target dirs diff --git a/tests/test_repomaker.py b/tests/test_repomaker.py index 3596845..4e7ca43 100644 --- a/tests/test_repomaker.py +++ b/tests/test_repomaker.py @@ -106,10 +106,11 @@ class RepoMakerTest(unittest.TestCase): def test_add_repo(self): """Test converting repository to the download structure.""" with tempdir(prefix='repomaker.', suffix='.inrepo') as in_repo: - prepare_dir(in_repo, ['src', 'noarch', 'i586', 'i686', 'x86_64']) + prepare_dir(in_repo, ['src', 'noarch', 'i586', 'i686', 'x86_64', + 'armv7el']) with tempdir(prefix='repomaker.', suffix='.outrepo') as out_repo: maker = RepoMaker('test-id', out_repo) - maker.add_repo(in_repo, 'testrepo', ('i586', 'x86_64'), + maker.add_repo(in_repo, 'testrepo', ('ia32', 'x86_64'), move=True, gpg_key='key', signer='/bin/true', buildconf='buildconf') # Check repo structure @@ -142,13 +143,17 @@ class RepoMakerTest(unittest.TestCase): 'x86_64/debug': [] } + baserepo = os.path.join(out_repo, 'test-id', + 'repos', 'testrepo') + # Make sure that not interesting arch armv7el has been skipped + gen_arches = sorted(os.path.basename(path) \ + for path in glob.glob(os.path.join(baserepo, '*'))) + self.assertEqual(gen_arches, ['ia32', 'sources', 'x86_64']) + + # test if all packages are present in primary.xml for arch in ('sources', 'ia32/packages', 'ia32/debug', 'x86_64/packages', 'x86_64/debug'): - primary_path = glob.glob(os.path.join(out_repo, - 'test-id', - 'repos', - 'testrepo', - arch, + primary_path = glob.glob(os.path.join(baserepo, arch, 'repodata', '*primary.xml.gz'))[0] dom = minidom.parse(gzip.open(primary_path)) -- 2.7.4