]> git.donarmstrong.com Git - lilypond.git/blob - stepmake/bin/add-html-footer.py
release: 1.2.5
[lilypond.git] / stepmake / bin / add-html-footer.py
1 #!@PYTHON@
2
3 """
4 Print a nice footer.  add the top of the NEWS file (up to the ********)
5 """
6
7 program_name = 'add-html-footer'
8 version = '0.1'
9
10 import sys
11 import os
12 import time
13 import string 
14 import getopt
15 import __main__
16
17 fullname = "unknown"
18 news_file = ''
19
20 index_file=''
21 banner_file = ''
22 news_file=''
23 news =''
24 footer = '\n<hr>Please take me <a href=%s>back to the index</a>\n\
25 of %s<!%s%s>\n'
26 builtstr = '\n<hr><font size=-1>\n\
27 This page was built from %s-%s by\
28 <address><br>%s &lt<a href=mailto:%s>%s</a>&gt, at %s.</address><p></font>' 
29
30 (options, files) = getopt.getopt(sys.argv[1:], 'hp:', ['help', 'news=', 'index=', 'package=']) 
31
32 def gulp_file (fn):
33         f = open (fn)
34         return f.read ()
35
36 def help ():
37     sys.stdout.write (r"""Usage: add-html-footer [OPTION]... HTML-FILE
38 Add a nice footer, add the top of the NEWS file (up to the ********)
39 Options:
40   -h, --help             print this help
41   -p, --package          package name (ugh. Junkme.)
42   """)
43     sys.exit (0)
44
45 for opt in options:
46     o = opt[0]
47     a = opt[1]
48     if o == '--news':
49         news_file = a
50     elif o == '--index':
51         index_file = a
52     elif o == '-h' or o == '--help':
53         help ()
54     elif o == '-p' or o == '--package':
55         topdir = a
56
57 sys.path.append (topdir + '/stepmake/bin')
58 from packagepython import *
59 package = Package (topdir)
60 packager = Packager ()
61
62 if package.NAME == 'LILYPOND':
63     package.Name = 'GNU LilyPond'
64
65 def set_vars():
66     os.environ["CONFIGSUFFIX"] = 'www';
67     if os.name == 'nt':
68         import ntpwd
69         pw = ntpwd.getpwname(os.environ['USERNAME'])
70     else:
71         import pwd
72         pw = pwd.getpwuid (os.getuid());
73
74     __main__.fullname=pw[4]
75
76 set_vars ()
77
78 def footstr(index):
79     try:
80         footer = gulp_file (package.topdir + '/Documentation/footer.html.in')
81     except:
82         pass
83     s = footer % (index, package.Name, packager.webmaster, packager.webmaster)
84     s = s + builtstr % (package.Name, 
85                         version_tuple_to_str (package.version), fullname,
86                         packager.mail, packager.mail, 
87                         time.strftime ('%c %Z', time.localtime (time.time ())))
88     return s
89
90 banner = footstr (index_file)
91 banner_id = '<! banner_id >'
92
93
94 if news_file:
95     news = gulp_file (news_file)
96     i = regex.search ('^\*\*', news)
97     news = news[:i]
98     
99 def check_tag (tag, sub, s, bottom):
100     tag = string.lower (tag)
101     TAG = string.upper (tag)
102     s = regsub.sub (tag, TAG, s)
103     i = regex.search (TAG, s)
104     if i < 0:
105         if bottom:
106             s = s + sub + '\n'
107         else:
108             s = sub + '\n' + s
109     return s
110     
111 for f in files:
112     s = gulp_file (f)
113
114     if news_file:
115         s = regsub.sub ('top_of_NEWS', '<XMP>\n'+ news  + '\n</XMP>\n', s)
116
117     s = check_tag ('<body', '', s, 0)
118     if regex.search ('<BODY', s) == -1:
119         s = '<BODY>\n' + s
120     s = regsub.sub ('<BODY>', '<BODY BGCOLOR=WHITE><FONT COLOR=BLACK>', s)
121     if regex.search (banner_id, s) == -1:
122         s = regsub.sub ('</body>', '</BODY>', s)
123         s = regsub.sub ('</BODY>', banner_id  + banner + '</BODY>', s)
124     else:
125         s = check_tag ('</body>', '</BODY>', s, 1)
126
127     title = '<HEAD><TITLE>' \
128         + package.Name + ' -- ' + os.path.basename (os.path.splitext(f)[0]) \
129         + '</TITLE></HEAD>'
130     s = check_tag ('<title>', title, s, 0)
131
132     s = check_tag ('<html', '', s, 0)
133     if regex.search ('<HTML', s) == -1:
134         s = '<HTML>\n' + s
135     s = check_tag ('</html>', '</HTML>', s, 1)
136
137     dump_file (f, s)
138
139