diff options
-rw-r--r-- | gemato/recursiveloader.py | 14 | ||||
-rw-r--r-- | tests/test_recursiveloader.py | 20 |
2 files changed, 30 insertions, 4 deletions
diff --git a/gemato/recursiveloader.py b/gemato/recursiveloader.py index 20fbb0b..19d72b8 100644 --- a/gemato/recursiveloader.py +++ b/gemato/recursiveloader.py @@ -106,13 +106,16 @@ class ManifestRecursiveLoader(object): self.loaded_manifests[relpath] = m return m - def save_manifest(self, relpath): + def save_manifest(self, relpath, sort=False): """ 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. + + If @sort is True, the Manifest entries will be sorted prior + to saving. """ m = self.loaded_manifests[relpath] path = os.path.join(self.root_directory, relpath) @@ -126,7 +129,7 @@ class ManifestRecursiveLoader(object): with gemato.compression.open_potentially_compressed_path( path, 'w', encoding='utf8') as f: - m.dump(f, sign_openpgp=sign, + m.dump(f, sign_openpgp=sign, sort=sort, openpgp_env=self.openpgp_env, openpgp_keyid=self.openpgp_keyid) @@ -400,7 +403,7 @@ class ManifestRecursiveLoader(object): return ret - def save_manifests(self, hashes=None, force=False): + def save_manifests(self, hashes=None, force=False, sort=False): """ Save the Manifests modified since the last save_manifests() call. @@ -413,6 +416,9 @@ class ManifestRecursiveLoader(object): If @force is True, all Manifests will be rewritten even if they were not modified. + + If @sort is True, the Manifest entries will be sorted prior + to saving. """ if hashes is None: @@ -445,7 +451,7 @@ class ManifestRecursiveLoader(object): # we've apparently modified this Manifest, so store it now if force or mpath in self.updated_manifests: - self.save_manifest(mpath) + self.save_manifest(mpath, sort=sort) # now, discard all the Manifests whose entries we've updated self.updated_manifests -= fixed_manifests diff --git a/tests/test_recursiveloader.py b/tests/test_recursiveloader.py index 1e9b186..68ed602 100644 --- a/tests/test_recursiveloader.py +++ b/tests/test_recursiveloader.py @@ -374,6 +374,26 @@ DATA test 0 MD5 d41d8cd98f00b204e9800998ecf8427e 'r', encoding='utf8') as f: self.assertNotEqual(f.read(), self.FILES['sub/Manifest']) + def test_save_manifests_force_sort(self): + m = gemato.recursiveloader.ManifestRecursiveLoader( + os.path.join(self.dir, 'Manifest')) + m.save_manifests(force=True, sort=True) + with io.open(os.path.join(self.dir, 'Manifest'), + 'r', encoding='utf8') as f: + self.assertEqual(f.read(), u''' +DIST topdistfile-1.txt 0 MD5 d41d8cd98f00b204e9800998ecf8427e +MANIFEST other/Manifest 0 MD5 d41d8cd98f00b204e9800998ecf8427e +MANIFEST sub/Manifest 145 MD5 75e2be2f56f58e486fd195ec4d96da4a +TIMESTAMP 2017-01-01T01:01:01Z +'''.lstrip()) + with io.open(os.path.join(self.dir, 'sub/Manifest'), + 'r', encoding='utf8') as f: + self.assertEqual(f.read(), u''' +DIST subdistfile-1.txt 0 MD5 d41d8cd98f00b204e9800998ecf8427e +MANIFEST deeper/Manifest 49 MD5 b86a7748346d54c6455886306f017e6c +OPTIONAL nonstray +'''.lstrip()) + def test_update_entry_for_path(self): m = gemato.recursiveloader.ManifestRecursiveLoader( os.path.join(self.dir, 'Manifest')) |