~ubuntu-branches/ubuntu/trusty/python-docutils/trusty-proposed

« back to all changes in this revision

Viewing changes to .pc/rst2odt_prepstyles-elementtree.diff/tools/rst2odt_prepstyles.py

  • Committer: Package Import Robot
  • Author(s): Michael Schutte, Jakub Wilk, Michael Schutte, Dmitry Shachnev
  • Date: 2013-08-05 16:47:43 UTC
  • mfrom: (11.1.9 experimental)
  • Revision ID: package-import@ubuntu.com-20130805164743-00lyz2imgs85ttwz
Tags: 0.11-1
[ Jakub Wilk ]
* Remove martin f. krafft and Ben Finney from Uploaders at their requests.

[ Michael Schutte ]
* New upstream release 0.11, closes: #712284, #714880.
  - Drop patch math-output-html.diff: Fixed upstream.
  - Drop patch fix-buildhtml-progress.diff: Applied upstream.
  - Drop patch strict-csv-parser.diff: Fixed upstream.
  - Drop patch unknown-url-exc-use-repr.diff: Applied upstream.
  - Update patch move-data-to-usr-share.diff: Default stylesheet paths for
    writers/html4css1 have changed.
  - Refresh the remaining patches.
  - New patch no-local-roman.diff: Use the roman module from python-roman
    instead of the copy shipped with docutils.
  - Update information about upstream version control in debian/copyright.
* Change my e-mail host in Uploaders and debian/copyright to @debian.org.
* New patch rst2odt_prepstyles-elementtree.diff: Port the rst2odt_prepstyles
  utility to ElementTree.  Drop Recommends: python-lxml.  Closes: #714319.
* New patch odt-writer-ascii-filenames.diff: Only use ASCII for filenames of
  images embedded in ODT files, closes: #714317.

[ Dmitry Shachnev ]
* Use dh_python2 instead of deprecated dh_pysupport.
* Add XS-Testsuite header, and replace XS-Python-Version with preferred
  X-Python-Version (closes: #685509).
* Add myself to Uploaders.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
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.
 
6
 
 
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
"""
 
11
 
 
12
#
 
13
# Author: Michael Schutte <michi@uiae.at>
 
14
 
 
15
from lxml import etree
 
16
import sys
 
17
import zipfile
 
18
from tempfile import mkstemp
 
19
import shutil
 
20
import os
 
21
 
 
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"
 
25
}
 
26
 
 
27
def prepstyle(filename):
 
28
    
 
29
    zin = zipfile.ZipFile(filename)
 
30
    styles = zin.read("styles.xml")
 
31
    
 
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]
 
38
    
 
39
    tempname = mkstemp()
 
40
    zout = zipfile.ZipFile(os.fdopen(tempname[0], "w"), "w",
 
41
        zipfile.ZIP_DEFLATED)
 
42
    
 
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))
 
48
    
 
49
    zout.close()
 
50
    zin.close()
 
51
    shutil.move(tempname[1], filename)
 
52
 
 
53
 
 
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)
 
62
 
 
63
if __name__ == '__main__':
 
64
    main()
 
65
 
 
66
 
 
67
# vim:tw=78:sw=4:sts=4:et: