ftype = ARCH_MAP.get(ftype, ftype)
basename = os.path.basename(fname)
- if ftype != "src":
+ if ftype not in ("src", "noarch"):
archs.add(ftype)
is_debug = "-debugsource-" in fname or "-debuginfo-" in fname
self.repos = {}
self.imagedata = None
- def add_repo(self, in_dir, name, buildconf=None, move=False, gpg_key=None,
- signer='/usr/bin/sign'):
+ def add_repo(self, in_dir, name, archs = (), buildconf=None,
+ move=False, gpg_key=None, signer='/usr/bin/sign'):
"""
Convert repository to download structure.
Create or update repository using packages from repo_dir
Args:
in_dir (str): path to repository to convert
name (str): name of the repository to create
+ archs (tuple): list of architectures
buildconf(str): content of build configuration
move (bool): move files instead of hardlinking
gpg_key (str): path to file with gpg key
repo_dir = os.path.join(self.outdir, "repos", name)
if name not in self.repos:
- self.repos[name] = {'archs': set()}
+ self.repos[name] = {'archs': set(archs)}
files, archs = collect(in_dir)
self.repos[name]['archs'].update(archs)
for fpath, ftype, is_debug, is_group, is_imageconf in files:
# Prepare list of target directories
- target_dirs = gen_target_dirs(repo_dir, archs, ftype, is_debug)
+ target_dirs = gen_target_dirs(repo_dir, self.repos[name]['archs'],
+ ftype, is_debug)
# Move or hardlink .rpm to target dirs
move_or_hardlink(fpath, target_dirs, move)
finally:
shutil.rmtree(tmpdir)
+def prepare_dir(in_repo, arches):
+ """Create test directory structure."""
+ files = ["%s-%s.%s.rpm" % (name, version, arch) \
+ for name in ("pkg1", "pkg2", "pkg3") \
+ for version in ("0.1-2.3", "1.2-3.4") \
+ for arch in arches]
+ for fname in files:
+ subdir = fname.split('.')[-2]
+ #subdir = ('', fname)[files.index(fname) % 2]
+ dir_path = os.path.join(in_repo, subdir)
+ if not os.path.exists(dir_path):
+ os.makedirs(dir_path)
+ with open(os.path.join(dir_path, fname), 'w') as frpm:
+ frpm.write(RPM)
+
class RepoMakerTest(unittest.TestCase):
'''Tests for RepoMaker functionality.'''
def test_add_repo(self):
"""Test converting repository to the download structure."""
with tempdir(prefix='repomaker.', suffix='.inrepo') as in_repo:
- # prepare directory with rpms
- arches = ('src', 'noarch', 'i586', 'x86_64')
- files = ["%s-%s.%s.rpm" % (name, version, arch) \
- for name in ("pkg1", "pkg2", "pkg3") \
- for version in ("0.1-2.3", "1.2-3.4") \
- for arch in arches]
- for fname in files:
- subdir = ('', fname)[files.index(fname)%2]
- dir_path = os.path.join(in_repo, subdir)
- if not os.path.exists(dir_path):
- os.makedirs(dir_path)
- with open(os.path.join(dir_path, fname), 'w') as frpm:
- frpm.write(RPM)
-
+ prepare_dir(in_repo, ['src', 'noarch', 'i586', 'x86_64'])
with tempdir(prefix='repomaker.', suffix='.outrepo') as out_repo:
maker = RepoMaker('test-id', out_repo)
- maker.add_repo(in_repo, 'testrepo', move=True, gpg_key='key',
- signer='/bin/true', buildconf='buildconf')
+ maker.add_repo(in_repo, 'testrepo', ('i586', 'x86_64'),
+ move=True, gpg_key='key', signer='/bin/true',
+ buildconf='buildconf')
# Check repo structure
results = {
'sources':
packages = sorted(elem.getAttribute('href') for elem in \
dom.getElementsByTagName('location'))
self.assertEqual(packages, results[arch])
+
+
+ def test_add_repo_noarch(self):
+ """
+ Test converting repository to the download structure.
+ Input repo contains only noarch packages.
+ """
+ with tempdir(prefix='repomaker.', suffix='.inrepo') as in_repo:
+ prepare_dir(in_repo, ['src', 'noarch'])
+
+ with tempdir(prefix='repomaker.', suffix='.outrepo') as out_repo:
+ maker = RepoMaker('test-id', out_repo)
+ maker.add_repo(in_repo, 'testrepo-noarch', ('ia32', 'x86_64'),
+ move=True, gpg_key='key', signer='/bin/true',
+ buildconf='buildconf')
+ # Check repo structure
+ results = {
+ 'sources':
+ ['pkg1-0.1-2.3.src.rpm', 'pkg1-1.2-3.4.src.rpm',
+ 'pkg2-0.1-2.3.src.rpm', 'pkg2-1.2-3.4.src.rpm',
+ 'pkg3-0.1-2.3.src.rpm', 'pkg3-1.2-3.4.src.rpm'],
+ 'ia32/packages':
+ ['pkg1-0.1-2.3.noarch.rpm',
+ 'pkg1-1.2-3.4.noarch.rpm',
+ 'pkg2-0.1-2.3.noarch.rpm',
+ 'pkg2-1.2-3.4.noarch.rpm',
+ 'pkg3-0.1-2.3.noarch.rpm',
+ 'pkg3-1.2-3.4.noarch.rpm'],
+ 'ia32/debug': [],
+ 'x86_64/packages':
+ ['pkg1-0.1-2.3.noarch.rpm',
+ 'pkg1-1.2-3.4.noarch.rpm',
+ 'pkg2-0.1-2.3.noarch.rpm',
+ 'pkg2-1.2-3.4.noarch.rpm',
+ 'pkg3-0.1-2.3.noarch.rpm',
+ 'pkg3-1.2-3.4.noarch.rpm'],
+ 'x86_64/debug': []
+ }
+
+ 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-noarch',
+ arch,
+ 'repodata',
+ '*primary.xml.gz'))[0]
+ #print 'primary_path=', primary_path
+ dom = minidom.parse(gzip.open(primary_path))
+ packages = sorted(elem.getAttribute('href') for elem in \
+ dom.getElementsByTagName('location'))
+ print 'packages:', arch, packages, results[arch]
+ self.assertEqual(packages, results[arch])