From a584803cfa2ae6421b9199363ca8989304adc382 Mon Sep 17 00:00:00 2001 From: Gertjan Klein Date: Wed, 16 Dec 2020 17:25:05 +0100 Subject: [PATCH] Use lxml to preserve attribute order in data exports. --- copy-iris-items.py | 13 +++++++++++-- requirements.txt | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/copy-iris-items.py b/copy-iris-items.py index 8a4cdc5..ab2e4f3 100644 --- a/copy-iris-items.py +++ b/copy-iris-items.py @@ -12,7 +12,7 @@ import base64 import urllib.request as urq import json -import xml.etree.ElementTree as ET +import lxml.etree as ET import data_handler from config import get_config, ConfigurationError @@ -250,7 +250,7 @@ def save_deployable_settings(config): fname = join(config.datadir, config.Project.enssettings.name) # Remove timestamp and version from export - root = ET.fromstring(data) + root = ET.fromstring(data.encode('UTF-8')) for name in 'ts', 'zv': if name in root.attrib: del root.attrib[name] @@ -293,6 +293,15 @@ def save_lookup_tables(config): logging.info(f" {table} contains no data, skipping.") continue + # Remove timestamp and version from export + root = ET.fromstring(data.encode('UTF-8')) + for name in 'ts', 'zv': + if name in root.attrib: + del root.attrib[name] + # tostring doesn't return an XML declaration + data = '\n' + data += ET.tostring(root, encoding='unicode') + # Make sure the output directory exists if not isdir(config.datadir): os.makedirs(config.datadir) diff --git a/requirements.txt b/requirements.txt index bd79a65..67b7ea9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ toml +lxml