X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=stepmake%2Fbin%2Fadd-html-footer.py;h=da47dab1e557d8c4acf66c43dee4d09da850fcfb;hb=637eff7ba745bbeb96d347d1798615529cea9e5f;hp=e8a858a0c9b3fa6d065b0f257ca134be606bdbb4;hpb=1cf3d59c1559fb9774c4c1c8cae155cfe54a927c;p=lilypond.git
diff --git a/stepmake/bin/add-html-footer.py b/stepmake/bin/add-html-footer.py
index e8a858a0c9..da47dab1e5 100644
--- a/stepmake/bin/add-html-footer.py
+++ b/stepmake/bin/add-html-footer.py
@@ -1,134 +1,254 @@
#!@PYTHON@
"""
-Print a nice footer. add the top of the NEWS file (up to the ********)
+Print a nice footer. add the top of the ChangeLog file (up to the ********)
"""
-
-program_name = 'add-html-footer'
-version = '0.1'
-
+import re
import sys
import os
-from string import *
+import time
+import string
import getopt
-import __main__
-fullname = "unknown"
-news_file = ''
+gcos = "unknown"
+index_url=''
+top_url=''
+changelog_file=''
+package_name = ''
+package_version = ''
+
+mail_address = '(address unknown)'
+try:
+ mail_address= os.environ['MAILADDRESS']
+except KeyError:
+ pass
+
+webmaster= mail_address
+try:
+ webmaster= os.environ['WEBMASTER']
+except KeyError:
+ pass
+
+header_file = ''
+footer_file = ''
+default_header = r"""
+"""
+
+default_footer = r"""
Please take me back to the index
+of @PACKAGE_NAME@
+"""
+
+built = r"""
+
+This page was built from @PACKAGE_NAME@-@PACKAGE_VERSION@ by
+
+
@GCOS@ <@MAILADDRESS@>,
+@LOCALTIME@."""
+
-index_file=''
-banner_file = ''
-news_file=''
-news =''
-(options, files) = getopt.getopt(sys.argv[1:], 'hp:', ['help', 'news=', 'index=', 'package='])
+def gulp_file (f):
+ try:
+ i = open(f)
+ i.seek (0, 2)
+ n = i.tell ()
+ i.seek (0,0)
+ except:
+ sys.stderr.write ("can't open file: %s\n" % f)
+ return ''
+ s = i.read (n)
+ if len (s) <= 0:
+ sys.stderr.write ("gulped empty file: %s\n" % f)
+ i.close ()
+ return s
def help ():
- sys.stdout.write ("Usage: add-html-footer [OPTION]... HTML-FILE\n"
- "Add a nice footer, add the top of the NEWS file (up to the ********)\n\n"
- + "Options:\n"
- + " -h, --help print this help\n"
- + " -p, --package=DIR specify package\n"
- )
- sys.exit (0)
+ sys.stdout.write (r"""Usage: add-html-footer [OPTION]... HTML-FILE
+Add header, footer and top of ChangLog file (up to the ********) to HTML-FILE
+
+Options:
+ --changelog=FILE use FILE as ChangeLog [ChangeLog]
+ --footer=FILE use FILE as footer
+ --header=FILE use FILE as header
+ -h, --help print this help
+ --index=URL set homepage to URL
+ --name=NAME set package_name to NAME
+ --version=VERSION set package version to VERSION
+""")
+ sys.exit (0)
+
+(options, files) = getopt.getopt(sys.argv[1:], 'h', [
+ 'changelog=', 'footer=', 'header=', 'help', 'index=',
+ 'name=', 'version='])
for opt in options:
- o = opt[0]
- a = opt[1]
- if o == '--news':
- news_file = a
- elif o == '--index':
- index_file = a
- elif o == '-h' or o == '--help':
- help ()
- elif o == '-p' or o == '--package':
- topdir = a
-
-sys.path.append (topdir + '/stepmake/bin')
-from packagepython import *
-package = Package (topdir)
-packager = Packager ()
-
-def set_vars():
- os.environ["CONFIGSUFFIX"] = 'www';
- if os.name == 'nt':
- import ntpwd
- pw = ntpwd.getpwname(os.environ['USERNAME'])
- else:
- import pwd
- pw = pwd.getpwuid (os.getuid());
-
- __main__.fullname=pw[4]
-
-set_vars ()
-
-backstr = '\n
Please take me back to the index\n\
-of ' + package.Name + '\n'
-builtstr = '\n
\n\
-This page was built from ' + package.name + '-%s by \n\
-
%s <%s>\n\
-'
-
-def footstr(index):
- s = backstr % index
- s = s + builtstr % (version_tuple_to_str (package.version), fullname,
- packager.mail, packager.mail)
- return s
-
-banner = footstr (index_file)
-banner_id = ''
-
-
-if news_file:
- news = gulp_file (news_file)
- i = regex.search ('^\*\*', news)
- news = news[:i]
-
-def check_tag (tag, sub, s, bottom):
- tag = lower (tag)
- TAG = upper (tag)
- s = regsub.sub (tag, TAG, s)
- i = regex.search (TAG, s)
- if i < 0:
- if bottom:
- s = s + sub + '\n'
+ o = opt[0]
+ a = opt[1]
+ if o == '--changelog':
+ changelog_file = a
+ elif o == '--footer':
+ footer_file = a
+ elif o == '--header':
+ header_file = a
+ elif o == '-h' or o == '--help':
+ help ()
+ # urg, this is top!
+ elif o == '--index':
+ index_url = a
+ elif o == '--name':
+ package_name = a
+ elif o == '--version':
+ package_version = a
else:
- s = sub + '\n' + s
- return s
-
-for f in files:
- s = gulp_file (f)
-
- if news_file:
- s = regsub.sub ('top_of_NEWS', '\n'+ news + '\n\n', s)
-
- s = check_tag ('', '', s)
- if regex.search (banner_id, s) == -1:
- s = regsub.sub ('', '', s)
- s = regsub.sub (''
+ s = re.sub ('(?i)', body, s)
+ if re.search ('(?i)]*>', body + header, s, 1)
+ elif re.search ('(?i)', '' + header, s, 1)
+ else:
+ s = header + s
+
+ s = header_tag + '\n' + s
+
+ if re.search ('(?i)\n'
+ s = doctype + s
+
+ if re.search (footer_tag, s) == None:
+ s = s + footer_tag + '\n'
+
+ if re.search ('(?i)', footer + '', s, 1)
+ elif re.search ('(?i)', footer + '', s, 1)
+ else:
+ s = s + footer
+
+ #URUGRGOUSNGUOUNRIU
+ index = index_url
+ top = top_url
+ if os.path.basename (f) == "index.html":
+ cwd = os.getcwd ()
+ if os.path.basename (cwd) == "topdocs":
+ index = "index.html"
+ top = ""
+
+ # don't cause ///////index.html entries in log files.
+ # index = "./index.html"
+ # top = "./"
+
+ s = re.sub ('@INDEX@', index, s)
+ s = re.sub ('@TOP@', top, s)
+ s = re.sub ('@PACKAGE_NAME@', package_name, s)
+ s = re.sub ('@PACKAGE_VERSION@', package_version, s)
+ s = re.sub ('@WEBMASTER@', webmaster, s)
+ s = re.sub ('@GCOS@', gcos, s)
+ s = re.sub ('@LOCALTIME@', localtime, s)
+ s = re.sub ('@MAILADDRESS@', mail_address, s)
+
+ m = re.match ('.*?', s, re.DOTALL)
+ while m:
+ at_var = m.group (1)
+ at_val = m.group (2)
+ #sys.stderr.write ('at: %s -> %s\n' % (at_var, at_val))
+ s = re.sub (at_var, at_val, s)
+ m = re.match ('.*?', s, re.DOTALL)
+
+ # urg
+ # maybe find first node?
+ fallback_web_title = '-- --'
+ m = re.match ('.*?\(.*?\)', s, re.DOTALL)
+ if m:
+ fallback_web_title = m.group (1)
+ s = re.sub ('@WEB-TITLE@', fallback_web_title, s)
+
+ s = remove_self_ref (s)
+
+ open (f, 'w').write (s)
- dump_file (f, s)
+for f in files:
+ do_file (f)
', banner_id + banner + '', s)
- else:
- s = check_tag ('', '', s, 1)
-
- title = '
' \
- + package.Name + ' -- ' + os.path.basename (os.path.splitext(f)[0]) \
- + ''
- s = check_tag ('
', title, s, 0)
-
- s = check_tag ('', '', s, 0)
- s = check_tag ('', '', s, 1)
-
- #urg
- if regex.search ('@COUNTER_REF@', s) != -1:
- counter = ''
- try:
- counter = os.environ[package.NAME + '_COUNTERPATH']
- counter = '
\n'
- except:
- pass
- s = regsub.gsub ('@COUNTER_REF@', counter, s)
+ raise 'unknown opt ', o
+
+#burp?
+def set_gcos ():
+ global gcos
+ os.environ["CONFIGSUFFIX"] = 'www';
+ if os.name == 'nt':
+ import ntpwd
+ pw = ntpwd.getpwname(os.environ['USERNAME'])
+ else:
+ import pwd
+ if os.environ.has_key('FAKEROOTKEY'):
+ pw = pwd.getpwnam (os.environ['LOGNAME'])
+ else:
+ pw = pwd.getpwuid (os.getuid())
+
+ f = pw[4]
+ f = string.split (f, ',')[0]
+ gcos = f
+
+def compose (default, file):
+ s = default
+ if file:
+ s = gulp_file (file)
+ return s
+
+set_gcos ()
+localtime = time.strftime ('%c %Z', time.localtime (time.time ()))
+
+if os.path.basename (index_url) != "index.html":
+ index_url = os.path.join (index_url , "index.html")
+top_url = os.path.dirname (index_url) + "/"
+
+header = compose (default_header, header_file)
+footer = compose (default_footer, footer_file) + built
+header_tag = ''
+footer_tag = ''
+
+# Python < 1.5.2 compatibility
+#
+# On most platforms, this is equivalent to
+#`normpath(join(os.getcwd()), PATH)'. *Added in Python version 1.5.2*
+if os.path.__dict__.has_key ('abspath'):
+ abspath = os.path.abspath
+else:
+ def abspath (path):
+ return os.path.normpath (os.path.join (os.getcwd (), path))
+
+
+def remove_self_ref (s):
+ self_url = abspath (os.getcwd () + '/' + f)
+ #sys.stderr.write ('url0: %s\n' % self_url)
+ self_url = re.sub ('.*' + string.lower (package_name) + '[^/]*/',
+ '', self_url)
+ #sys.stderr.write ('url1: %s\n' % self_url)
+
+ #urg, ugly lily-specific toplevel index hack
+ self_url = re.sub ('.*topdocs/out-www/index.html', 'index.html', self_url)
+ #sys.stderr.write ('url2: %s\n' % self_url)
+
+ m = re.match ('.*?()([^<]*)()',
+ s, re.DOTALL)
+ while m:
+ #sys.stderr.write ('self: %s\n' % m.group (2))
+ s = s[:m.start (1)] + m.group (2) + s[m.end (3):]
+ m = re.match ('.*?()([^<]*)()',
+ s, re.DOTALL)
+ return s
+
+def do_file (f):
+ s = gulp_file (f)
+
+ if changelog_file:
+ changes = gulp_file (changelog_file)
+ # urg?
+ #m = re.search ('^\\\\*\\\\*', changes)
+ m = re.search (r'\*\*\*', changes)
+ if m:
+ changes = changes[:m.start (0)]
+ s = re.sub ('top_of_ChangeLog', '\n'+ changes + '\n
\n', s)
+
+ if re.search (header_tag, s) == None:
+ body = '