~ubuntu-branches/ubuntu/saucy/lxml/saucy-updates

« back to all changes in this revision

Viewing changes to doc/mkhtml.py

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2013-02-19 21:47:31 UTC
  • mfrom: (2.1.35 experimental)
  • Revision ID: package-import@ubuntu.com-20130219214731-jbkip7ycyvzlth3m
Tags: 3.1.0-1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
import shutil
9
9
import subprocess
10
10
 
 
11
try:
 
12
    from io import open as open_file
 
13
except ImportError:
 
14
    from codecs import open as open_file
 
15
 
11
16
RST2HTML_OPTIONS = " ".join([
12
17
    '--no-toc-backlinks',
13
18
    '--strip-comments',
135
140
                stylesheet_url, source_path, dest_path))
136
141
    subprocess.call(command, shell=True)
137
142
 
 
143
def convert_changelog(lxml_path, changelog_file_path, rst2html_script, stylesheet_url):
 
144
    f = open_file(os.path.join(lxml_path, 'CHANGES.txt'), 'r', encoding='utf-8')
 
145
    try:
 
146
        content = f.read()
 
147
    finally:
 
148
        f.close()
 
149
 
 
150
    links = dict(LP='`%s <https://bugs.launchpad.net/lxml/+bug/%s>`_',
 
151
                 GH='`%s <https://github.com/lxml/lxml/issues/%s>`_')
 
152
    replace_tracker_links = re.compile('((LP|GH)#([0-9]+))').sub
 
153
    def insert_link(match):
 
154
        text, ref_type, ref_id = match.groups()
 
155
        return links[ref_type] % (text, ref_id)
 
156
    content = replace_tracker_links(insert_link, content)
 
157
 
 
158
    command = [sys.executable, rst2html_script] + RST2HTML_OPTIONS.split() + [
 
159
        '--link-stylesheet', '--stylesheet', stylesheet_url ]
 
160
    out_file = open(changelog_file_path, 'wb')
 
161
    try:
 
162
        rst2html = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=out_file)
 
163
        rst2html.communicate(content.encode('utf8'))
 
164
    finally:
 
165
        out_file.close()
 
166
 
138
167
def publish(dirname, lxml_path, release):
139
168
    if not os.path.exists(dirname):
140
169
        os.mkdir(dirname)
180
209
                build_menu(tree, basename, section_head)
181
210
 
182
211
    # also convert CHANGES.txt
183
 
    rest2html(script,
184
 
              os.path.join(lxml_path, 'CHANGES.txt'),
185
 
              os.path.join(dirname, 'changes-%s.html' % release),
186
 
              '')
 
212
    convert_changelog(lxml_path, os.path.join(dirname, 'changes-%s.html' % release),
 
213
                      script, stylesheet_url)
187
214
 
188
215
    # generate sitemap from menu
189
216
    sitemap = XML('''\