Skip to content

Commit c37622b

Browse files
author
p12
committed
Transform: rewrite devhelp index file transformation in python+lxml
1 parent 8f22a84 commit c37622b

3 files changed

Lines changed: 64 additions & 51 deletions

File tree

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ DISTFILES= \
3737
images/ \
3838
build_link_map.py \
3939
devhelp2qch.xsl \
40-
fix_devhelp-links.xsl \
40+
fix_devhelp-links.py \
4141
httrack-workarounds.py \
4242
index2browser.py \
4343
index2devhelp.py \
@@ -113,13 +113,13 @@ cppreference-doc-en-c.devhelp2: output link-map.xml
113113
./index2devhelp.py $(docdir)/html index-chapters-c.xml \
114114
"C Standard Library reference" "cppreference-doc-en-c" "c" \
115115
index-functions-c.xml devhelp-index-c.xml
116-
xsltproc fix_devhelp-links.xsl devhelp-index-c.xml > cppreference-doc-en-c.devhelp2
116+
./fix_devhelp-links.py devhelp-index-c.xml cppreference-doc-en-c.devhelp2
117117

118118
cppreference-doc-en-cpp.devhelp2: output link-map.xml
119119
./index2devhelp.py $(docdir)/html index-chapters-cpp.xml \
120120
"C++ Standard Library reference" "cppreference-doc-en-cpp" "cpp" \
121121
index-functions-cpp.xml devhelp-index-cpp.xml
122-
xsltproc fix_devhelp-links.xsl devhelp-index-cpp.xml > cppreference-doc-en-cpp.devhelp2
122+
./fix_devhelp-links.py devhelp-index-cpp.xml cppreference-doc-en-cpp.devhelp2
123123

124124
#build the .qch (QT help) file
125125
cppreference-doc-en-cpp.qch: qch-help-project-cpp.xml

fix_devhelp-links.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env python
2+
'''
3+
Copyright (C) 2012-2013 p12 <tir5c3@yahoo.co.uk>
4+
5+
This file is part of cppreference-doc
6+
7+
This program is free software: you can redistribute it and/or modify
8+
it under the terms of the GNU General Public License as published by
9+
the Free Software Foundation, either version 3 of the License, or
10+
(at your option) any later version.
11+
12+
This program is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
GNU General Public License for more details.
16+
17+
You should have received a copy of the GNU General Public License
18+
along with this program. If not, see http://www.gnu.org/licenses/.
19+
'''
20+
21+
import lxml.etree as e
22+
import sys
23+
24+
if len(sys.argv) != 3:
25+
print '''Please provide the following 2 argument:
26+
* the file name of the source file
27+
* the file name of the destination file
28+
'''
29+
30+
in_fn = sys.argv[1]
31+
out_fn = sys.argv[2]
32+
33+
map_file = open('link-map.xml', 'r')
34+
root = e.XML(map_file.read())
35+
el_files = root.xpath('/files/*')
36+
37+
mapping = dict()
38+
39+
for el_file in el_files:
40+
fn_from = el_file.get('from')
41+
fn_to = el_file.get('to')
42+
mapping[fn_from] = fn_to
43+
44+
in_f = open(in_fn, 'r')
45+
root = e.XML(in_f.read())
46+
in_f.close()
47+
48+
el_mod = root.xpath('//*[@link]')
49+
for el in el_mod:
50+
link = el.get('link')
51+
try:
52+
link = mapping[link]
53+
except:
54+
print 'Could not find ' + link + ' in mapping'
55+
link = '404'
56+
el.set('link', link)
57+
58+
out_f = open(out_fn, 'w')
59+
out_f.write(e.tostring(root, pretty_print=True))
60+
out_f.close()
61+

fix_devhelp-links.xsl

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)