diff options
author | Michał Górny <mgorny@gentoo.org> | 2017-11-01 17:07:44 +0100 |
---|---|---|
committer | Michał Górny <mgorny@gentoo.org> | 2017-11-01 17:07:44 +0100 |
commit | 50f0f552ee1af6b5d2b8b749f5413788f21bcb8a (patch) | |
tree | ec828f9720f76dc2602a83770de6363235ab4f13 | |
parent | c3391d185af458b65c668c9902f596f35bf93bff (diff) | |
download | gemato-50f0f552ee1af6b5d2b8b749f5413788f21bcb8a.tar.gz |
profile: Support controlling sub-Manifest files
-rw-r--r-- | gemato/profile.py | 32 | ||||
-rw-r--r-- | gemato/recursiveloader.py | 14 | ||||
-rw-r--r-- | tests/test_profile.py | 19 |
3 files changed, 61 insertions, 4 deletions
diff --git a/gemato/profile.py b/gemato/profile.py index 2b551a6..b05addd 100644 --- a/gemato/profile.py +++ b/gemato/profile.py @@ -21,12 +21,42 @@ class DefaultProfile(object): """ return 'DATA' + def want_manifest_in_directory(self, relpath, dirnames, filenames): + return False + class EbuildRepositoryProfile(DefaultProfile): """ A profile suited for a modern ebuild repository. """ - pass + + def want_manifest_in_directory(self, relpath, dirnames, filenames): + # a quick way to catch most of packages and ::gentoo categories + if 'metadata.xml' in filenames: + return True + spl = relpath.split(os.path.sep) + # top level directories... + if len(spl) == 1: + # with any subdirectories (categories, metadata, profiles) + if len(dirnames) > 0: + return True + # plus some unconditional standard directories + if relpath in ('eclass', 'licenses', 'metadata', + 'profiles'): + return True + elif len(spl) == 2: + # 'slow' way of detecting package directories + if any(f.endswith('.ebuild') for f in filenames): + return True + # some standard directories worth separate Manifests + if spl[0] == 'metadata' and spl[1] in ('glsa', 'md5-cache', + 'news'): + return True + elif len(spl) == 3: + # metadata cache -> per-directory Manifests + if spl[0:2] == ['metadata', 'md5-cache']: + return True + return False class BackwardsCompatEbuildRepositoryProfile(EbuildRepositoryProfile): diff --git a/gemato/recursiveloader.py b/gemato/recursiveloader.py index a52f333..de826b3 100644 --- a/gemato/recursiveloader.py +++ b/gemato/recursiveloader.py @@ -816,6 +816,9 @@ class ManifestRecursiveLoader(object): manifest_stack[-1][1]): manifest_stack.pop() + want_manifest = self.profile.want_manifest_in_directory( + relpath, dirnames, filenames) + skip_dirs = [] for d in dirnames: # skip dotfiles @@ -883,6 +886,8 @@ class ManifestRecursiveLoader(object): fe = gemato.manifest.new_manifest_entry(ftype, fpath, 0, {}) new_entries.append(fe) + if relpath in self.updated_manifests: + continue changed = gemato.verify.update_entry_for_path( os.path.join(dirpath, f), @@ -892,6 +897,15 @@ class ManifestRecursiveLoader(object): if changed and mpath is not None: self.updated_manifests.add(mpath) + # do we have Manifest in this directory? + if want_manifest and manifest_stack[-1][1] != relpath: + mpath = os.path.join(relpath, 'Manifest') + m = self.create_manifest(mpath) + manifest_stack.append((mpath, relpath, m)) + fe = gemato.manifest.ManifestEntryMANIFEST( + mpath, 0, {}) + new_entries.append(fe) + if new_entries: mpath, mdirpath, m = manifest_stack[-1] for fe in new_entries: diff --git a/tests/test_profile.py b/tests/test_profile.py index ebc9406..b8cb02d 100644 --- a/tests/test_profile.py +++ b/tests/test_profile.py @@ -6,6 +6,7 @@ import os.path import gemato.profile +import gemato.recursiveloader from tests.testutil import TempDirTestCase @@ -38,6 +39,18 @@ class EbuildRepositoryTests(TempDirTestCase): 'profiles/desc', 'profiles/updates', ] + EXPECTED_MANIFESTS = [ + 'dev-foo/Manifest', + 'dev-foo/bar/Manifest', + 'eclass/Manifest', + 'licenses/Manifest', + 'metadata/Manifest', + 'metadata/glsa/Manifest', + 'metadata/md5-cache/Manifest', + 'metadata/md5-cache/dev-foo/Manifest', + 'metadata/news/Manifest', + 'profiles/Manifest', + ] EXPECTED_TYPES = { 'header.txt': 'DATA', 'skel.ebuild': 'DATA', @@ -102,6 +115,9 @@ class EbuildRepositoryTests(TempDirTestCase): m.find_path_entry(f).tag, expt, "type mismatch for {}".format(f)) + for f in self.EXPECTED_MANIFESTS: + self.assertEqual(m.find_path_entry(f).tag, 'MANIFEST', + "type mismatch for {}".format(f)) return m class BackwardsCompatEbuildRepositoryTests(EbuildRepositoryTests): @@ -114,9 +130,6 @@ class BackwardsCompatEbuildRepositoryTests(EbuildRepositoryTests): 'dev-foo/bar/metadata.xml': 'MISC', 'dev-foo/bar/files/test.patch': 'AUX', }) - # TODO: this is only temporary until we have API to create - # the Manifest at this level automatically - self.FILES['dev-foo/bar/Manifest'] = u'' super(BackwardsCompatEbuildRepositoryTests, self).__init__( *args, **kwargs) |