diff options
-rw-r--r-- | gemato/recursiveloader.py | 14 | ||||
-rw-r--r-- | tests/test_recursiveloader.py | 33 |
2 files changed, 45 insertions, 2 deletions
diff --git a/gemato/recursiveloader.py b/gemato/recursiveloader.py index 24e705b..06753d1 100644 --- a/gemato/recursiveloader.py +++ b/gemato/recursiveloader.py @@ -272,11 +272,15 @@ class ManifestRecursiveLoader(object): return e return None - def get_file_entry_dict(self, path=''): + def get_file_entry_dict(self, path='', only_types=None): """ Find all file entries that apply to paths starting with @path. Return a dictionary mapping relative paths to entries. Raises an exception if multiple entries for file collide. + + If @only_types are specified as a list, only files of specified + types will be collected. If it is not specified, then all types + for local files will be processed. """ self.load_manifests_for_path(path, recursive=True) @@ -284,7 +288,13 @@ class ManifestRecursiveLoader(object): for mpath, relpath, m in self._iter_manifests_for_path(path, recursive=True): for e in m.entries: - if e.tag in ('DIST', 'TIMESTAMP'): + if only_types is not None: + if e.tag not in only_types: + continue + # DIST entries always specify plain filename + if e.tag == 'DIST': + relpath = '' + elif e.tag in ('DIST', 'TIMESTAMP'): # distfiles are not local files, so skip them # timestamp is not a file ;-) continue diff --git a/tests/test_recursiveloader.py b/tests/test_recursiveloader.py index ddff0b1..097cd69 100644 --- a/tests/test_recursiveloader.py +++ b/tests/test_recursiveloader.py @@ -203,6 +203,32 @@ DATA test 0 MD5 d41d8cd98f00b204e9800998ecf8427e self.assertEqual(entries['sub/deeper/Manifest'].path, 'deeper/Manifest') self.assertEqual(entries['sub/deeper/test'].path, 'test') + def test_get_file_entry_dict_only_types(self): + m = gemato.recursiveloader.ManifestRecursiveLoader( + os.path.join(self.dir, 'Manifest')) + entries = m.get_file_entry_dict('', only_types=['MANIFEST']) + self.assertSetEqual(frozenset(entries), + frozenset(( + 'other/Manifest', + 'sub/Manifest', + 'sub/deeper/Manifest', + ))) + self.assertEqual(entries['other/Manifest'].path, 'other/Manifest') + self.assertEqual(entries['sub/Manifest'].path, 'sub/Manifest') + self.assertEqual(entries['sub/deeper/Manifest'].path, 'deeper/Manifest') + + def test_get_file_entry_dict_only_types_DIST(self): + m = gemato.recursiveloader.ManifestRecursiveLoader( + os.path.join(self.dir, 'Manifest')) + entries = m.get_file_entry_dict('', only_types=['DIST']) + self.assertSetEqual(frozenset(entries), + frozenset(( + 'subdistfile-1.txt', + 'topdistfile-1.txt', + ))) + self.assertEqual(entries['subdistfile-1.txt'].path, 'subdistfile-1.txt') + self.assertEqual(entries['topdistfile-1.txt'].path, 'topdistfile-1.txt') + def test_get_deduplicated_file_entry_dict_for_update(self): m = gemato.recursiveloader.ManifestRecursiveLoader( os.path.join(self.dir, 'Manifest')) @@ -1276,6 +1302,13 @@ MISC test.ebuild 0 MD5 d41d8cd98f00b204e9800998ecf8427e self.assertRaises(gemato.exceptions.ManifestIncompatibleEntry, m.get_file_entry_dict, '') + def test_get_file_entry_dict_only_types(self): + m = gemato.recursiveloader.ManifestRecursiveLoader( + os.path.join(self.dir, 'Manifest')) + entries = m.get_file_entry_dict('', only_types=['DATA']) + self.assertListEqual(sorted(entries), ['test.ebuild']) + self.assertEqual(entries['test.ebuild'].tag, 'DATA') + def test_deduplicated_get_file_entry_dict_for_update(self): m = gemato.recursiveloader.ManifestRecursiveLoader( os.path.join(self.dir, 'Manifest')) |