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 webmaster= mail_address
28 webmaster= os.environ['WEBMASTER']
38 #wiki_base = 'http://afavant.elte.hu/lywiki/'
42 default_footer = r"""<hr>Please take me <a href=@INDEX@>back to the index</a>
47 <div style="background-color: #e8ffe8; padding: 2; border: #c0ffc0 1px solid;">
51 This page is for %(package_name)s-%(package_version)s (%(branch_str)s). <br>
53 <address><font size="-1">
54 Report errors to <<a href="mailto:%(mail_address)s">%(mail_address)s</a>>.</font></address>
68 sys.stderr.write ("can't open file: %s\n" % f)
72 sys.stderr.write ("gulped empty file: %s\n" % f)
77 sys.stdout.write (r"""Usage: add-html-footer [OPTIONS]... HTML-FILE
78 Add header, footer and top of ChangLog file (up to the ********) to HTML-FILE
81 --changelog=FILE use FILE as ChangeLog [ChangeLog]
82 --footer=FILE use FILE as footer
83 --header=FILE use FILE as header
84 -h, --help print this help
85 --index=URL set homepage to URL
86 --name=NAME set package_name to NAME
87 --version=VERSION set package version to VERSION
92 (options, files) = getopt.getopt(sys.argv[1:], 'h', [
93 'changelog=', 'footer=', 'header=', 'help', 'index=',
99 if o == '--changelog':
101 elif o == '--footer':
103 elif o == '--header':
105 elif o == '-h' or o == '--help':
112 elif o == '--version':
115 raise 'unknown opt ', o
120 os.environ["CONFIGSUFFIX"] = 'www';
123 pw = ntpwd.getpwname(os.environ['USERNAME'])
126 if os.environ.has_key('FAKEROOTKEY') and os.environ.has_key('LOGNAME'):
127 pw = pwd.getpwnam (os.environ['LOGNAME'])
129 pw = pwd.getpwuid (os.getuid())
132 f = string.split (f, ',')[0]
135 def compose (default, file):
142 localtime = time.strftime ('%c %Z', time.localtime (time.time ()))
144 if os.path.basename (index_url) != "index.html":
145 index_url = os.path.join (index_url , "index.html")
146 top_url = os.path.dirname (index_url) + "/"
148 header = compose (default_header, header_file)
150 # compose (default_footer, footer_file)
152 header_tag = '<!-- header_tag -->'
153 footer_tag = '<!-- footer_tag -->'
155 # Python < 1.5.2 compatibility
157 # On most platforms, this is equivalent to
158 #`normpath(join(os.getcwd()), PATH)'. *Added in Python version 1.5.2*
159 if os.path.__dict__.has_key ('abspath'):
160 abspath = os.path.abspath
163 return os.path.normpath (os.path.join (os.getcwd (), path))
166 def remove_self_ref (s):
167 self_url = abspath (os.getcwd () + '/' + f)
168 #sys.stderr.write ('url0: %s\n' % self_url)
170 # self_url = re.sub ('.*?' + string.lower (package_name) + '[^/]*/',
172 # URG - this only works when source tree is unpacked in `src/' dir
173 # For some reason, .*? still eats away
174 # /home/fred/usr/src/lilypond-1.5.14/Documentation/user/out-www/lilypond/
177 # /home/fred/usr/src/lilypond-1.5.14/
180 self_url = re.sub ('.*?src/' + string.lower (package_name) + '[^/]*/',
183 #sys.stderr.write ('url1: %s\n' % self_url)
185 #urg, ugly lily-specific toplevel index hack
186 self_url = re.sub ('.*topdocs/out-www/index.html', 'index.html', self_url)
187 #sys.stderr.write ('url2: %s\n' % self_url)
189 # ugh, python2.[12] re is broken.
190 ## pat = re.compile ('.*?(<a href="[\./]*' + self_url + '#?[^"]*">)([^<]*)(</a>)', re.DOTALL)
191 pat = re.compile ('[.\n]*?(<a href="[\./]*' + self_url + '#?[^"]*">)([^<]*)(</a>)')
194 #sys.stderr.write ('self: %s\n' % m.group (2))
195 s = s[:m.start (1)] + m.group (2) + s[m.end (3):]
201 s = re.sub ('%', '%%', s)
204 if re.search (header_tag, s) == None:
205 body = '<BODY BGCOLOR=WHITE TEXT=BLACK>'
206 s = re.sub ('(?i)<body>', body, s)
207 if re.search ('(?i)<BODY', s):
208 s = re.sub ('(?i)<body[^>]*>', body + header, s, 1)
209 elif re.search ('(?i)<html', s):
210 s = re.sub ('(?i)<html>', '<HTML>' + header, s, 1)
214 s = header_tag + '\n' + s
216 if re.search ('(?i)<!DOCTYPE', s) == None:
217 doctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">\n'
220 if re.search (footer_tag, s) == None:
221 s = s + footer_tag + '\n'
223 if re.search ('(?i)</body', s):
224 s = re.sub ('(?i)</body>', footer + '</BODY>', s, 1)
225 elif re.search ('(?i)</html', s):
226 s = re.sub ('(?i)</html>', footer + '</HTML>', s, 1)
235 if os.path.basename (f) == "index.html":
237 if os.path.basename (cwd) == "topdocs":
241 # don't cause ///////index.html entries in log files.
242 # 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 open (f, 'w').write (s)
286 localedir = 'out/locale'
289 gettext.bindtextdomain ('newweb', localedir)
290 gettext.textdomain ('newweb')
300 ('nl', 'Nederlands'),
303 language_available = _ ("Other languages: %s.") % "%(language_menu)s"
304 browser_language = _ ("Using <A HREF='%s'>automatic language selection</A>.") \
305 % "%(root_url)sabout/browser-language"
307 LANGUAGES_TEMPLATE = '''\
309 %(language_available)s
315 def file_lang (file, lang):
316 (base, ext) = os.path.splitext (file)
317 base = os.path.splitext (base)[0]
318 if lang and lang != 'site':
319 return base + '.' + lang + ext
323 def i18n (file_name, page):
327 base_name = os.path.basename (file_name)
330 m = re.match ('.*[.]([^.]*).html', file_name)
334 # Find available translations of this page.
335 available = filter (lambda x: lang != x[0] \
336 and os.path.exists (file_lang (file_name, x[0])),
339 # Strip .html, .png suffix for auto language selection.
340 # page = re.sub ('''(href|src)=[\'"]([^/][.]*[^.:\'"]*)(.html(#[^"]*)|.png)[\'"]''',
343 # Create language menu.
345 for (prefix, name) in available:
346 lang_file = file_lang (base_name, prefix)
347 language_menu += '<a href="%(lang_file)s">%(name)s</a>' % vars ()
351 languages = LANGUAGES_TEMPLATE % vars ()
353 return page + languages