Do not unescape text when generating Text nodes.
[docutils.git] / docutils / tools / rst2odt_prepstyles.py
blobd20e0849c75a1f42068e8badc04a5d328ea39467
1 #!/usr/bin/env python
3 # $Id$
4 # Author: Dave Kuhlman <dkuhlman@rexx.com>
5 # Copyright: This module has been placed in the public domain.
7 """
8 Fix a word-processor-generated styles.odt for odtwriter use: Drop page size
9 specifications from styles.xml in STYLE_FILE.odt.
10 """
13 # Author: Michael Schutte <michi@uiae.at>
15 from lxml import etree
16 import sys
17 import zipfile
18 from tempfile import mkstemp
19 import shutil
20 import os
22 NAMESPACES = {
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"]):
37 del el.attrib[attr]
39 tempname = mkstemp()
40 zout = zipfile.ZipFile(os.fdopen(tempname[0], "w"), "w",
41 zipfile.ZIP_DEFLATED)
43 for item in zin.infolist():
44 if item.filename == "styles.xml":
45 zout.writestr(item, etree.tostring(root))
46 else:
47 zout.writestr(item, zin.read(item.filename))
49 zout.close()
50 zin.close()
51 shutil.move(tempname[1], filename)
54 def main():
55 args = sys.argv[1:]
56 if len(args) != 1:
57 print >> sys.stderr, __doc__
58 print >> sys.stderr, "Usage: %s STYLE_FILE.odt\n" % sys.argv[0]
59 sys.exit(1)
60 filename = args[0]
61 prepstyle(filename)
63 if __name__ == '__main__':
64 main()
67 # vim:tw=78:sw=4:sts=4:et: