summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gemato/manifest.py21
-rw-r--r--tests/test_manifest.py20
2 files changed, 40 insertions, 1 deletions
diff --git a/gemato/manifest.py b/gemato/manifest.py
index b01e5d4..2c1f4b7 100644
--- a/gemato/manifest.py
+++ b/gemato/manifest.py
@@ -305,7 +305,6 @@ class ManifestFile(object):
tag = sl[0]
self.entries.append(MANIFEST_TAG_MAPPING[tag].from_list(sl))
-
def dump(self, f):
"""
Dump data into file @f. The file should be open for writing
@@ -314,3 +313,23 @@ class ManifestFile(object):
for e in self.entries:
f.write(u' '.join(e.to_list()) + '\n')
+
+ def find_path_entry(self, path):
+ """
+ Find a matching entry for path @path and return it. Returns
+ None when no path matches. DIST entries are not included.
+ """
+
+ for e in self.entries:
+ if isinstance(e, ManifestEntryIGNORE):
+ # ignore matches recursively, so we process it separately
+ # py<3.5 does not have os.path.commonpath()
+ if (path + '/').startswith(e.path + '/'):
+ return e
+ elif isinstance(e, ManifestEntryDIST):
+ # distfiles are not local files, so skip them
+ pass
+ elif isinstance(e, ManifestPathEntry):
+ if e.path == path:
+ return e
+ return None
diff --git a/tests/test_manifest.py b/tests/test_manifest.py
index e08bf36..5e72a8a 100644
--- a/tests/test_manifest.py
+++ b/tests/test_manifest.py
@@ -58,6 +58,26 @@ class ManifestTest(unittest.TestCase):
m.dump(outf)
self.assertEqual(outf.getvalue().strip(), TEST_DEPRECATED_MANIFEST.strip())
+ def test_find_path_entry(self):
+ m = gemato.manifest.ManifestFile()
+ m.load(io.StringIO(TEST_MANIFEST))
+ self.assertIsNone(m.find_path_entry('2017-10-22T18:06:41Z'))
+ self.assertEqual(m.find_path_entry('eclass/Manifest').path, 'eclass/Manifest')
+ self.assertIsNone(m.find_path_entry('eclass'))
+ self.assertEqual(m.find_path_entry('local').path, 'local')
+ self.assertEqual(m.find_path_entry('local/foo').path, 'local')
+ self.assertIsNone(m.find_path_entry('locale'))
+ self.assertEqual(m.find_path_entry('myebuild-0.ebuild').path, 'myebuild-0.ebuild')
+ self.assertEqual(m.find_path_entry('metadata.xml').path, 'metadata.xml')
+ self.assertEqual(m.find_path_entry('ChangeLog').path, 'ChangeLog')
+ self.assertIsNone(m.find_path_entry('mydistfile.tar.gz'))
+
+ def test_find_path_entry_AUX(self):
+ m = gemato.manifest.ManifestFile()
+ m.load(io.StringIO(TEST_DEPRECATED_MANIFEST))
+ self.assertIsNone(m.find_path_entry('test.patch'))
+ self.assertEqual(m.find_path_entry('files/test.patch').aux_path, 'test.patch')
+
class ManifestEntryTest(unittest.TestCase):
"""