4 Print a nice footer. add the top of the ChangeLog file (up to the ********)
16 content_negotiation = False
20 mail_address = '(address unknown)'
22 mail_address= os.environ['MAILADDRESS']
26 mail_address_url= 'mailto:' + mail_address
27 if re.search ("http://", mail_address):
28 mail_address_url = mail_address
30 webmaster= mail_address
32 webmaster= os.environ['WEBMASTER']
42 #wiki_base = 'http://afavant.elte.hu/lywiki/'
46 default_footer = r"""<hr>Please take me <a href=@INDEX@>back to the index</a>
51 <div style="background-color: #e8ffe8; padding: 2; border: #c0ffc0 1px solid;">
55 This page is for %(package_name)s-%(package_version)s (%(branch_str)s). <br>
57 <address><font size="-1">
58 Report errors to <a href="%(mail_address_url)s">%(mail_address)s</a>.</font></address>
67 sys.stdout.write (r"""Usage: add-html-footer [OPTIONS]... HTML-FILE
68 Add header, footer and top of ChangLog file (up to the ********) to HTML-FILE
71 --changelog=FILE use FILE as ChangeLog [ChangeLog]
72 --content-negotiation strip .html and .png from urls
73 --footer=FILE use FILE as footer
74 --header=FILE use FILE as header
75 -h, --help print this help
76 --index=URL set homepage to URL
77 --name=NAME set package_name to NAME
78 --version=VERSION set package version to VERSION
83 (options, files) = getopt.getopt(sys.argv[1:], 'h', [
84 'changelog=', 'footer=', 'header=', 'help', 'index=',
85 'name=', 'content-negotiation', 'version='])
90 if o == '--changelog':
92 elif o == '--content-negotiation':
93 content_negotiation = True
98 elif o == '-h' or o == '--help':
105 elif o == '--version':
108 raise 'unknown opt ', o
111 def compose (default, file):
114 s = open (file).read ()
117 localtime = time.strftime ('%c %Z', time.localtime (time.time ()))
119 if os.path.basename (index_url) != "index.html":
120 index_url = os.path.join (index_url , "index.html")
121 top_url = os.path.dirname (index_url) + "/"
123 header = compose (default_header, header_file)
125 # compose (default_footer, footer_file)
127 header_tag = '<!-- header_tag -->'
128 footer_tag = '<!-- footer_tag -->'
130 # Python < 1.5.2 compatibility
132 # On most platforms, this is equivalent to
133 #`normpath(join(os.getcwd()), PATH)'. *Added in Python version 1.5.2*
134 if os.path.__dict__.has_key ('abspath'):
135 abspath = os.path.abspath
138 return os.path.normpath (os.path.join (os.getcwd (), path))
141 def remove_self_ref (s):
142 self_url = abspath (os.getcwd () + '/' + f)
143 #sys.stderr.write ('url0: %s\n' % self_url)
145 # self_url = re.sub ('.*?' + string.lower (package_name) + '[^/]*/',
147 # URG - this only works when source tree is unpacked in `src/' dir
148 # For some reason, .*? still eats away
149 # /home/fred/usr/src/lilypond-1.5.14/Documentation/user/out-www/lilypond/
152 # /home/fred/usr/src/lilypond-1.5.14/
155 self_url = re.sub ('.*?src/' + string.lower (package_name) + '[^/]*/',
158 #sys.stderr.write ('url1: %s\n' % self_url)
160 #urg, ugly lily-specific toplevel index hack
161 self_url = re.sub ('.*topdocs/out-www/index.html', 'index.html', self_url)
162 #sys.stderr.write ('url2: %s\n' % self_url)
164 # ugh, python2.[12] re is broken.
165 ## pat = re.compile ('.*?(<a href="[\./]*' + self_url + '#?[^"]*">)([^<]*)(</a>)', re.DOTALL)
166 pat = re.compile ('[.\n]*?(<a href="[\./]*' + self_url + '#?[^"]*">)([^<]*)(</a>)')
169 #sys.stderr.write ('self: %s\n' % m.group (2))
170 s = s[:m.start (1)] + m.group (2) + s[m.end (3):]
175 if os.path.islink (f):
179 s = re.sub ('%', '%%', s)
182 if re.search (header_tag, s) == None:
183 body = '<BODY BGCOLOR=WHITE TEXT=BLACK>'
184 s = re.sub ('(?i)<body>', body, s)
185 if re.search ('(?i)<BODY', s):
186 s = re.sub ('(?i)<body[^>]*>', body + header, s, 1)
187 elif re.search ('(?i)<html', s):
188 s = re.sub ('(?i)<html>', '<HTML>' + header, s, 1)
192 s = header_tag + '\n' + s
194 if re.search ('(?i)<!DOCTYPE', s) == None:
195 doctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">\n'
198 if re.search (footer_tag, s) == None:
199 if re.search ('(?i)</body', s):
200 s = re.sub ('(?i)</body>', footer_tag + footer + '\n' + '</BODY>', s, 1)
201 elif re.search ('(?i)</html', s):
202 s = re.sub ('(?i)</html>', footer_tag + footer + '\n' + '</HTML>', s, 1)
204 s = s + footer_tag + footer + '\n'
211 if os.path.basename (f) == "index.html":
213 if os.path.basename (cwd) == "topdocs":
217 # don't cause ///////index.html entries in log files.
218 # index = "./index.html"
221 versiontup = string.split(package_version, '.')
222 branch_str = 'stable-branch'
223 if string.atoi ( versiontup[1]) % 2:
224 branch_str = 'development-branch'
226 wiki_page = ('v%s.%s-' % (versiontup[0], versiontup[1]) + f)
227 wiki_page = re.sub ('out-www/', '', wiki_page)
228 wiki_page = re.sub ('/', '-', wiki_page)
229 wiki_page = re.sub (r'\.-', '', wiki_page)
230 wiki_page = re.sub ('.html', '', wiki_page)
235 wiki_string = (r'''<a href="%(wiki_base)s%(wiki_page)s">Read </a> comments on this page, or
236 <a href="%(wiki_base)s%(wiki_page)s?action=edit">add</a> one.''' %
237 { 'wiki_base': wiki_base,
238 'wiki_page': wiki_page})
241 subst.update (locals())
245 # maybe find first node?
246 fallback_web_title = '-- --'
248 # ugh, python2.[12] re is broken.
249 #m = re.match ('.*?<title>\(.*?\)</title>', s, re.DOTALL)
250 m = re.match ('[.\n]*?<title>([.\n]*?)</title>', s)
252 fallback_web_title = m.group (1)
253 s = re.sub ('@WEB-TITLE@', fallback_web_title, s)
255 s = remove_self_ref (s)
257 # remove info's annoying's indication of referencing external document
258 s = re.sub (' \((lilypond|lilypond-internals|music-glossary)\)</a>',
261 if not os.path.islink (f):
262 open (f, 'w').write (s)
266 localedir = 'out/locale'
269 gettext.bindtextdomain ('newweb', localedir)
270 gettext.textdomain ('newweb')
280 ('nl', 'Nederlands'),
284 language_available = _ ("Other languages: %s.") % "%(language_menu)s"
285 browser_language = _ ("Using <A HREF='%s'>automatic language selection</A>.") \
286 % "%(root_url)sabout/browser-language"
288 LANGUAGES_TEMPLATE = '''\
290 %(language_available)s
296 def file_lang (file, lang):
297 (base, ext) = os.path.splitext (file)
298 base = os.path.splitext (base)[0]
299 if lang and lang != C:
300 return base + '.' + lang + ext
304 def i18n (file_name, page):
308 base_name = os.path.basename (file_name)
311 m = re.match ('.*[.]([^/.]*).html', file_name)
315 # Find available translations of this page.
316 available = filter (lambda x: lang != x[0] \
317 and os.path.exists (file_lang (file_name, x[0])),
320 # Strip .html, .png suffix for auto language selection (content
321 # negotiation). The menu must keep the full extension, so do
322 # this before adding the menu.
323 if content_negotiation:
324 page = re.sub ('''(href|src)=[\'"]([^/][.]*[^.:\'"]*)(.html|.png)(#[^"\']*|)[\'"]''',
325 '\\1="\\2\\4"', page)
327 # Add menu after stripping: must not have autoselection for language menu.
329 for (prefix, name) in available:
330 lang_file = file_lang (base_name, prefix)
331 if language_menu != '':
332 language_menu += ', '
333 language_menu += '<a href="%(lang_file)s">%(name)s</a>' % vars ()
337 languages = LANGUAGES_TEMPLATE % vars ()
339 # Put language menu before '</body>' and '</html>' tags
340 if re.search ('(?i)</body', page):
341 page = re.sub ('(?i)</body>', languages + '</BODY>', page, 1)
342 elif re.search ('(?i)</html', page):
343 page = re.sub ('(?i)</html>', languages + '</HTML>', page, 1)
345 page = page + languages
347 if content_negotiation and language_menu:
348 os.symlink (file_name, os.path.splitext (os.path.basename (file_name))[0] + '.en.html')