X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=buildscripts%2Fadd_html_footer.py;h=2abb0bf88de0f3271e4cb6bb9441d0d7bfa40315;hb=f96e38fbbbfba9cf4729323beb518a65ae77d562;hp=2935d456cfcb1141a8b02f18fca4e814037927f9;hpb=af770f3440264c18ce01525dce1aa76b86ace0d5;p=lilypond.git
diff --git a/buildscripts/add_html_footer.py b/buildscripts/add_html_footer.py
index 2935d456cf..2abb0bf88d 100644
--- a/buildscripts/add_html_footer.py
+++ b/buildscripts/add_html_footer.py
@@ -6,48 +6,75 @@ Print a nice footer.
import re
import os
import time
+import operator
import langdefs
-default_header = r"""
+# This is to try to make the docball not too big with almost duplicate files
+# see process_links()
+non_copied_pages = ['Documentation/user/out-www/lilypond-big-page',
+ 'Documentation/user/out-www/lilypond-internals-big-page',
+ 'Documentation/user/out-www/music-glossary-big-page',
+ 'out-www/examples',
+ 'Documentation/topdocs',
+ 'Documentation/bibliography',
+ 'Documentation/out-www/THANKS',
+ 'Documentation/out-www/DEDICATION',
+ 'input/']
+
+def _doc (s):
+ return s
+
+header = r"""
"""
-default_footer = r'''
+footer = '''
-This page is for %(package_name)s-%(package_version)s (%(branch_str)s).
+%(footer_name_version)s
+
+
+%(footer_report_errors)s
+
+%(footer_suggest_docs)s
-
-Report errors to %(mail_address)s.
'''
+footer_name_version = _doc ('This page is for %(package_name)s-%(package_version)s (%(branch_str)s).')
+footer_report_errors = _doc ('Report errors to %(mail_address)s.')
+# ugh, must not have "_doc" in strings because it is naively replaced with "_" in hacked gettext process
+footer_suggest_docs = _doc ('Your suggestions for the documentation are welcome.')
+
+mail_address = 'http://post.gmane.org/post.php?group=gmane.comp.gnu.lilypond.bugs'
+suggest_Docs_url = 'http://lilypond.org/web/devel/participating/documentation-adding'
header_tag = ''
-footer_tag = ''
+header_tag_re = re.compile (header_tag)
-def _ (s):
- return s
+footer_tag = ''
+footer_tag_re = re.compile (footer_tag)
-language_available = _ ("Other languages: %s.") % "%(language_menu)s"
-browser_language = _ ("Using automatic language selection.") \
- % "/web/about/browser-language"
+lang_available = _doc ("Other languages: %s.")
+browser_lang = _doc ('About automatic language selection.')
+browser_language_url = "/web/about/browser-language"
-LANGUAGES_TEMPLATE = '''\
+LANGUAGES_TEMPLATE = '''
%(language_available)s
%(browser_language)s
-''' % vars ()
+'''
html_re = re.compile ('(.*?)(?:[.]([^/.]*))?[.]html$')
+pages_dict = {}
def build_pages_dict (filelist):
- """Build dictionnary of available translations of each page"""
- pages_dict = {}
+ """Build dictionary of available translations of each page"""
+ global pages_dict
for f in filelist:
m = html_re.match (f)
if m:
@@ -60,142 +87,165 @@ def build_pages_dict (filelist):
pages_dict[g[0]] = [e]
else:
pages_dict[g[0]].append (e)
- return pages_dict
-
-
-def do_file (prefix, lang_ext, target, header, footer, pages_dict, out_root, name_filter,
- package_name, package_version, branch_str, mail_address_url, mail_address):
- file_name = langdefs.lang_file_name (prefix, lang_ext, '.html')
- in_f = open (file_name)
- s = in_f.read()
- in_f.close()
-
- s = re.sub ('%', '%%', s)
-
- ### add header
- if re.search (header_tag, s) == None:
- body = ''
- s = re.sub ('(?i)', body, s)
- if re.search ('(?i)]*>', body + header, s, 1)
- elif re.search ('(?i)', '' + header, s, 1)
- else:
- s = header + s
+
+def source_links_replace (m, source_val):
+ return 'href="' + os.path.join (source_val, m.group (1)) + '"'
+
+splitted_docs_re = re.compile ('(input/lsr/out-www/lilypond-snippets|Documentation/user/out-www/(lilypond|music-glossary|lilypond-program|lilypond-learning))/')
+
+snippets_ref_re = re.compile (r'href="(\.\./)?lilypond-snippets')
+src_href_re = re.compile ('(href|src)="(lily-.*?|.*?[.]png)"')
+source_link_re = re.compile ('href="source/(.*?)"')
+
+## Windows does not support symlinks.
+# This function avoids creating symlinks for splitted HTML manuals
+# Get rid of symlinks in GNUmakefile.in (local-WWW-post)
+# this also fixes missing PNGs only present in translated docs
+def hack_urls (s, prefix):
+ if splitted_docs_re.match (prefix):
+ s = src_href_re.sub ('\\1="../\\2"', s)
+
+ # fix Snippets xrefs ad hoc
+ s = snippets_ref_re.sub ('href="source/input/lsr/lilypond-snippets', s)
+
+ source_path = os.path.join (os.path.dirname (prefix), 'source')
+ if not os.path.islink (source_path):
+ return s
+ source_val = os.readlink (source_path)
+ return source_link_re.sub (lambda m: source_links_replace (m, source_val), s)
+
+body_tag_re = re.compile ('(?i)]*)>')
+html_tag_re = re.compile ('(?i)')
+doctype_re = re.compile ('(?i)\n'
+
+def add_header (s):
+ """Add header ( and doctype)"""
+ if header_tag_re.search (s) == None:
+ body = ''
+ (s, n) = body_tag_re.subn (body + header, s, 1)
+ if not n:
+ (s, n) = html_tag_re.subn ('' + header, s, 1)
+ if not n:
+ s = header + s
s = header_tag + '\n' + s
- if re.search ('(?i)\n'
+ if doctype_re.search (s) == None:
s = doctype + s
+ return s
- # remove info's annoying's indication of referencing external document
- s = re.sub (' \((lilypond|lilypond-internals|music-glossary)\)', '', s)
+title_tag_re = re.compile ('.*?(.*?)', re.DOTALL)
+AT_web_title_re = re.compile ('@WEB-TITLE@')
+def add_title (s):
# urg
# maybe find first node?
fallback_web_title = '-- --'
- m = re.match ('.*?(.*?)', s, re.DOTALL)
+ m = title_tag_re.match (s)
if m:
fallback_web_title = m.group (1)
- s = re.sub ('@WEB-TITLE@', fallback_web_title, s)
+ s = AT_web_title_re.sub (fallback_web_title, s)
+ return s
+
+end_body_re = re.compile ('(?i)')
+end_html_re = re.compile ('(?i)')
+
+def add_footer (s):
+ """add footer"""
+ (s, n) = end_body_re.subn (footer_tag + footer + '\n' + '', s, 1)
+ if not n:
+ (s, n) = end_html_re.subn (footer_tag + footer + '\n' + '', s, 1)
+ if not n:
+ s += footer_tag + footer + '\n'
+ return s
+
+def find_translations (prefix, lang_ext):
+ """find available translations of a page"""
+ available = []
+ missing = []
+ for l in langdefs.LANGUAGES:
+ e = l.webext
+ if lang_ext != e:
+ if e in pages_dict[prefix]:
+ available.append (l)
+ elif lang_ext == '' and l.enabled and reduce (operator.and_, [not prefix.startswith (s) for s in non_copied_pages]):
+ # English version of missing translated pages will be written
+ missing.append (e)
+ return available, missing
- ### add footer
+online_links_re = re.compile ('''(href|src)=[\'"]([^/][.]*[^.:\'"]*)(.html|.png)(#[^"\']*|)[\'"]''')
+offline_links_re = re.compile ('''href=[\'"]([^/][.]*[^.:\'"]*)(.html)(#[^"\']*|)[\'"]''')
+
+def process_links (s, prefix, lang_ext, file_name, missing, target):
page_flavors = {}
- if re.search (footer_tag, s) == None:
- if re.search ('(?i)', footer_tag + footer + '\n' + '', s, 1)
- elif re.search ('(?i)', footer_tag + footer + '\n' + '', s, 1)
+ if target == 'online':
+ # Strip .html, .png suffix for auto language selection (content
+ # negotiation). The menu must keep the full extension, so do
+ # this before adding the menu.
+ page_flavors[file_name] = \
+ [lang_ext, online_links_re.sub ('\\1="\\2\\4"', s)]
+ elif target == 'offline':
+ # in LANG doc index: don't rewrite .html suffixes
+ # as not all .LANG.html pages exist;
+ # the doc index should be translated and contain the right links
+ if prefix == 'Documentation/out-www/index':
+ page_flavors[file_name] = [lang_ext, s]
+ elif lang_ext == '':
+ page_flavors[file_name] = [lang_ext, s]
+ for e in missing:
+ page_flavors[langdefs.lang_file_name (prefix, e, '.html')] = \
+ [e, offline_links_re.sub ('href="\\1.' + e + '\\2\\3"', s)]
else:
- s += footer_tag + footer + '\n'
-
- # Find available translations of this page.
- available = []
- missing = []
- for l in langdefs.LANGUAGES:
- e = l.webext
- if lang_ext != e:
- if e in pages_dict[prefix]:
- available.append (l)
- elif lang_ext == '' and l.enabled: # English version of missing translated pages will be written
- missing.append (e)
-
- if target == 'online':
- # Strip .html, .png suffix for auto language selection (content
- # negotiation). The menu must keep the full extension, so do
- # this before adding the menu.
- page_flavors[file_name] = re.sub (
- '''(href|src)=[\'"]([^/][.]*[^.:\'"]*)(.html|.png)(#[^"\']*|)[\'"]''',
- '\\1="\\2\\4"', s)
- elif target == 'offline':
- if lang_ext == '':
- page_flavors[file_name] = s
- for e in missing:
- page_flavors[langdefs.lang_file_name (prefix, e, '.html')] = re.sub (
- '''href=[\'"]([^/][.]*[^.:\'"]*)(.html)(#[^"\']*|)[\'"]''',
- 'href="\\1.' + e + '\\2\\3"', s)
- else:
- page_flavors[file_name] = re.sub (
- '''href=[\'"]([^/][.]*[^.:\'"]*)(.html)(#[^"\']*|)[\'"]''',
- 'href="\\1.' + lang_ext + '\\2\\3"', s)
+ page_flavors[file_name] = \
+ [lang_ext,
+ offline_links_re.sub ('href="\\1.' + lang_ext + '\\2\\3"', s)]
+ return page_flavors
- # Add menu after stripping: must not have autoselection for language menu.
+def add_menu (page_flavors, prefix, available, target, translation):
+ for k in page_flavors.keys():
language_menu = ''
+ languages = ''
+ if page_flavors[k][0] != '':
+ t = translation[page_flavors[k][0]]
+ else:
+ t = _doc
for lang in available:
lang_file = lang.file_name (os.path.basename (prefix), '.html')
if language_menu != '':
language_menu += ', '
- language_menu += '%s' % (lang_file, lang.name)
-
- languages = ''
+ language_menu += '%s' % (lang_file, t (lang.name))
+ if target == 'offline':
+ browser_language = ''
+ elif target == 'online':
+ browser_language = t (browser_lang) % browser_language_url
if language_menu:
+ language_available = t (lang_available) % language_menu
languages = LANGUAGES_TEMPLATE % vars ()
-
- # Put language menu before '' and '' tags
- for k in page_flavors.keys():
- if re.search ('(?i)