summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gemato/manifest.py28
-rw-r--r--tests/test_manifest.py17
2 files changed, 44 insertions, 1 deletions
diff --git a/gemato/manifest.py b/gemato/manifest.py
index 8683f95..ebdb71f 100644
--- a/gemato/manifest.py
+++ b/gemato/manifest.py
@@ -40,6 +40,13 @@ class ManifestEntryTIMESTAMP(object):
def to_list(self):
return (self.tag, self.ts.strftime('%Y-%m-%dT%H:%M:%SZ'))
+ def __eq__(self, other):
+ return self.tag == other.tag and self.ts == other.ts
+
+ def __lt__(self, other):
+ return (self.tag < other.tag
+ or (self.tag == other.tag and self.ts < other.ts))
+
class ManifestPathEntry(object):
"""
@@ -62,6 +69,13 @@ class ManifestPathEntry(object):
'{} line: expected relative path, got: {}'.format(l[0], l[1:]))
return l[1]
+ def __eq__(self, other):
+ return self.tag == other.tag and self.path == other.path
+
+ def __lt__(self, other):
+ return (self.tag < other.tag
+ or (self.tag == other.tag and self.path < other.path))
+
class ManifestEntryIGNORE(ManifestPathEntry):
"""
@@ -148,6 +162,13 @@ class ManifestFileEntry(ManifestPathEntry):
ret += [k, v]
return ret
+ def __eq__(self, other):
+ return (super(ManifestFileEntry, self).__eq__(other)
+ and self.size == other.size
+ and self.checksums == other.checksums)
+
+ # for the purpose of __lt__, the path is good enough for sorting
+
class ManifestEntryMANIFEST(ManifestFileEntry):
"""
@@ -409,7 +430,7 @@ class ManifestFile(object):
self.openpgp_signed = True
def dump(self, f, sign_openpgp=None, openpgp_keyid=None,
- openpgp_env=None):
+ openpgp_env=None, sort=False):
"""
Dump data into file @f. The file should be open for writing
in text mode, and truncated to zero length.
@@ -421,11 +442,16 @@ class ManifestFile(object):
@openpgp_keyid and @openpgp_env specify the key
and the environment to use for signing.
+
+ If @sort is True, the entries are sorted prior to dumping.
"""
if sign_openpgp is None:
sign_openpgp = self.openpgp_signed
+ if sort:
+ self.entries = sorted(self.entries)
+
if sign_openpgp:
with io.StringIO() as data:
# get the plain data into a stream
diff --git a/tests/test_manifest.py b/tests/test_manifest.py
index 973432a..ed5042d 100644
--- a/tests/test_manifest.py
+++ b/tests/test_manifest.py
@@ -19,6 +19,7 @@ DATA myebuild-0.ebuild 0 MD5 d41d8cd98f00b204e9800998ecf8427e SHA1 da39a3ee5e6b4
MISC metadata.xml 0 MD5 d41d8cd98f00b204e9800998ecf8427e SHA1 da39a3ee5e6b4b0d3255bfef95601890afd80709
OPTIONAL ChangeLog
DIST mydistfile.tar.gz 0 MD5 d41d8cd98f00b204e9800998ecf8427e SHA1 da39a3ee5e6b4b0d3255bfef95601890afd80709
+DATA foo.txt 0
'''
TEST_DEPRECATED_MANIFEST = u'''
@@ -115,6 +116,22 @@ class ManifestTest(unittest.TestCase):
self.assertIsNone(m.find_timestamp())
self.assertIsNone(m.find_path_entry('eclass/Manifest'))
+ def test_sorted(self):
+ m = gemato.manifest.ManifestFile()
+ m.load(io.StringIO(TEST_MANIFEST))
+ with io.StringIO() as f:
+ m.dump(f, sort=True)
+ self.assertEqual(f.getvalue(), u'''
+DATA foo.txt 0
+DATA myebuild-0.ebuild 0 MD5 d41d8cd98f00b204e9800998ecf8427e SHA1 da39a3ee5e6b4b0d3255bfef95601890afd80709
+DIST mydistfile.tar.gz 0 MD5 d41d8cd98f00b204e9800998ecf8427e SHA1 da39a3ee5e6b4b0d3255bfef95601890afd80709
+IGNORE local
+MANIFEST eclass/Manifest 0 MD5 d41d8cd98f00b204e9800998ecf8427e SHA1 da39a3ee5e6b4b0d3255bfef95601890afd80709
+MISC metadata.xml 0 MD5 d41d8cd98f00b204e9800998ecf8427e SHA1 da39a3ee5e6b4b0d3255bfef95601890afd80709
+OPTIONAL ChangeLog
+TIMESTAMP 2017-10-22T18:06:41Z
+'''.lstrip())
+
class ManifestEntryTest(unittest.TestCase):
"""