Skip to content

Commit 194aea5

Browse files
committed
Merge remote-tracking branch 'upstream/master'
* upstream/master: Preprocess: Switch from XSLT to python for Qt help project generation Makefile: Make build more silent. .gitignore: Ignore release folder Preprocess: Match FTP external links Preprocess: Avoid unnecessary string creation Makefile: Use xz archive format when building on Linux
2 parents b7739dc + 600d384 commit 194aea5

File tree

5 files changed

+156
-97
lines changed

5 files changed

+156
-97
lines changed

Makefile

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ DISTFILES= \
4242
skins/ \
4343
build_link_map.py \
4444
ddg_parse_html.py \
45-
devhelp2qch.xsl \
45+
devhelp2qch.py \
4646
fix_devhelp-links.py \
4747
index2autolinker.py \
4848
index2browser.py \
@@ -68,6 +68,14 @@ DISTFILES= \
6868
CLEANFILES= \
6969
output
7070

71+
TAR_FORMAT := gz
72+
TAR_OPTION := z
73+
UNAME_S := $(shell uname -s)
74+
ifeq ($(UNAME_S),Linux)
75+
TAR_FORMAT := xz
76+
TAR_OPTION := J
77+
endif
78+
7179
clean:
7280
rm -rf $(CLEANFILES)
7381

@@ -76,7 +84,7 @@ check:
7684
dist: clean
7785
mkdir -p "cppreference-doc-$(VERSION)"
7886
cp -r $(DISTFILES) "cppreference-doc-$(VERSION)"
79-
tar czf "cppreference-doc-$(VERSION).tar.gz" "cppreference-doc-$(VERSION)"
87+
tar c$(TAR_OPTION)f "cppreference-doc-$(VERSION).tar.$(TAR_FORMAT)" "cppreference-doc-$(VERSION)"
8088
rm -rf "cppreference-doc-$(VERSION)"
8189

8290
install: all
@@ -110,21 +118,21 @@ release: all
110118
# zip the distributable
111119
mkdir -p "cppreference-doc-$(VERSION)"
112120
cp -r $(DISTFILES) "cppreference-doc-$(VERSION)"
113-
tar cJf "release/cppreference-doc-$(VERSION).tar.xz" "cppreference-doc-$(VERSION)"
121+
tar c$(TAR_OPTION)f "release/cppreference-doc-$(VERSION).tar.$(TAR_FORMAT)" "cppreference-doc-$(VERSION)"
114122
zip -qr "release/cppreference-doc-$(VERSION).zip" "cppreference-doc-$(VERSION)"
115123
rm -rf "cppreference-doc-$(VERSION)"
116124

117125
# zip the html output
118126
pushd "output"; \
119-
tar cJf "../release/html-book-$(VERSION).tar.xz" "reference" \
127+
tar c$(TAR_OPTION)f "../release/html-book-$(VERSION).tar.$(TAR_FORMAT)" "reference" \
120128
"cppreference-doxygen-local.tag.xml" ; \
121129
zip -qr "../release/html-book-$(VERSION).zip" "reference" \
122130
"cppreference-doxygen-local.tag.xml" ; \
123131
popd
124132

125133
# zip qch
126134
pushd "output"; \
127-
tar czf "../release/qch-book-$(VERSION).tar.gz" "cppreference-doc-en-cpp.qch"; \
135+
tar c$(TAR_OPTION)f "../release/qch-book-$(VERSION).tar.$(TAR_FORMAT)" "cppreference-doc-en-cpp.qch"; \
128136
zip -qr "../release/qch-book-$(VERSION).zip" "cppreference-doc-en-cpp.qch"; \
129137
popd
130138

@@ -183,8 +191,9 @@ output/qch-help-project-cpp.xml: output/cppreference-doc-en-cpp.devhelp2
183191
echo "</files>" >> "output/qch-files.xml"
184192

185193
#create the project (copies the file list)
186-
xsltproc devhelp2qch.xsl "output/cppreference-doc-en-cpp.devhelp2" > \
187-
"output/qch-help-project-cpp.xml"
194+
./devhelp2qch.py --src=output/cppreference-doc-en-cpp.devhelp2 \
195+
--dst=output/qch-help-project-cpp.xml \
196+
--virtual_folder=cpp --file_list=output/qch-files.xml
188197

189198
# build doxygen tag file
190199
output/cppreference-doxygen-local.tag.xml: \

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ to <http://en.cppreference.com/w/Cppreference:Archives>.
4141
Dependencies
4242
------------
4343

44-
The package depends on 'wget' (>=1.15), 'python3', 'python3-lxml', 'xsltproc'
44+
The package depends on 'wget' (>=1.15), 'python3', 'python3-lxml',
4545
and 'qhelpgenerator' for the generation of the documentation.
4646

4747
See also

devhelp2qch.py

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#!/usr/bin/env python3
2+
3+
# Copyright (C) 2017 Giedrius Zitkus <elink@namusauga.lt>
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+
# devhelp2qch.py script converts 'in_root' xml source file to 'out_root' xml output
21+
# including files list from library 'files_root' at the end.
22+
23+
from lxml import etree
24+
from copy import deepcopy
25+
import sys
26+
import argparse
27+
28+
def convert_toc_lines(source_line, in_section):
29+
i = 0
30+
for el_sub in source_line.getchildren():
31+
el_section_1 = etree.XML('<section/>')
32+
el_section_1.set('title', el_sub.get('name'))
33+
el_section_1.set('ref', el_sub.get('link'))
34+
35+
if el_sub.getchildren() != []:
36+
in_section.append(convert_toc_lines(el_sub, el_section_1))
37+
else:
38+
in_section.append(el_section_1)
39+
40+
return in_section
41+
42+
def convert_toc(in_root_t):
43+
el_toc = etree.XML('<toc/>')
44+
el_section = etree.XML('<section/>')
45+
el_section.set('title', in_root_t.get('title'))
46+
el_section.set('ref', in_root_t.get('link'))
47+
el_toc.append(convert_toc_lines(in_root_t[1], el_section))
48+
return el_toc
49+
50+
def convert_keywords(in_root_k):
51+
el_keywords = etree.XML('<keywords/>')
52+
for el_function in in_root_k[2]:
53+
el_keyword = etree.XML('<keyword/>')
54+
el_keyword.set('name', el_function.get('name'))
55+
el_keyword.set('id', el_function.get('name'))
56+
el_keyword.set('ref', el_function.get('link'))
57+
58+
el_keywords.append(el_keyword)
59+
if el_function.get('name').startswith('std::'):
60+
el_keyword = etree.XML('<keyword/>')
61+
el_keyword.set('name', el_function.get('name'))
62+
63+
# Add an additional id for libc++ users
64+
name_without_std = el_function.get('name')[5:]
65+
66+
el_keyword.set('id', 'std::__LIBCPP_ABI_VERSION::' + name_without_std)
67+
el_keyword.set('ref', el_function.get('link'))
68+
69+
el_keywords.append(el_keyword)
70+
71+
el_keyword = etree.XML('<keyword/>')
72+
el_keyword.set('name', el_function.get('name'))
73+
el_keyword.set('id', 'std::__1::' + name_without_std)
74+
el_keyword.set('ref', el_function.get('link'))
75+
76+
el_keywords.append(el_keyword)
77+
return el_keywords
78+
79+
# Adds files list from external library
80+
def add_files_list(files_root_f):
81+
el_files = etree.XML('<files/>')
82+
for file_item in files_root_f:
83+
el_file = etree.XML('<file/>')
84+
el_file.text = file_item.text
85+
el_files.append(el_file)
86+
return el_files
87+
88+
def convert_devhelp_to_qch(in_root, files_root, out_root, virtual_folder):
89+
el = etree.XML('<namespace/>')
90+
el.text = 'cppreference.com.' + in_root.get('name')
91+
out_root.append(el)
92+
93+
el = etree.XML('<virtualFolder/>')
94+
el.text = virtual_folder
95+
out_root.append(el)
96+
97+
el = etree.XML('<customFilter/>')
98+
el.set('name', in_root.get('title'))
99+
el_filter = etree.XML('<filterAttribute/>')
100+
el_filter.text = in_root.get('name')
101+
el.append(el_filter)
102+
out_root.append(el)
103+
104+
el = etree.XML('<filterSection/>')
105+
el_filter = etree.XML('<filterAttribute/>')
106+
el_filter.text = in_root.get('name')
107+
el.append(el_filter)
108+
el.append(convert_toc(in_root))
109+
el.append(convert_keywords(in_root))
110+
el.append(add_files_list(files_root))
111+
out_root.append(el)
112+
113+
def main():
114+
parser = argparse.ArgumentParser(prog='devhelp2qch.py')
115+
parser.add_argument('--src', type=str, help='The path to the XML input file')
116+
parser.add_argument('--dst', type=str, help='The path to the destination XML file')
117+
parser.add_argument('--virtual_folder', type=str, help='Virtual folder name')
118+
parser.add_argument('--file_list', type=str, help='The path to the file list in XML file')
119+
args = parser.parse_args()
120+
121+
src_path = args.src
122+
dst_path = args.dst
123+
v_folder = args.virtual_folder
124+
file_path = args.file_list
125+
126+
parser = etree.XMLParser(encoding='UTF-8', recover=True)
127+
in_tree = etree.parse(src_path, parser)
128+
file_tree = etree.parse(file_path, parser)
129+
out_el = etree.XML('<QtHelpProject xmlns:devhelp="http://www.devhelp.net/book" xmlns:str="http://exslt.org/strings" version="1.0"/>')
130+
131+
convert_devhelp_to_qch(in_tree.getroot(), file_tree.getroot(), out_el, v_folder)
132+
133+
out_f = open(dst_path, 'wb')
134+
out_f.write(etree.tostring(out_el, encoding="utf-8", pretty_print=True, xml_declaration=True))
135+
out_f.close()
136+
137+
if __name__ == "__main__":
138+
main()

devhelp2qch.xsl

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

preprocess.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def preprocess_html_file(root, fn, rename_map):
244244
for err in parser.error_log:
245245
print("HTML WARN: {0}".format(err))
246246

247-
html.write(fn, encoding='UTF-8', method='html')
247+
html.write(fn, encoding='utf-8', method='html')
248248

249249
def preprocess_css_file(fn):
250250
f = open(fn, "r", encoding='utf-8')

0 commit comments

Comments
 (0)