You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ponymail.apache.org by se...@apache.org on 2020/08/29 15:43:01 UTC

[incubator-ponymail-unit-tests] 01/02: Tool to canonicalise yaml files

This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-unit-tests.git

commit 167290a3972f37efd24e9e9437483491f5a339d4
Author: Sebb <se...@apache.org>
AuthorDate: Sat Aug 29 16:42:00 2020 +0100

    Tool to canonicalise yaml files
---
 tools/yaml_sort.py | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/tools/yaml_sort.py b/tools/yaml_sort.py
new file mode 100755
index 0000000..3e88646
--- /dev/null
+++ b/tools/yaml_sort.py
@@ -0,0 +1,27 @@
+#!/usr/bin/env python3
+"""
+Sort yaml files so they can be compared easily.
+"""
+
+import sys
+import yaml
+
+yml = yaml.safe_load(open(sys.argv[1], 'r'))
+
+# update the dict in place
+for key1 in yml.keys():
+    if key1 == 'parsing':
+        for key2 in yml[key1]:
+            for entry in yml[key1][key2]:
+                # fix up the order by dropping and re-adding
+                for n in ['index', 'message-id', 'body_sha3_256', 'attachments']:
+                    entry[n] = entry.pop(n)
+    elif key1 == 'generators':
+        for key2 in yml[key1]:
+            for key3 in yml[key1][key2]:
+                for entry in yml[key1][key2][key3]:
+                    # fix up the order by dropping and re-adding
+                    for n in ['index', 'message-id', 'generated']:
+                        entry[n] = entry.pop(n)
+
+yaml.dump(yml,sys.stdout, sort_keys=False)
\ No newline at end of file