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']
37 default_footer = r"""<hr>Please take me <a href=@INDEX@>back to the index</a>
43 This page was built from @PACKAGE_NAME@-@PACKAGE_VERSION@ (@BRANCH@) by<br>
45 <address><font size="-1">@GCOS@ <<a href="mailto:@MAILADDRESS@">@MAILADDRESS@</a>>,
46 @LOCALTIME@.</font></address>"""
56 sys.stderr.write ("can't open file: %s\n" % f)
60 sys.stderr.write ("gulped empty file: %s\n" % f)
65 sys.stdout.write (r"""Usage: add-html-footer [OPTION]... HTML-FILE
66 Add header, footer and top of ChangLog file (up to the ********) to HTML-FILE
69 --changelog=FILE use FILE as ChangeLog [ChangeLog]
70 --footer=FILE use FILE as footer
71 --header=FILE use FILE as header
72 -h, --help print this help
73 --index=URL set homepage to URL
74 --name=NAME set package_name to NAME
75 --version=VERSION set package version to VERSION
79 (options, files) = getopt.getopt(sys.argv[1:], 'h', [
80 'changelog=', 'footer=', 'header=', 'help', 'index=',
86 if o == '--changelog':
92 elif o == '-h' or o == '--help':
99 elif o == '--version':
102 raise 'unknown opt ', o
107 os.environ["CONFIGSUFFIX"] = 'www';
110 pw = ntpwd.getpwname(os.environ['USERNAME'])
113 if os.environ.has_key('FAKEROOTKEY'):
114 pw = pwd.getpwnam (os.environ['LOGNAME'])
116 pw = pwd.getpwuid (os.getuid())
119 f = string.split (f, ',')[0]
122 def compose (default, file):
129 localtime = time.strftime ('%c %Z', time.localtime (time.time ()))
131 if os.path.basename (index_url) != "index.html":
132 index_url = os.path.join (index_url , "index.html")
133 top_url = os.path.dirname (index_url) + "/"
135 header = compose (default_header, header_file)
136 footer = compose (default_footer, footer_file) + built
137 header_tag = '<!-- header_tag -->'
138 footer_tag = '<!-- footer_tag -->'
140 # Python < 1.5.2 compatibility
142 # On most platforms, this is equivalent to
143 #`normpath(join(os.getcwd()), PATH)'. *Added in Python version 1.5.2*
144 if os.path.__dict__.has_key ('abspath'):
145 abspath = os.path.abspath
148 return os.path.normpath (os.path.join (os.getcwd (), path))
151 def remove_self_ref (s):
152 self_url = abspath (os.getcwd () + '/' + f)
153 #sys.stderr.write ('url0: %s\n' % self_url)
155 # self_url = re.sub ('.*?' + string.lower (package_name) + '[^/]*/',
157 # URG - this only works when source tree is unpacked in `src/' dir
158 # For some reason, .*? still eats away
159 # /home/fred/usr/src/lilypond-1.5.14/Documentation/user/out-www/lilypond/
162 # /home/fred/usr/src/lilypond-1.5.14/
165 self_url = re.sub ('.*?src/' + string.lower (package_name) + '[^/]*/',
168 #sys.stderr.write ('url1: %s\n' % self_url)
170 #urg, ugly lily-specific toplevel index hack
171 self_url = re.sub ('.*topdocs/out-www/index.html', 'index.html', self_url)
172 #sys.stderr.write ('url2: %s\n' % self_url)
174 # ugh, python2.[12] re is broken.
175 ## pat = re.compile ('.*?(<a href="[\./]*' + self_url + '#?[^"]*">)([^<]*)(</a>)', re.DOTALL)
176 pat = re.compile ('[.\n]*?(<a href="[\./]*' + self_url + '#?[^"]*">)([^<]*)(</a>)')
179 #sys.stderr.write ('self: %s\n' % m.group (2))
180 s = s[:m.start (1)] + m.group (2) + s[m.end (3):]
188 changes = gulp_file (changelog_file)
190 #m = re.search ('^\\\\*\\\\*', changes)
191 m = re.search (r'\*\*\*', changes)
193 changes = changes[:m.start (0)]
194 s = re.sub ('top_of_ChangeLog', '<pre>\n'+ changes + '\n</pre>\n', s)
196 if re.search (header_tag, s) == None:
197 body = '<BODY BGCOLOR=WHITE TEXT=BLACK>'
198 s = re.sub ('(?i)<body>', body, s)
199 if re.search ('(?i)<BODY', s):
200 s = re.sub ('(?i)<body[^>]*>', body + header, s, 1)
201 elif re.search ('(?i)<html', s):
202 s = re.sub ('(?i)<html>', '<HTML>' + header, s, 1)
206 s = header_tag + '\n' + s
208 if re.search ('(?i)<!DOCTYPE', s) == None:
209 doctype = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">\n'
212 if re.search (footer_tag, s) == None:
213 s = s + footer_tag + '\n'
215 if re.search ('(?i)</body', s):
216 s = re.sub ('(?i)</body>', footer + '</BODY>', s, 1)
217 elif re.search ('(?i)</html', s):
218 s = re.sub ('(?i)</html>', footer + '</HTML>', s, 1)
226 if os.path.basename (f) == "index.html":
228 if os.path.basename (cwd) == "topdocs":
232 # don't cause ///////index.html entries in log files.
233 # index = "./index.html"
237 versiontup = string.split(package_version, '.')
238 branch_str = 'stable-branch'
239 if string.atoi ( versiontup[1]) % 2:
240 branch_str = 'development-branch'
242 s = re.sub ('@INDEX@', index, s)
243 s = re.sub ('@TOP@', top, s)
244 s = re.sub ('@PACKAGE_NAME@', package_name, s)
245 s = re.sub ('@PACKAGE_VERSION@', package_version, s)
246 s = re.sub ('@WEBMASTER@', webmaster, s)
247 s = re.sub ('@GCOS@', gcos, s)
248 s = re.sub ('@LOCALTIME@', localtime, s)
249 s = re.sub ('@MAILADDRESS@', mail_address, s)
250 s = re.sub ('@BRANCH@', branch_str, s)
252 # ugh, python2.[12] re is broken.
253 #pat = re.compile ('.*?<!--\s*(@[^@]*@)\s*=\s*([^\s]*)\s*-->', re.DOTALL)
254 pat = re.compile ('[.\n]*?<!--\s*(@[^@]*@)\s*=\s*([^\s]*)\s*-->')
259 sys.stderr.write ('at: %s -> %s\n' % (at_var, at_val))
260 s = re.sub (at_var, at_val, s)
264 # maybe find first node?
265 fallback_web_title = '-- --'
267 # ugh, python2.[12] re is broken.
268 #m = re.match ('.*?<title>\(.*?\)</title>', s, re.DOTALL)
269 m = re.match ('[.\n]*?<title>([.\n]*?)</title>', s)
271 fallback_web_title = m.group (1)
272 s = re.sub ('@WEB-TITLE@', fallback_web_title, s)
274 s = remove_self_ref (s)
276 open (f, 'w').write (s)