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/'
41 default_footer = r"""<hr>Please take me <a href=@INDEX@>back to the index</a>
47 <table align="center" width="100%%" cellspacing="2" BGCOLOR="#e8ffe8">
51 <a href="%(wiki_base)s%(wiki_page)s">Read </a> comments on this page, or
52 <a href="%(wiki_base)s%(wiki_page)s?action=edit">add</a> one.
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="mailto:%(mail_address)s">%(mail_address)s</a>>.</font></address>
73 sys.stderr.write ("can't open file: %s\n" % f)
77 sys.stderr.write ("gulped empty file: %s\n" % f)
82 sys.stdout.write (r"""Usage: add-html-footer [OPTIONS]... HTML-FILE
83 Add header, footer and top of ChangLog file (up to the ********) to HTML-FILE
86 --changelog=FILE use FILE as ChangeLog [ChangeLog]
87 --footer=FILE use FILE as footer
88 --header=FILE use FILE as header
89 -h, --help print this help
90 --index=URL set homepage to URL
91 --name=NAME set package_name to NAME
92 --version=VERSION set package version to VERSION
97 (options, files) = getopt.getopt(sys.argv[1:], 'h', [
98 'changelog=', 'footer=', 'header=', 'help', 'index=',
104 if o == '--changelog':
106 elif o == '--footer':
108 elif o == '--header':
110 elif o == '-h' or o == '--help':
117 elif o == '--version':
120 raise 'unknown opt ', o
125 os.environ["CONFIGSUFFIX"] = 'www';
128 pw = ntpwd.getpwname(os.environ['USERNAME'])
131 if os.environ.has_key('FAKEROOTKEY') and os.environ.has_key('LOGNAME'):
132 pw = pwd.getpwnam (os.environ['LOGNAME'])
134 pw = pwd.getpwuid (os.getuid())
137 f = string.split (f, ',')[0]
140 def compose (default, file):
147 localtime = time.strftime ('%c %Z', time.localtime (time.time ()))
149 if os.path.basename (index_url) != "index.html":
150 index_url = os.path.join (index_url , "index.html")
151 top_url = os.path.dirname (index_url) + "/"
153 header = compose (default_header, header_file)
155 # compose (default_footer, footer_file)
157 header_tag = '<!-- header_tag -->'
158 footer_tag = '<!-- footer_tag -->'
160 # Python < 1.5.2 compatibility
162 # On most platforms, this is equivalent to
163 #`normpath(join(os.getcwd()), PATH)'. *Added in Python version 1.5.2*
164 if os.path.__dict__.has_key ('abspath'):
165 abspath = os.path.abspath
168 return os.path.normpath (os.path.join (os.getcwd (), path))
171 def remove_self_ref (s):
172 self_url = abspath (os.getcwd () + '/' + f)
173 #sys.stderr.write ('url0: %s\n' % self_url)
175 # self_url = re.sub ('.*?' + string.lower (package_name) + '[^/]*/',
177 # URG - this only works when source tree is unpacked in `src/' dir
178 # For some reason, .*? still eats away
179 # /home/fred/usr/src/lilypond-1.5.14/Documentation/user/out-www/lilypond/
182 # /home/fred/usr/src/lilypond-1.5.14/
185 self_url = re.sub ('.*?src/' + string.lower (package_name) + '[^/]*/',
188 #sys.stderr.write ('url1: %s\n' % self_url)
190 #urg, ugly lily-specific toplevel index hack
191 self_url = re.sub ('.*topdocs/out-www/index.html', 'index.html', self_url)
192 #sys.stderr.write ('url2: %s\n' % self_url)
194 # ugh, python2.[12] re is broken.
195 ## pat = re.compile ('.*?(<a href="[\./]*' + self_url + '#?[^"]*">)([^<]*)(</a>)', re.DOTALL)
196 pat = re.compile ('[.\n]*?(<a href="[\./]*' + self_url + '#?[^"]*">)([^<]*)(</a>)')
199 #sys.stderr.write ('self: %s\n' % m.group (2))
200 s = s[:m.start (1)] + m.group (2) + s[m.end (3):]
206 s = re.sub ('%', '%%', s)
209 changes = gulp_file (changelog_file)
211 #m = re.search ('^\\\\*\\\\*', changes)
212 m = re.search (r'\*\*\*', changes)
214 changes = changes[:m.start (0)]
215 s = re.sub ('top_of_ChangeLog', '<pre>\n'+ changes + '\n</pre>\n', s)
217 if re.search (header_tag, s) == None:
218 body = '<BODY BGCOLOR=WHITE TEXT=BLACK>'
219 s = re.sub ('(?i)<body>', body, s)
220 if re.search ('(?i)<BODY', s):
221 s = re.sub ('(?i)<body[^>]*>', body + header, s, 1)
222 elif re.search ('(?i)<html', s):
223 s = re.sub ('(?i)<html>', '<HTML>' + header, s, 1)
227 s = header_tag + '\n' + s
229 if re.search ('(?i)<!DOCTYPE', s) == None:
230 doctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">\n'
233 if re.search (footer_tag, s) == None:
234 s = s + footer_tag + '\n'
236 if re.search ('(?i)</body', s):
237 s = re.sub ('(?i)</body>', footer + '</BODY>', s, 1)
238 elif re.search ('(?i)</html', s):
239 s = re.sub ('(?i)</html>', footer + '</HTML>', s, 1)
247 if os.path.basename (f) == "index.html":
249 if os.path.basename (cwd) == "topdocs":
253 # don't cause ///////index.html entries in log files.
254 # index = "./index.html"
258 versiontup = string.split(package_version, '.')
259 branch_str = 'stable-branch'
260 if string.atoi ( versiontup[1]) % 2:
261 branch_str = 'development-branch'
263 wiki_page = ('v%s.%s-' % (versiontup[0], versiontup[1]) + f)
264 wiki_page = re.sub ('out-www/', '', wiki_page)
265 wiki_page = re.sub ('/', '-', wiki_page)
266 wiki_page = re.sub ('.html', '', wiki_page)
269 subst.update (locals())
275 # maybe find first node?
276 fallback_web_title = '-- --'
278 # ugh, python2.[12] re is broken.
279 #m = re.match ('.*?<title>\(.*?\)</title>', s, re.DOTALL)
280 m = re.match ('[.\n]*?<title>([.\n]*?)</title>', s)
282 fallback_web_title = m.group (1)
283 s = re.sub ('@WEB-TITLE@', fallback_web_title, s)
285 s = remove_self_ref (s)
287 open (f, 'w').write (s)