Skip to content

Commit

Permalink
Use lxml to preserve attribute order in data exports.
Browse files Browse the repository at this point in the history
  • Loading branch information
gertjanklein committed Dec 16, 2020
1 parent 5c7bd78 commit a584803
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
13 changes: 11 additions & 2 deletions copy-iris-items.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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 = '<?xml version="1.0" encoding="UTF-8"?>\n'
data += ET.tostring(root, encoding='unicode')

# Make sure the output directory exists
if not isdir(config.datadir):
os.makedirs(config.datadir)
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
toml
lxml

0 comments on commit a584803

Please sign in to comment.