summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2017-10-27 21:24:08 +0200
committerMichał Górny <mgorny@gentoo.org>2017-10-27 21:24:08 +0200
commit3f03960384881dfb41050599f9cb224f3a134a9e (patch)
tree817c55217107a53c08d3a7635cf8085545e7bb0c
parent948ed8eff9c98df8b11c292486f42308da179f64 (diff)
downloadgemato-3f03960384881dfb41050599f9cb224f3a134a9e.tar.gz
recursiveloader: Support saving Manifests
-rw-r--r--gemato/recursiveloader.py17
-rw-r--r--tests/test_recursiveloader.py19
2 files changed, 36 insertions, 0 deletions
diff --git a/gemato/recursiveloader.py b/gemato/recursiveloader.py
index 96a5365..16c188b 100644
--- a/gemato/recursiveloader.py
+++ b/gemato/recursiveloader.py
@@ -60,6 +60,23 @@ class ManifestRecursiveLoader(object):
self.loaded_manifests[relpath] = m
return m
+ def save_manifest(self, relpath):
+ """
+ Save a single Manifest file whose relative path within Manifest
+ tree is @relpath. The Manifest must already be loaded.
+ If the name indicates compression, it will be compressed
+ transparently. If it was OpenPGP-signed, a new signature
+ will be created.
+ """
+ m = self.loaded_manifests[relpath]
+ path = os.path.join(self.root_directory, relpath)
+ with gemato.compression.open_potentially_compressed_path(
+ path, 'w', encoding='utf8') as f:
+ if m.openpgp_signed:
+ raise NotImplementedError(
+ 'Manifest signing not implemented yet')
+ m.dump(f)
+
def _iter_manifests_for_path(self, path, recursive=False):
"""
Iterate over loaded Manifests that can apply to path.
diff --git a/tests/test_recursiveloader.py b/tests/test_recursiveloader.py
index 29bfb0f..3debeaa 100644
--- a/tests/test_recursiveloader.py
+++ b/tests/test_recursiveloader.py
@@ -284,6 +284,17 @@ DATA test 0 MD5 d41d8cd98f00b204e9800998ecf8427e
os.path.join(self.dir, 'other')]),
1)
+ def test_save_manifest(self):
+ """
+ Test if saving the (unmodified) Manifest works.
+ """
+ m = gemato.recursiveloader.ManifestRecursiveLoader(
+ os.path.join(self.dir, 'Manifest'))
+ m.save_manifest('Manifest')
+ with io.open(os.path.join(self.dir, 'Manifest'),
+ 'r', encoding='utf8') as f:
+ self.assertEqual(f.read(), self.FILES['Manifest'].lstrip())
+
class MultipleManifestTest(TempDirTestCase):
DIRS = ['sub']
@@ -1045,6 +1056,14 @@ DATA test 0 MD5 d41d8cd98f00b204e9800998ecf8427e
gemato.cli.main(['gemato', 'verify', self.dir]),
0)
+ def test_save_manifest(self):
+ m = gemato.recursiveloader.ManifestRecursiveLoader(
+ os.path.join(self.dir, 'Manifest.gz'))
+ m.save_manifest('Manifest.gz')
+ with gemato.compression.open_potentially_compressed_path(
+ os.path.join(self.dir, 'Manifest.gz'), 'rb') as f:
+ self.assertEqual(f.read(), self.MANIFEST.lstrip())
+
class CompressedSubManifestTest(TempDirTestCase):
"""