OLD | NEW |
1 #!@PYTHON@ | 1 #!@PYTHON@ |
2 | 2 |
3 """ | 3 """ |
4 Postprocess HTML files: | 4 Postprocess HTML files: |
5 add footer, tweak links, add language selection menu. | 5 add footer, tweak links, add language selection menu. |
6 """ | 6 """ |
| 7 import codecs |
7 import re | 8 import re |
8 import os | 9 import os |
9 import sys | 10 import sys |
10 import time | 11 import time |
11 import operator | 12 import operator |
12 | 13 |
13 import langdefs | 14 import langdefs |
| 15 from functools import reduce |
14 | 16 |
15 # This is to try to make the docball not too big with almost duplicate files | 17 # This is to try to make the docball not too big with almost duplicate files |
16 # see process_links() | 18 # see process_links() |
17 non_copied_pages = ['Documentation/out-www/notation-big-page', | 19 non_copied_pages = ['Documentation/out-www/notation-big-page', |
18 'Documentation/out-www/internals-big-page', | 20 'Documentation/out-www/internals-big-page', |
19 'Documentation/out-www/learning-big-page', | 21 'Documentation/out-www/learning-big-page', |
20 'Documentation/out-www/usage-big-page', | 22 'Documentation/out-www/usage-big-page', |
21 'Documentation/out-www/music-glossary-big-page', | 23 'Documentation/out-www/music-glossary-big-page', |
22 'Documentation/out-www/contributor', | 24 'Documentation/out-www/contributor', |
23 'Documentation/out-www/changes-big-page', | 25 'Documentation/out-www/changes-big-page', |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 else: | 329 else: |
328 mail_address_url= 'mailto:' + mail_address | 330 mail_address_url= 'mailto:' + mail_address |
329 | 331 |
330 versiontup = package_version.split ('.') | 332 versiontup = package_version.split ('.') |
331 branch_str = _doc ('stable-branch') | 333 branch_str = _doc ('stable-branch') |
332 if int (versiontup[1]) % 2: | 334 if int (versiontup[1]) % 2: |
333 branch_str = _doc ('development-branch') | 335 branch_str = _doc ('development-branch') |
334 | 336 |
335 # Initialize dictionaries for string formatting | 337 # Initialize dictionaries for string formatting |
336 subst = {} | 338 subst = {} |
337 subst[''] = dict ([i for i in globals ().items() if type (i[1]) is str]) | 339 subst[''] = dict ([i for i in list(globals ().items()) if type (i[1]) is str
]) |
338 subst[''].update (dict ([i for i in locals ().items() if type (i[1]) is str]
)) | 340 subst[''].update (dict ([i for i in list(locals ().items()) if type (i[1]) i
s str])) |
339 for l in translation: | 341 for l in translation: |
340 e = langdefs.LANGDICT[l].webext | 342 e = langdefs.LANGDICT[l].webext |
341 if e: | 343 if e: |
342 subst[e] = {} | 344 subst[e] = {} |
343 for name in subst['']: | 345 for name in subst['']: |
344 subst[e][name] = translation[l] (subst[''][name]) | 346 subst[e][name] = translation[l] (subst[''][name]) |
345 # Do deeper string formatting as early as possible, | 347 # Do deeper string formatting as early as possible, |
346 # so only one '%' formatting pass is needed later | 348 # so only one '%' formatting pass is needed later |
347 for e in subst: | 349 for e in subst: |
348 subst[e]['footer_name_version'] = subst[e]['footer_name_version'] % subs
t[e] | 350 subst[e]['footer_name_version'] = subst[e]['footer_name_version'] % subs
t[e] |
349 subst[e]['footer_report_links'] = subst[e]['footer_report_links'] % subs
t[e] | 351 subst[e]['footer_report_links'] = subst[e]['footer_report_links'] % subs
t[e] |
350 | 352 |
351 for prefix, ext_list in pages_dict.items (): | 353 for prefix, ext_list in list(pages_dict.items ()): |
352 for lang_ext in ext_list: | 354 for lang_ext in ext_list: |
353 file_name = langdefs.lang_file_name (prefix, lang_ext, '.html') | 355 file_name = langdefs.lang_file_name (prefix, lang_ext, '.html') |
354 source_time = os.path.getmtime(file_name) | 356 source_time = os.path.getmtime(file_name) |
355 dest_time = 0 | 357 dest_time = 0 |
356 if os.path.exists(name_filter(file_name)): | 358 if os.path.exists(name_filter(file_name)): |
357 dest_time = os.path.getmtime(name_filter(file_name)) | 359 dest_time = os.path.getmtime(name_filter(file_name)) |
358 if dest_time < source_time: | 360 if dest_time < source_time: |
359 | 361 |
360 in_f = open (file_name) | 362 s = codecs.open (file_name, 'r', 'utf-8').read () |
361 s = in_f.read() | |
362 in_f.close() | |
363 | |
364 s = s.replace ('%', '%%') | 363 s = s.replace ('%', '%%') |
365 s = hack_urls (s, prefix, target, bool (int (versiontup[1]) % 2
)) | 364 s = hack_urls (s, prefix, target, bool (int (versiontup[1]) % 2
)) |
366 s = add_header (s, prefix) | 365 s = add_header (s, prefix) |
367 | 366 |
368 ### add sidebar information | 367 ### add sidebar information |
369 s = s.replace ('<!-- Sidebar Version Tag -->', sidebar_version) | 368 s = s.replace ('<!-- Sidebar Version Tag -->', sidebar_version) |
370 | 369 |
371 ### add footer | 370 ### add footer |
372 if footer_tag_re.search (s) == None: | 371 if footer_tag_re.search (s) == None: |
373 if 'web' in file_name: | 372 if 'web' in file_name: |
374 s = add_footer (s, footer_tag + web_footer) | 373 s = add_footer (s, footer_tag + web_footer) |
375 else: | 374 else: |
376 s = add_footer (s, footer_tag + footer) | 375 s = add_footer (s, footer_tag + footer) |
377 | 376 |
378 available, missing = find_translations (prefix, lang_ext) | 377 available, missing = find_translations (prefix, lang_ext) |
379 page_flavors = process_links (s, prefix, lang_ext, file_name
, missing, target) | 378 page_flavors = process_links (s, prefix, lang_ext, file_name
, missing, target) |
380 # Add menu after stripping: must not have autoselection for
language menu. | 379 # Add menu after stripping: must not have autoselection for
language menu. |
381 page_flavors = add_menu (page_flavors, prefix, available, ta
rget, translation) | 380 page_flavors = add_menu (page_flavors, prefix, available, ta
rget, translation) |
382 for k in page_flavors: | 381 for k in page_flavors: |
383 page_flavors[k][1] = page_flavors[k][1] % subst[page_flavors
[k][0]] | 382 page_flavors[k][1] = page_flavors[k][1] % subst[page_flavors
[k][0]] |
384 out_f = open (name_filter (k), 'w') | 383 out_f = codecs.open (name_filter (k), 'w', 'utf-8') |
385 out_f.write (page_flavors[k][1]) | 384 out_f.write (page_flavors[k][1]) |
386 out_f.close() | 385 out_f.close() |
387 # if the page is translated, a .en.html symlink is necessary for content
negotiation | 386 # if the page is translated, a .en.html symlink is necessary for content
negotiation |
388 if target == 'online' and ext_list != [''] and not os.path.lexists (name
_filter (prefix + '.en.html')): | 387 if target == 'online' and ext_list != [''] and not os.path.lexists (name
_filter (prefix + '.en.html')): |
389 os.symlink (os.path.basename (prefix) + '.html', name_filter (prefix
+ '.en.html')) | 388 os.symlink (os.path.basename (prefix) + '.html', name_filter (prefix
+ '.en.html')) |
OLD | NEW |