12 # This is to try to make the docball not too big with almost duplicate files
14 non_copied_pages = ['Documentation/user/out-www/lilypond-big-page',
15 'Documentation/user/out-www/lilypond-internals-big-page',
16 'Documentation/user/out-www/music-glossary-big-page',
18 'Documentation/topdocs/out-www/NEWS',
19 'Documentation/topdocs/out-www/INSTALL',
20 'Documentation/bibliography/out-www/index',
21 'Documentation/bibliography/out-www/engraving',
22 'Documentation/bibliography/out-www/colorado',
23 'Documentation/bibliography/out-www/computer-notation'
24 'Documentation/out-www/THANKS',
25 'Documentation/out-www/DEDICATION',
26 'Documentation/topdocs/out-www/AUTHORS']
32 <div style="background-color: #e8ffe8; padding: 2; border: #c0ffc0 1px solid;">
35 This page is for %(package_name)s-%(package_version)s (%(branch_str)s). <br>
37 <address><font size="-1">
38 Report errors to <a href="%(mail_address_url)s">%(mail_address)s</a>.</font></address>
43 mail_address = 'http://post.gmane.org/post.php?group=gmane.comp.gnu.lilypond.bugs'
45 header_tag = '<!-- header_tag -->'
46 footer_tag = '<!-- footer_tag -->'
51 language_available = _ ("Other languages: %s.") % "%(language_menu)s"
52 browser_language = _ ("Using <A HREF='%s'>automatic language selection</A>.") \
53 % "/web/about/browser-language"
55 LANGUAGES_TEMPLATE = '''\
57 %(language_available)s
64 html_re = re.compile ('(.*?)(?:[.]([^/.]*))?[.]html$')
67 def build_pages_dict (filelist):
68 """Build dictionnary of available translations of each page"""
74 if len (g) <= 1 or g[1] == None:
78 if not g[0] in pages_dict.keys():
79 pages_dict[g[0]] = [e]
81 pages_dict[g[0]].append (e)
84 """Add header (<BODY> and doctype)"""
85 if re.search (header_tag, s) == None:
86 body = '<BODY BGCOLOR=WHITE TEXT=BLACK>'
87 s = re.sub ('(?i)<body>', body, s)
88 if re.search ('(?i)<BODY', s):
89 s = re.sub ('(?i)<body[^>]*>', body + header, s, 1)
90 elif re.search ('(?i)<html', s):
91 s = re.sub ('(?i)<html>', '<HTML>' + header, s, 1)
95 s = header_tag + '\n' + s
97 if re.search ('(?i)<!DOCTYPE', s) == None:
98 doctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">\n'
102 def info_external_ref_remove (s):
103 """Remove info's annoying's indication of referencing external document"""
104 return re.sub (' \((lilypond|lilypond-internals|music-glossary)\)</a>', '</a>', s)
108 # maybe find first node?
109 fallback_web_title = '-- --'
110 m = re.match ('.*?<title>(.*?)</title>', s, re.DOTALL)
112 fallback_web_title = m.group (1)
113 s = re.sub ('@WEB-TITLE@', fallback_web_title, s)
116 info_nav_bar = re.compile (r'<div class="node">\s*<p>\s*<a name=".+?"></a>(.+?)<hr>\s*</div>', re.M | re.S)
121 also add navigation bar to bottom of Info HTML pages"""
122 m = info_nav_bar.search (s)
124 custom_footer = '<br><hr>\n<div class="node">\n<p>' + m.group (1) + '</div>\n' + footer
126 custom_footer = footer
127 if re.search ('(?i)</body', s):
128 s = re.sub ('(?i)</body>', footer_tag + custom_footer + '\n' + '</BODY>', s, 1)
129 elif re.search ('(?i)</html', s):
130 s = re.sub ('(?i)</html>', footer_tag + custom_footer + '\n' + '</HTML>', s, 1)
132 s += footer_tag + custom_footer + '\n'
135 def find_translations (prefix, lang_ext):
136 """find available translations of a page"""
139 for l in langdefs.LANGUAGES:
142 if e in pages_dict[prefix]:
144 elif lang_ext == '' and l.enabled and not prefix in non_copied_pages:
145 # English version of missing translated pages will be written
147 return available, missing
149 def process_links (s, prefix, lang_ext, file_name, missing, target):
151 if target == 'online':
152 # Strip .html, .png suffix for auto language selection (content
153 # negotiation). The menu must keep the full extension, so do
154 # this before adding the menu.
155 page_flavors[file_name] = re.sub (
156 '''(href|src)=[\'"]([^/][.]*[^.:\'"]*)(.html|.png)(#[^"\']*|)[\'"]''',
158 elif target == 'offline':
159 # in LANG doc index: don't rewrite .html suffixes as not all .LANG.html pages exist
160 # the doc index should be translated and contain the right links
161 if prefix == 'Documentation/out-www/index':
162 page_flavors[file_name] = s
164 page_flavors[file_name] = s
166 page_flavors[langdefs.lang_file_name (prefix, e, '.html')] = re.sub (
167 '''href=[\'"]([^/][.]*[^.:\'"]*)(.html)(#[^"\']*|)[\'"]''',
168 'href="\\1.' + e + '\\2\\3"', s)
170 page_flavors[file_name] = re.sub (
171 '''href=[\'"]([^/][.]*[^.:\'"]*)(.html)(#[^"\']*|)[\'"]''',
172 'href="\\1.' + lang_ext + '\\2\\3"', s)
175 def add_menu (page_flavors, prefix, available):
177 for lang in available:
178 lang_file = lang.file_name (os.path.basename (prefix), '.html')
179 if language_menu != '':
180 language_menu += ', '
181 language_menu += '<a href="%s">%s</a>' % (lang_file, lang.name)
185 languages = LANGUAGES_TEMPLATE % vars ()
187 # put language menu before '</body>' and '</html>' tags
188 for k in page_flavors.keys():
189 if re.search ('(?i)</body', page_flavors[k]):
190 page_flavors[k] = re.sub ('(?i)</body>', languages + '</BODY>', page_flavors[k], 1)
191 elif re.search ('(?i)</html', page_flavors[k]):
192 page_flavors[k] = re.sub ('(?i)</html>', languages + '</HTML>', page_flavors[k], 1)
194 page_flavors[k] += languages
198 def add_html_footer (package_name = '',
199 package_version = '',
201 name_filter = lambda s: s):
202 """Add header, footer to a number of HTML files
205 package_name=NAME set package_name to NAME
206 package_version=VERSION set package version to VERSION
207 targets=offline|online set page processing depending on the target
208 offline is for reading HTML pages locally
209 online is for hosting the HTML pages on a website with content
211 name_filter a HTML file name filter
213 localtime = time.strftime ('%c %Z', time.localtime (time.time ()))
215 if re.search ("http://", mail_address):
216 mail_address_url = mail_address
218 mail_address_url= 'mailto:' + mail_address
220 versiontup = package_version.split ('.')
221 branch_str = 'stable-branch'
222 if int ( versiontup[1]) % 2:
223 branch_str = 'development-branch'
225 for prefix, ext_list in pages_dict.items ():
226 for lang_ext in ext_list:
227 file_name = langdefs.lang_file_name (prefix, lang_ext, '.html')
228 in_f = open (file_name)
232 s = re.sub ('%', '%%', s)
234 # seems to be no more needed
235 # s = info_external_ref_remove (s)
238 if re.search (footer_tag, s) == None:
240 available, missing = find_translations (prefix, lang_ext)
241 page_flavors = process_links (s, prefix, lang_ext, file_name, missing, target)
242 # Add menu after stripping: must not have autoselection for language menu.
243 page_flavors = add_menu (page_flavors, prefix, available)
244 # urg, this stuff is oudated and seems useless, let's disable it
246 # for e in [l.webext for l in langdefs.LANGUAGES]:
247 # if not e in pages_dict[prefix]:
248 # page_flavors[langdefs.lang_file_name (prefix, e, '.html')] = s
251 subst.update (locals())
252 for k in page_flavors.keys():
253 page_flavors[k] = page_flavors[k] % subst
255 out_f = open (name_filter (k), 'w')
256 out_f.write (page_flavors[k])
258 # if the page is translated, a .en.html symlink is necessary for content negotiation
259 if target == 'online' and ext_list != ['']:
260 os.symlink (os.path.basename (prefix) + '.html', name_filter (prefix + '.en.html'))