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>
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 --footer=FILE use FILE as footer
73 --header=FILE use FILE as header
74 -h, --help print this help
75 --index=URL set homepage to URL
76 --name=NAME set package_name to NAME
77 --version=VERSION set package version to VERSION
82 (options, files) = getopt.getopt(sys.argv[1:], 'h', [
83 'changelog=', 'footer=', 'header=', 'help', 'index=',
89 if o == '--changelog':
95 elif o == '-h' or o == '--help':
102 elif o == '--version':
105 raise 'unknown opt ', o
110 os.environ["CONFIGSUFFIX"] = 'www';
113 pw = ntpwd.getpwname(os.environ['USERNAME'])
116 if os.environ.has_key('FAKEROOTKEY') and os.environ.has_key('LOGNAME'):
117 pw = pwd.getpwnam (os.environ['LOGNAME'])
119 pw = pwd.getpwuid (os.getuid())
122 f = string.split (f, ',')[0]
125 def compose (default, file):
128 s = open (file).read ()
132 localtime = time.strftime ('%c %Z', time.localtime (time.time ()))
134 if os.path.basename (index_url) != "index.html":
135 index_url = os.path.join (index_url , "index.html")
136 top_url = os.path.dirname (index_url) + "/"
138 header = compose (default_header, header_file)
140 # compose (default_footer, footer_file)
142 header_tag = '<!-- header_tag -->'
143 footer_tag = '<!-- footer_tag -->'
145 # Python < 1.5.2 compatibility
147 # On most platforms, this is equivalent to
148 #`normpath(join(os.getcwd()), PATH)'. *Added in Python version 1.5.2*
149 if os.path.__dict__.has_key ('abspath'):
150 abspath = os.path.abspath
153 return os.path.normpath (os.path.join (os.getcwd (), path))
156 def remove_self_ref (s):
157 self_url = abspath (os.getcwd () + '/' + f)
158 #sys.stderr.write ('url0: %s\n' % self_url)
160 # self_url = re.sub ('.*?' + string.lower (package_name) + '[^/]*/',
162 # URG - this only works when source tree is unpacked in `src/' dir
163 # For some reason, .*? still eats away
164 # /home/fred/usr/src/lilypond-1.5.14/Documentation/user/out-www/lilypond/
167 # /home/fred/usr/src/lilypond-1.5.14/
170 self_url = re.sub ('.*?src/' + string.lower (package_name) + '[^/]*/',
173 #sys.stderr.write ('url1: %s\n' % self_url)
175 #urg, ugly lily-specific toplevel index hack
176 self_url = re.sub ('.*topdocs/out-www/index.html', 'index.html', self_url)
177 #sys.stderr.write ('url2: %s\n' % self_url)
179 # ugh, python2.[12] re is broken.
180 ## pat = re.compile ('.*?(<a href="[\./]*' + self_url + '#?[^"]*">)([^<]*)(</a>)', re.DOTALL)
181 pat = re.compile ('[.\n]*?(<a href="[\./]*' + self_url + '#?[^"]*">)([^<]*)(</a>)')
184 #sys.stderr.write ('self: %s\n' % m.group (2))
185 s = s[:m.start (1)] + m.group (2) + s[m.end (3):]
191 s = re.sub ('%', '%%', s)
194 if re.search (header_tag, s) == None:
195 body = '<BODY BGCOLOR=WHITE TEXT=BLACK>'
196 s = re.sub ('(?i)<body>', body, s)
197 if re.search ('(?i)<BODY', s):
198 s = re.sub ('(?i)<body[^>]*>', body + header, s, 1)
199 elif re.search ('(?i)<html', s):
200 s = re.sub ('(?i)<html>', '<HTML>' + header, s, 1)
204 s = header_tag + '\n' + s
206 if re.search ('(?i)<!DOCTYPE', s) == None:
207 doctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">\n'
210 if re.search (footer_tag, s) == None:
211 if re.search ('(?i)</body', s):
212 s = re.sub ('(?i)</body>', footer_tag + footer + '\n' + '</BODY>', s, 1)
213 elif re.search ('(?i)</html', s):
214 s = re.sub ('(?i)</html>', footer_tag + footer + '\n' + '</HTML>', s, 1)
216 s = s + footer_tag + footer + '\n'
223 if os.path.basename (f) == "index.html":
225 if os.path.basename (cwd) == "topdocs":
229 # don't cause ///////index.html entries in log files.
230 # index = "./index.html"
233 versiontup = string.split(package_version, '.')
234 branch_str = 'stable-branch'
235 if string.atoi ( versiontup[1]) % 2:
236 branch_str = 'development-branch'
238 wiki_page = ('v%s.%s-' % (versiontup[0], versiontup[1]) + f)
239 wiki_page = re.sub ('out-www/', '', wiki_page)
240 wiki_page = re.sub ('/', '-', wiki_page)
241 wiki_page = re.sub (r'\.-', '', wiki_page)
242 wiki_page = re.sub ('.html', '', wiki_page)
247 wiki_string = (r'''<a href="%(wiki_base)s%(wiki_page)s">Read </a> comments on this page, or
248 <a href="%(wiki_base)s%(wiki_page)s?action=edit">add</a> one.''' %
249 { 'wiki_base': wiki_base,
250 'wiki_page': wiki_page})
253 subst.update (locals())
257 # maybe find first node?
258 fallback_web_title = '-- --'
260 # ugh, python2.[12] re is broken.
261 #m = re.match ('.*?<title>\(.*?\)</title>', s, re.DOTALL)
262 m = re.match ('[.\n]*?<title>([.\n]*?)</title>', s)
264 fallback_web_title = m.group (1)
265 s = re.sub ('@WEB-TITLE@', fallback_web_title, s)
267 s = remove_self_ref (s)
269 # remove info's annoying's indication of referencing external document
270 s = re.sub (' \((lilypond|lilypond-internals|music-glossary)\)</a>',
273 open (f, 'w').write (s)
277 localedir = 'out/locale'
280 gettext.bindtextdomain ('newweb', localedir)
281 gettext.textdomain ('newweb')
291 ('nl', 'Nederlands'),
294 language_available = _ ("Other languages: %s.") % "%(language_menu)s"
295 browser_language = _ ("Using <A HREF='%s'>automatic language selection</A>.") \
296 % "%(root_url)sabout/browser-language"
298 LANGUAGES_TEMPLATE = '''\
300 %(language_available)s
306 def file_lang (file, lang):
307 (base, ext) = os.path.splitext (file)
308 base = os.path.splitext (base)[0]
309 if lang and lang != 'site':
310 return base + '.' + lang + ext
314 def i18n (file_name, page):
318 base_name = os.path.basename (file_name)
321 m = re.match ('.*[.]([^.]*).html', file_name)
325 # Find available translations of this page.
326 available = filter (lambda x: lang != x[0] \
327 and os.path.exists (file_lang (file_name, x[0])),
330 # Strip .html, .png suffix for auto language selection.
331 # page = re.sub ('''(href|src)=[\'"]([^/][.]*[^.:\'"]*)(.html(#[^"]*)|.png)[\'"]''',
334 # Create language menu.
336 for (prefix, name) in available:
337 lang_file = file_lang (base_name, prefix)
338 language_menu += '<a href="%(lang_file)s">%(name)s</a>' % vars ()
342 languages = LANGUAGES_TEMPLATE % vars ()
344 # Put language menu before '</body>' and '</html>' tags
345 if re.search ('(?i)</body', page):
346 page = re.sub ('(?i)</body>', languages + '</BODY>', page, 1)
347 elif re.search ('(?i)</html', page):
348 page = re.sub ('(?i)</html>', languages + '</HTML>', page, 1)
350 page = page + languages