4 Print a nice footer. add the top of the ChangeLog file (up to the ********)
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>
71 sys.stderr.write ("can't open file: %s\n" % f)
75 sys.stderr.write ("gulped empty file: %s\n" % f)
80 sys.stdout.write (r"""Usage: add-html-footer [OPTIONS]... HTML-FILE
81 Add header, footer and top of ChangLog file (up to the ********) to HTML-FILE
84 --changelog=FILE use FILE as ChangeLog [ChangeLog]
85 --footer=FILE use FILE as footer
86 --header=FILE use FILE as header
87 -h, --help print this help
88 --index=URL set homepage to URL
89 --name=NAME set package_name to NAME
90 --version=VERSION set package version to VERSION
95 (options, files) = getopt.getopt(sys.argv[1:], 'h', [
96 'changelog=', 'footer=', 'header=', 'help', 'index=',
102 if o == '--changelog':
104 elif o == '--footer':
106 elif o == '--header':
108 elif o == '-h' or o == '--help':
115 elif o == '--version':
118 raise 'unknown opt ', o
123 os.environ["CONFIGSUFFIX"] = 'www';
126 pw = ntpwd.getpwname(os.environ['USERNAME'])
129 if os.environ.has_key('FAKEROOTKEY') and os.environ.has_key('LOGNAME'):
130 pw = pwd.getpwnam (os.environ['LOGNAME'])
132 pw = pwd.getpwuid (os.getuid())
135 f = string.split (f, ',')[0]
138 def compose (default, file):
145 localtime = time.strftime ('%c %Z', time.localtime (time.time ()))
147 if os.path.basename (index_url) != "index.html":
148 index_url = os.path.join (index_url , "index.html")
149 top_url = os.path.dirname (index_url) + "/"
151 header = compose (default_header, header_file)
153 # compose (default_footer, footer_file)
155 header_tag = '<!-- header_tag -->'
156 footer_tag = '<!-- footer_tag -->'
158 # Python < 1.5.2 compatibility
160 # On most platforms, this is equivalent to
161 #`normpath(join(os.getcwd()), PATH)'. *Added in Python version 1.5.2*
162 if os.path.__dict__.has_key ('abspath'):
163 abspath = os.path.abspath
166 return os.path.normpath (os.path.join (os.getcwd (), path))
169 def remove_self_ref (s):
170 self_url = abspath (os.getcwd () + '/' + f)
171 #sys.stderr.write ('url0: %s\n' % self_url)
173 # self_url = re.sub ('.*?' + string.lower (package_name) + '[^/]*/',
175 # URG - this only works when source tree is unpacked in `src/' dir
176 # For some reason, .*? still eats away
177 # /home/fred/usr/src/lilypond-1.5.14/Documentation/user/out-www/lilypond/
180 # /home/fred/usr/src/lilypond-1.5.14/
183 self_url = re.sub ('.*?src/' + string.lower (package_name) + '[^/]*/',
186 #sys.stderr.write ('url1: %s\n' % self_url)
188 #urg, ugly lily-specific toplevel index hack
189 self_url = re.sub ('.*topdocs/out-www/index.html', 'index.html', self_url)
190 #sys.stderr.write ('url2: %s\n' % self_url)
192 # ugh, python2.[12] re is broken.
193 ## pat = re.compile ('.*?(<a href="[\./]*' + self_url + '#?[^"]*">)([^<]*)(</a>)', re.DOTALL)
194 pat = re.compile ('[.\n]*?(<a href="[\./]*' + self_url + '#?[^"]*">)([^<]*)(</a>)')
197 #sys.stderr.write ('self: %s\n' % m.group (2))
198 s = s[:m.start (1)] + m.group (2) + s[m.end (3):]
204 s = re.sub ('%', '%%', s)
207 if re.search (header_tag, s) == None:
208 body = '<BODY BGCOLOR=WHITE TEXT=BLACK>'
209 s = re.sub ('(?i)<body>', body, s)
210 if re.search ('(?i)<BODY', s):
211 s = re.sub ('(?i)<body[^>]*>', body + header, s, 1)
212 elif re.search ('(?i)<html', s):
213 s = re.sub ('(?i)<html>', '<HTML>' + header, s, 1)
217 s = header_tag + '\n' + s
219 if re.search ('(?i)<!DOCTYPE', s) == None:
220 doctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">\n'
223 if re.search (footer_tag, s) == None:
224 if re.search ('(?i)</body', s):
225 s = re.sub ('(?i)</body>', footer_tag + footer + '\n' + '</BODY>', s, 1)
226 elif re.search ('(?i)</html', s):
227 s = re.sub ('(?i)</html>', footer_tag + footer + '\n' + '</HTML>', s, 1)
229 s = s + footer_tag + footer + '\n'
236 if os.path.basename (f) == "index.html":
238 if os.path.basename (cwd) == "topdocs":
242 # don't cause ///////index.html entries in log files.
243 # index = "./index.html"
246 versiontup = string.split(package_version, '.')
247 branch_str = 'stable-branch'
248 if string.atoi ( versiontup[1]) % 2:
249 branch_str = 'development-branch'
251 wiki_page = ('v%s.%s-' % (versiontup[0], versiontup[1]) + f)
252 wiki_page = re.sub ('out-www/', '', wiki_page)
253 wiki_page = re.sub ('/', '-', wiki_page)
254 wiki_page = re.sub (r'\.-', '', wiki_page)
255 wiki_page = re.sub ('.html', '', wiki_page)
260 wiki_string = (r'''<a href="%(wiki_base)s%(wiki_page)s">Read </a> comments on this page, or
261 <a href="%(wiki_base)s%(wiki_page)s?action=edit">add</a> one.''' %
262 { 'wiki_base': wiki_base,
263 'wiki_page': wiki_page})
266 subst.update (locals())
270 # maybe find first node?
271 fallback_web_title = '-- --'
273 # ugh, python2.[12] re is broken.
274 #m = re.match ('.*?<title>\(.*?\)</title>', s, re.DOTALL)
275 m = re.match ('[.\n]*?<title>([.\n]*?)</title>', s)
277 fallback_web_title = m.group (1)
278 s = re.sub ('@WEB-TITLE@', fallback_web_title, s)
280 s = remove_self_ref (s)
282 # remove info's annoying's indication of referencing external document
283 s = re.sub (' \((lilypond|lilypond-internals|music-glossary)\)</a>',
286 open (f, 'w').write (s)
290 localedir = 'out/locale'
293 gettext.bindtextdomain ('newweb', localedir)
294 gettext.textdomain ('newweb')
304 ('nl', 'Nederlands'),
307 language_available = _ ("Other languages: %s.") % "%(language_menu)s"
308 browser_language = _ ("Using <A HREF='%s'>automatic language selection</A>.") \
309 % "%(root_url)sabout/browser-language"
311 LANGUAGES_TEMPLATE = '''\
313 %(language_available)s
319 def file_lang (file, lang):
320 (base, ext) = os.path.splitext (file)
321 base = os.path.splitext (base)[0]
322 if lang and lang != 'site':
323 return base + '.' + lang + ext
327 def i18n (file_name, page):
331 base_name = os.path.basename (file_name)
334 m = re.match ('.*[.]([^.]*).html', file_name)
338 # Find available translations of this page.
339 available = filter (lambda x: lang != x[0] \
340 and os.path.exists (file_lang (file_name, x[0])),
343 # Strip .html, .png suffix for auto language selection.
344 # page = re.sub ('''(href|src)=[\'"]([^/][.]*[^.:\'"]*)(.html(#[^"]*)|.png)[\'"]''',
347 # Create language menu.
349 for (prefix, name) in available:
350 lang_file = file_lang (base_name, prefix)
351 language_menu += '<a href="%(lang_file)s">%(name)s</a>' % vars ()
355 languages = LANGUAGES_TEMPLATE % vars ()
357 # Put language menu before '</body>' and '</html>' tags
358 if re.search ('(?i)</body', page):
359 page = re.sub ('(?i)</body>', languages + '</BODY>', page, 1)
360 elif re.search ('(?i)</html', page):
361 page = re.sub ('(?i)</html>', languages + '</HTML>', page, 1)
363 page = page + languages