3
# $Id: rst2odt_prepstyles.py 5839 2009-01-07 19:09:28Z dkuhlman $
4
# Author: Dave Kuhlman <dkuhlman@rexx.com>
5
# Copyright: This module has been placed in the public domain.
8
Fix a word-processor-generated styles.odt for odtwriter use: Drop page size
9
specifications from styles.xml in STYLE_FILE.odt.
13
# Author: Michael Schutte <michi@uiae.at>
15
from lxml import etree
18
from tempfile import mkstemp
23
"style": "urn:oasis:names:tc:opendocument:xmlns:style:1.0",
24
"fo": "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
27
def prepstyle(filename):
29
zin = zipfile.ZipFile(filename)
30
styles = zin.read("styles.xml")
32
root = etree.fromstring(styles)
33
for el in root.xpath("//style:page-layout-properties",
34
namespaces=NAMESPACES):
35
for attr in el.attrib:
36
if attr.startswith("{%s}" % NAMESPACES["fo"]):
40
zout = zipfile.ZipFile(os.fdopen(tempname[0], "w"), "w",
43
for item in zin.infolist():
44
if item.filename == "styles.xml":
45
zout.writestr(item, etree.tostring(root))
47
zout.writestr(item, zin.read(item.filename))
51
shutil.move(tempname[1], filename)
57
print >> sys.stderr, __doc__
58
print >> sys.stderr, "Usage: %s STYLE_FILE.odt\n" % sys.argv[0]
63
if __name__ == '__main__':
67
# vim:tw=78:sw=4:sts=4:et: