/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to tools/rst2prettyhtml.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-21 12:41:27 UTC
  • mto: This revision was merged to the branch mainline in revision 6623.
  • Revision ID: jelmer@jelmer.uk-20170521124127-iv8etg0vwymyai6y
s/bzr/brz/ in apport config.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python3
 
1
#!/usr/bin/env python
2
2
 
3
3
import errno
4
4
import os
5
 
from io import StringIO
 
5
from StringIO import StringIO
6
6
import sys
7
7
 
8
8
try:
9
9
    from docutils.core import publish_file
10
10
    from docutils.parsers import rst
11
11
except ImportError:
12
 
    print("Missing dependency.  Please install docutils.")
 
12
    print "Missing dependency.  Please install docutils."
13
13
    sys.exit(1)
14
14
try:
15
15
    from elementtree.ElementTree import XML
16
16
    from elementtree import HTMLTreeBuilder
17
17
except ImportError:
18
 
    print("Missing dependency.  Please install ElementTree.")
 
18
    print "Missing dependency.  Please install ElementTree."
19
19
    sys.exit(1)
20
20
try:
21
21
    import kid
22
22
except ImportError:
23
 
    print("Missing dependency.  Please install Kid.")
 
23
    print "Missing dependency.  Please install Kid."
24
24
    sys.exit(1)
25
25
 
26
26
 
29
29
    # prevent docutils from autoclosing the StringIO
30
30
    xhtml_file.close = lambda: None
31
31
    xhtml = publish_file(rest_file, writer_name='html', destination=xhtml_file,
32
 
                         settings_overrides={"doctitle_xform": 0})
 
32
                         settings_overrides={"doctitle_xform": 0} 
 
33
    
 
34
    )
33
35
    xhtml_file.seek(0)
34
36
    xml = HTMLTreeBuilder.parse(xhtml_file)
35
37
    head = xml.find('head')
36
38
    body = xml.find('body')
37
39
    assert head is not None
38
40
    assert body is not None
39
 
    template = kid.Template(file=template_name, head=head, body=body)
 
41
    template=kid.Template(file=template_name, 
 
42
                          head=head, body=body)
40
43
    return (template.serialize(output="html"))
41
44
 
42
45
 
43
46
def safe_open(filename, mode):
44
47
    try:
45
48
        return open(filename, mode + 'b')
46
 
    except IOError as e:
 
49
    except IOError, e:
47
50
        if e.errno != errno.ENOENT:
48
51
            raise
49
52
        sys.stderr.write('file not found: %s\n' % sys.argv[2])