1
- From 89d9ddfb25ecd6b0f974ac65dc0ef01a6c42e29e Mon Sep 17 00:00:00 2001
1
+ From 59e3c1e8105477b5b6c78ef0579a3f809ef89949 Mon Sep 17 00:00:00 2001
2
2
From: myfreeer <
[email protected] >
3
- Date: Sun, 30 Dec 2018 17:35:34 +0800
3
+ Date: Fri, 5 Apr 2019 07:50:59 +0800
4
4
Subject: [PATCH] source: use zh localized version
5
5
6
6
---
7
7
Makefile | 54 ++++++++++++------------
8
- commands/preprocess.py | 19 +++++----
9
- commands/preprocess_cssless.py | 5 + +-
10
- gadgets/standard_revisions-tests /base.py | 2 +-
8
+ commands/preprocess.py | 21 +++++----
9
+ commands/preprocess_cssless.py | 4 +-
10
+ gadgets/standard_revisions_tests /base.py | 2 +-
11
11
gadgets/sync_tests_mwiki.py | 2 +-
12
12
index2ddg.py | 4 +-
13
13
index_transform/browser.py | 2 +-
14
14
preprocess.py | 8 ++--
15
- tests/test_preprocess.py | 19 ++++++-- -
15
+ tests/test_preprocess.py | 2 + -
16
16
tests/test_preprocess_cssless.py | 2 +-
17
- 10 files changed, 64 insertions(+), 53 deletions(-)
17
+ 10 files changed, 52 insertions(+), 49 deletions(-)
18
18
19
19
diff --git a/Makefile b/Makefile
20
- index 2366fbc..423be32 100644
20
+ index e54b72d..84d98a5 100644
21
21
--- a/Makefile
22
22
+++ b/Makefile
23
23
@@ -100,18 +100,18 @@ install: all
@@ -94,14 +94,14 @@ index 2366fbc..423be32 100644
94
94
- output/cppreference-doc-en-cpp.qch: output/qch-help-project-cpp.xml
95
95
+ output/cppreference-doc-zh-cpp.qch: output/qch-help-project-cpp.xml
96
96
#qhelpgenerator only works if the project file is in the same directory as the documentation
97
- cp "output/qch-help-project-cpp.xml" "output/reference_cssless/qch.xml "
97
+ cp "output/qch-help-project-cpp.xml" "output/reference_cssless/qch.qhp "
98
98
99
99
pushd "output/reference_cssless" > /dev/null; \
100
- - $(qhelpgenerator) "qch.xml " -o "../cppreference-doc-en-cpp.qch"; \
101
- + $(qhelpgenerator) "qch.xml " -o "../cppreference-doc-zh-cpp.qch"; \
100
+ - $(qhelpgenerator) "qch.qhp " -o "../cppreference-doc-en-cpp.qch"; \
101
+ + $(qhelpgenerator) "qch.qhp " -o "../cppreference-doc-zh-cpp.qch"; \
102
102
popd > /dev/null
103
103
104
- rm -f "output/reference_cssless/qch.xml "
104
+ rm -f "output/reference_cssless/qch.qhp "
105
105
106
106
- output/qch-help-project-cpp.xml: output/cppreference-doc-en-cpp.devhelp2 output/reference_cssless
107
107
+ output/qch-help-project-cpp.xml: output/cppreference-doc-zh-cpp.devhelp2 output/reference_cssless
@@ -149,10 +149,10 @@ index 2366fbc..423be32 100644
149
149
- ./export.py --url=http://en.cppreference.com/mwiki reference/cppreference-export-ns0,4,8,10.xml 0 4 8 10
150
150
+ ./export.py --url=https://zh.cppreference.com/mwiki reference/cppreference-export-ns0,4,8,10.xml 0 4 8 10
151
151
diff --git a/commands/preprocess.py b/commands/preprocess.py
152
- index 7a0cd5c..16dc1b2 100644
152
+ index 2f8ff4c..43a527a 100644
153
153
--- a/commands/preprocess.py
154
154
+++ b/commands/preprocess.py
155
- @@ -41,15 +41,15 @@ def rearrange_archive(root):
155
+ @@ -42,23 +42,23 @@ def rearrange_archive(root):
156
156
# rearrange the archive. {root} here is output/reference
157
157
158
158
# before
@@ -172,16 +172,17 @@ index 7a0cd5c..16dc1b2 100644
172
172
# ... (other languages)
173
173
174
174
data_path = os.path.join(root, 'common')
175
- @@ -57,7 +57,7 @@ def rearrange_archive(root):
175
+ rmtree_if_exists(data_path)
176
176
shutil.move(os.path.join(root, 'upload.cppreference.com/mwiki'), data_path)
177
- shutil.rmtree(os.path.join(root, 'upload.cppreference.com'))
177
+ - shutil.rmtree(os.path.join(root, 'upload.cppreference.com'))
178
+ + shutil.rmtree(os.path.join(root, 'upload.cppreference.com'), ignore_errors=True)
178
179
179
180
- for lang in ["en"]:
180
181
+ for lang in ["zh"]:
181
182
path = os.path.join(root, lang + ".cppreference.com/")
182
183
src_html_path = path + "w/"
183
184
src_data_path = path + "mwiki/"
184
- @@ -78 ,7 +78 ,7 @@ def rearrange_archive(root):
185
+ @@ -81 ,7 +81 ,7 @@ def rearrange_archive(root):
185
186
shutil.copy(os.path.join(path, 'favicon.ico'), data_path)
186
187
187
188
# remove what's left
@@ -190,7 +191,7 @@ index 7a0cd5c..16dc1b2 100644
190
191
191
192
# remove the XML source file
192
193
for fn in fnmatch.filter(os.listdir(root), 'cppreference-export*.xml'):
193
- @@ -309 ,7 +309 ,10 @@ def remove_fileinfo(html):
194
+ @@ -341 ,7 +341 ,10 @@ def remove_fileinfo(html):
194
195
195
196
# make custom footer
196
197
def add_footer(html, root, fn):
@@ -202,8 +203,8 @@ index 7a0cd5c..16dc1b2 100644
202
203
for child in footer.getchildren():
203
204
id = child.get('id')
204
205
if id == 'cpp-navigation':
205
- @@ -340 ,7 +343 ,7 @@ def remove_unused_external(html):
206
- el.set('href', os.path.join(head, 'common', tail))
206
+ @@ -377 ,7 +380 ,7 @@ def remove_unused_external(html):
207
+
207
208
208
209
def preprocess_html_file(root, fn, rename_map):
209
210
- parser = etree.HTMLParser()
@@ -212,14 +213,11 @@ index 7a0cd5c..16dc1b2 100644
212
213
output = io.StringIO()
213
214
214
215
diff --git a/commands/preprocess_cssless.py b/commands/preprocess_cssless.py
215
- index 2f75d5a..0aa10db 100644
216
+ index 8bf9142..2df1774 100644
216
217
--- a/commands/preprocess_cssless.py
217
218
+++ b/commands/preprocess_cssless.py
218
- @@ -27,11 +27,12 @@ import io
219
- import logging
220
- import os
221
- import warnings
222
- + import codecs
219
+ @@ -28,9 +28,9 @@ from lxml.etree import strip_elements
220
+
223
221
224
222
def preprocess_html_merge_cssless(src_path, dst_path):
225
223
- with open(src_path, 'r') as a_file:
@@ -230,11 +228,11 @@ index 2f75d5a..0aa10db 100644
230
228
stripped = content.strip()
231
229
root = etree.fromstring(stripped, parser)
232
230
233
- diff --git a/gadgets/standard_revisions-tests /base.py b/gadgets/standard_revisions-tests /base.py
234
- index 848d431..91a0a99 100644
235
- --- a/gadgets/standard_revisions-tests /base.py
236
- +++ b/gadgets/standard_revisions-tests /base.py
237
- @@ -27 ,7 +27 ,7 @@ import unittest, time, re
231
+ diff --git a/gadgets/standard_revisions_tests /base.py b/gadgets/standard_revisions_tests /base.py
232
+ index b780e8d..67266e1 100644
233
+ --- a/gadgets/standard_revisions_tests /base.py
234
+ +++ b/gadgets/standard_revisions_tests /base.py
235
+ @@ -24 ,7 +24 ,7 @@ from selenium.webdriver.support.ui import Select
238
236
239
237
class Driver:
240
238
def __init__(self):
@@ -257,46 +255,46 @@ index 9aa3fc7..13294ec 100755
257
255
pywikibot.config2.step = 100
258
256
pywikibot.config2.put_throttle = 0
259
257
diff --git a/index2ddg.py b/index2ddg.py
260
- index 9789e56..32a8707 100755
258
+ index 0cfa557..36bcb45 100755
261
259
--- a/index2ddg.py
262
260
+++ b/index2ddg.py
263
- @@ -447 ,7 +447 ,7 @@ def process_identifier(out, redirects, root, link, item_ident, item_type,
264
- abstract = abstract.replace('\n','\\n')
261
+ @@ -465 ,7 +465 ,7 @@ def process_identifier(out, redirects, root, link, item_ident, item_type,
262
+ abstract = abstract.replace('\n', '\\n')
265
263
line += abstract + '\t'
266
264
# source url
267
265
- line += 'http://en.cppreference.com/w/' + link + '\n'
268
266
+ line += 'https://zh.cppreference.com/w/' + link + '\n'
269
267
out.write(line)
270
268
271
269
build_redirects(redirects, item_ident, item_type)
272
- @@ -540,7 +540,7 @@ def main():
273
- #print(str(i) + '/' + str(len(proc_ins)) + ': ' + link)
274
- #i+=1
270
+ @@ -580,7 +580,7 @@ def main():
271
+ # i+=1
275
272
276
- - root = e.parse(os.path.join(args.reference, fn), parser=html.HTMLParser())
277
- + root = e.parse(os.path.join(args.reference, fn), parser=html.HTMLParser(encoding="utf-8"))
273
+ root = e.parse(os.path.join(args.reference, fn),
274
+ - parser=html.HTMLParser())
275
+ + parser=html.HTMLParser(encoding="utf-8"))
278
276
279
277
for ident in idents:
280
278
281
279
diff --git a/index_transform/browser.py b/index_transform/browser.py
282
- index d2e625c..11375f2 100644
280
+ index fb8b976..e9657a4 100644
283
281
--- a/index_transform/browser.py
284
282
+++ b/index_transform/browser.py
285
- @@ -42,7 +42,7 @@ class Index2Browser(IndexTransform):
286
-
283
+ @@ -48,7 +48,7 @@ class Index2Browser(IndexTransform):
287
284
res = u''
288
- res += '<tt><b>' + xml_escape(full_name) + '</b></tt> [<span class="link">'
289
- - res += '<a href="http://en.cppreference.com/w/' + xml_escape(full_link) + '">'
290
- + res += '<a href="https://zh.cppreference.com/w/' + xml_escape(full_link) + '">'
291
- res += full_link + '</a></span>] <span class="mark">' + mark + '</span>\n'
292
- return res
293
-
285
+ res += '<tt><b>{0}</b></tt> [<span class="link">'.format(
286
+ xml_escape(full_name))
287
+ - res += '<a href="http://en.cppreference.com/w/{0}">'.format(
288
+ + res += '<a href="https://zh.cppreference.com/w/{0}">'.format(
289
+ xml_escape(full_link))
290
+ res += '{0}</a></span>] <span class="mark">{1}</span>\n'.format(
291
+ full_link, mark)
294
292
diff --git a/preprocess.py b/preprocess.py
295
- index 1a3b5c6..288fe0c 100755
293
+ index a04abd2..95823b6 100755
296
294
--- a/preprocess.py
297
295
+++ b/preprocess.py
298
- @@ -29 ,12 +29 ,12 @@ def main():
299
- parser.add_argument('--dst', type=str, help='Destination folder to put preprocessed archive to')
296
+ @@ -35 ,12 +35 ,12 @@ def main():
297
+ help='Destination folder to put preprocessed archive to')
300
298
args = parser.parse_args()
301
299
302
300
- root = args.dst
@@ -313,57 +311,25 @@ index 1a3b5c6..288fe0c 100755
313
311
preprocess.rearrange_archive(root)
314
312
315
313
diff --git a/tests/test_preprocess.py b/tests/test_preprocess.py
316
- index d4616aa..ef4de50 100644
314
+ index 5233199..38ec845 100644
317
315
--- a/tests/test_preprocess.py
318
316
+++ b/tests/test_preprocess.py
319
- @@ -40,19 +40,26 @@ def nostdout():
320
-
321
- class TestConvertLoaderName(unittest.TestCase):
322
- def test_convert_loader_name(self):
323
- - url = 'http://en.cppreference.com/mwiki/load.php?debug=false&lang=en&modules=site&only=scripts&skin=cppreference2&*'
324
- + url = 'https://zh.cppreference.com/mwiki/load.php?debug=false&lang=*&\
325
- + modules=site&only=scripts&skin=cppreference2&*'
326
- self.assertEqual('site_scripts.js', convert_loader_name(url))
327
-
328
- - url = 'http://en.cppreference.com/mwiki/load.php?debug=false&lang=en&modules=site&only=styles&skin=cppreference2&*'
329
- + url = 'https://zh.cppreference.com/mwiki/load.php?debug=false&lang=*&\
330
- + modules=site&only=styles&skin=cppreference2&*'
331
- self.assertEqual('site_modules.css', convert_loader_name(url))
332
-
333
- - url = 'http://en.cppreference.com/mwiki/load.php?debug=false&lang=en&modules=skins.cppreference2&only=scripts&skin=cppreference2&*'
334
- + url = 'https://zh.cppreference.com/mwiki/load.php?debug=false&lang=*&\
335
- + modules=skins.cppreference2&only=scripts&skin=cppreference2&*'
336
- self.assertEqual('skin_scripts.js', convert_loader_name(url))
337
-
338
- - url = 'http://en.cppreference.com/mwiki/load.php?debug=false&lang=en&modules=startup&only=scripts&skin=cppreference2&*'
339
- + url = 'https://zh.cppreference.com/mwiki/load.php?debug=false&lang=*&\
340
- + modules=startup&only=scripts&skin=cppreference2&*'
341
- self.assertEqual('startup_scripts.js', convert_loader_name(url))
342
-
343
- - url = 'http://en.cppreference.com/mwiki/load.php?debug=false&lang=en&modules=ext.gadget.ColiruCompiler%2CMathJax%7Cext.rtlcite%7Cmediawiki.legacy.commonPrint%2Cshared%7Cskins.cppreference2&only=styles&skin=cppreference2&*'
344
- + url = 'https://zh.cppreference.com/mwiki/load.php?debug=false&lang=*&\
345
- + modules=ext.gadget.ColiruCompiler%2CMathJax%7Cext.rtlcite%7Cmediawiki.\
346
- + legacy.commonPrint%2Cshared%7Cskins.cppreference2&only=styles&skin=\
347
- + cppreference2&*'
348
- self.assertEqual('ext.css', convert_loader_name(url))
349
-
350
- with self.assertRaises(Exception):
351
- @@ -227,7 +234,7 @@ class TestPreprocessHtml(unittest.TestCase):
352
- def setUp(self):
353
- self.testdata = os.path.join(os.path.dirname(__file__), 'preprocess_data')
317
+ @@ -256,7 +256,7 @@ class TestPreprocessHtml(unittest.TestCase):
318
+ self.testdata = os.path.join(os.path.dirname(__file__),
319
+ 'preprocess_data')
354
320
infile = os.path.join(self.testdata, "fabs.html")
355
321
- self.parser = etree.HTMLParser()
356
322
+ self.parser = etree.HTMLParser(encoding="utf-8")
357
323
self.html = etree.parse(infile, self.parser)
358
324
359
- # Check whether the HTML matches the contents of the specified test data file
325
+ # Check whether the HTML matches the contents of the specified test data
360
326
diff --git a/tests/test_preprocess_cssless.py b/tests/test_preprocess_cssless.py
361
- index fc93019..ffad345 100644
327
+ index 0b9f580..ab6dddb 100644
362
328
--- a/tests/test_preprocess_cssless.py
363
329
+++ b/tests/test_preprocess_cssless.py
364
- @@ -63 ,7 +63 ,7 @@ class HTMLTestBase(unittest.TestCase):
365
- input = '<html><body>{0}</body></html>'.format(input)
366
- expected_output = '<html><body>{0}</body></html>'.format(expected_output)
330
+ @@ -81 ,7 +81 ,7 @@ class HTMLTestBase(unittest.TestCase):
331
+ expected_output = \
332
+ '<html><body>{0}</body></html>'.format(expected_output)
367
333
368
334
- parser = etree.HTMLParser()
369
335
+ parser = etree.HTMLParser(encoding="utf-8")
0 commit comments