mirror of
https://github.com/archlinuxarm/PKGBUILDs.git
synced 2024-11-18 22:54:00 +00:00
68 lines
2.1 KiB
Diff
68 lines
2.1 KiB
Diff
--- a/tools/rst2odt_prepstyles.py
|
|
+++ b/tools/rst2odt_prepstyles.py
|
|
@@ -12,7 +12,15 @@
|
|
#
|
|
# Author: Michael Schutte <michi@uiae.at>
|
|
|
|
-from lxml import etree
|
|
+try:
|
|
+ from xml.etree import ElementTree as etree
|
|
+except ImportError:
|
|
+ try:
|
|
+ from elementtree import ElementTree as etree
|
|
+ except ImportError:
|
|
+ raise ImportError('Missing an implementation of ElementTree. ' \
|
|
+ 'Please install either Python >= 2.5 or ElementTree.')
|
|
+
|
|
import sys
|
|
import zipfile
|
|
from tempfile import mkstemp
|
|
@@ -27,12 +35,22 @@
|
|
def prepstyle(filename):
|
|
|
|
zin = zipfile.ZipFile(filename)
|
|
- styles = zin.read("styles.xml")
|
|
-
|
|
- root = etree.fromstring(styles)
|
|
- for el in root.xpath("//style:page-layout-properties",
|
|
- namespaces=NAMESPACES):
|
|
- for attr in el.attrib:
|
|
+ styles = zin.open("styles.xml")
|
|
+
|
|
+ root = None
|
|
+ # some extra effort to preserve namespace prefixes
|
|
+ for event, elem in etree.iterparse(styles, events=("start", "start-ns")):
|
|
+ if event == "start-ns":
|
|
+ etree.register_namespace(elem[0], elem[1])
|
|
+ elif event == "start":
|
|
+ if root is None:
|
|
+ root = elem
|
|
+
|
|
+ styles.close()
|
|
+
|
|
+ for el in root.findall(".//style:page-layout-properties",
|
|
+ namespaces=NAMESPACES):
|
|
+ for attr in el.attrib.keys():
|
|
if attr.startswith("{%s}" % NAMESPACES["fo"]):
|
|
del el.attrib[attr]
|
|
|
|
@@ -42,7 +60,7 @@
|
|
|
|
for item in zin.infolist():
|
|
if item.filename == "styles.xml":
|
|
- zout.writestr(item, etree.tostring(root))
|
|
+ zout.writestr(item, etree.tostring(root, encoding="UTF-8"))
|
|
else:
|
|
zout.writestr(item, zin.read(item.filename))
|
|
|
|
@@ -54,8 +72,8 @@
|
|
def main():
|
|
args = sys.argv[1:]
|
|
if len(args) != 1:
|
|
- print >> sys.stderr, __doc__
|
|
- print >> sys.stderr, "Usage: %s STYLE_FILE.odt\n" % sys.argv[0]
|
|
+ sys.stderr.write(__doc__)
|
|
+ sys.stderr.write("\nUsage: %s STYLE_FILE.odt\n" % sys.argv[0])
|
|
sys.exit(1)
|
|
filename = args[0]
|
|
prepstyle(filename)
|