
import sys
import os
import xml.etree.ElementTree as ET

if len(sys.argv) < 2:
    print("not enough arguments")
    sys.exit(1)


root = ET.Element("gresources")
n_gresource = ET.SubElement(root, "gresource", {"prefix": "/org/freedesktop/fwupd"})
for fn in sorted(sys.argv[2:]):
    n_file = ET.SubElement(n_gresource, "file", {"compressed": "true"})
    n_file.text = fn
    if fn.endswith(".xml"):
        n_file.set("preprocess", "xml-stripblanks")
    n_file.set("alias", os.path.basename(fn))
with open(sys.argv[1], "wb") as f:
    f.write(ET.tostring(root, "utf-8", xml_declaration=True))

sys.exit(0)


import sys
import os
import xml.etree.ElementTree as ET

if len(sys.argv) < 2:
    print("not enough arguments")
    sys.exit(1)


root = ET.Element("gresources")
n_gresource = ET.SubElement(root, "gresource", {"prefix": "/org/freedesktop/fwupd"})
for fn in sorted(sys.argv[2:]):
    n_file = ET.SubElement(n_gresource, "file", {"compressed": "true"})
    n_file.text = fn
    if fn.endswith(".xml"):
        n_file.set("preprocess", "xml-stripblanks")
    n_file.set("alias", os.path.basename(fn))
with open(sys.argv[1], "wb") as f:
    try:
        f.write(ET.tostring(root, "utf-8", xml_declaration=True))
    except TypeError:
        f.write(ET.tostring(root, "utf-8"))

sys.exit(0)

Fix compile when using python 3.7 or older
trivial: Fix compile when using python 3.7 or older

Signed-off-by: Richard Hughes <320bca71fc381a4a025636043ca86e734e31cf8b@hughsie.com>

  
  import sys
  import os
  import xml.etree.ElementTree as ET
  
  if len(sys.argv) < 2:
      print("not enough arguments")
      sys.exit(1)
  
  
  root = ET.Element("gresources")
  n_gresource = ET.SubElement(root, "gresource", {"prefix": "/org/freedesktop/fwupd"})
  for fn in sorted(sys.argv[2:]):
      n_file = ET.SubElement(n_gresource, "file", {"compressed": "true"})
      n_file.text = fn
      if fn.endswith(".xml"):
          n_file.set("preprocess", "xml-stripblanks")
      n_file.set("alias", os.path.basename(fn))
  with open(sys.argv[1], "wb") as f:
+     try:
-     f.write(ET.tostring(root, "utf-8", xml_declaration=True))
+         f.write(ET.tostring(root, "utf-8", xml_declaration=True))
+     except TypeError:
+         f.write(ET.tostring(root, "utf-8"))
  
  sys.exit(0)
  
Fix compile when using python 3.7 or older
## Code Before:

import sys
import os
import xml.etree.ElementTree as ET

if len(sys.argv) < 2:
    print("not enough arguments")
    sys.exit(1)


root = ET.Element("gresources")
n_gresource = ET.SubElement(root, "gresource", {"prefix": "/org/freedesktop/fwupd"})
for fn in sorted(sys.argv[2:]):
    n_file = ET.SubElement(n_gresource, "file", {"compressed": "true"})
    n_file.text = fn
    if fn.endswith(".xml"):
        n_file.set("preprocess", "xml-stripblanks")
    n_file.set("alias", os.path.basename(fn))
with open(sys.argv[1], "wb") as f:
    f.write(ET.tostring(root, "utf-8", xml_declaration=True))

sys.exit(0)

## Instruction:
Fix compile when using python 3.7 or older
## Code After:

import sys
import os
import xml.etree.ElementTree as ET

if len(sys.argv) < 2:
    print("not enough arguments")
    sys.exit(1)


root = ET.Element("gresources")
n_gresource = ET.SubElement(root, "gresource", {"prefix": "/org/freedesktop/fwupd"})
for fn in sorted(sys.argv[2:]):
    n_file = ET.SubElement(n_gresource, "file", {"compressed": "true"})
    n_file.text = fn
    if fn.endswith(".xml"):
        n_file.set("preprocess", "xml-stripblanks")
    n_file.set("alias", os.path.basename(fn))
with open(sys.argv[1], "wb") as f:
    try:
        f.write(ET.tostring(root, "utf-8", xml_declaration=True))
    except TypeError:
        f.write(ET.tostring(root, "utf-8"))

sys.exit(0)
