]> git.donarmstrong.com Git - lilypond.git/blob - stepmake/bin/add-html-footer.py
1eb654a68588e5115837a561a9ec65195ea1e8d2
[lilypond.git] / stepmake / bin / add-html-footer.py
1 #!@PYTHON@
2
3 """
4 Print a nice footer.  add the top of the ChangeLog 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 changelog_file = ''
19
20 index_file=''
21 banner_file = ''
22 changelog_file=''
23 changes =''
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:], 'c:hp:', ['changelog=', 'help', 'news=', 'index=', 'package=']) 
31
32 def gulp_file(f):
33         try:
34                 i = open(f)
35                 i.seek (0, 2)
36                 n = i.tell ()
37                 i.seek (0,0)
38         except:
39                 sys.stderr.write ("can't open file: %s\n" % f)
40                 return ''
41         s = i.read (n)
42         if len (s) <= 0:
43                 sys.stderr.write ("gulped emty file: %s\n" % f)
44         i.close ()
45         return s
46
47 def help ():
48     sys.stdout.write (r"""Usage: add-html-footer [OPTION]... HTML-FILE
49 Add a nice footer, add the top of the ChangLog file (up to the ********)
50 Options:
51   -h, --help             print this help
52   -p, --package          package name (ugh. Junkme.)
53   """)
54     sys.exit (0)
55
56 for opt in options:
57     o = opt[0]
58     a = opt[1]
59     if o == '--news' or o == '--changelog' or o == '-c':
60         changelog_file = a
61     elif o == '--index':
62         index_file = a
63     elif o == '-h' or o == '--help':
64         help ()
65     elif o == '-p' or o == '--package':
66         topdir = a
67
68 sys.path.append (topdir + '/stepmake/bin')
69 from packagepython import *
70 package = Package (topdir)
71 packager = Packager ()
72
73 if package.NAME == 'LILYPOND':
74     package.Name = 'GNU LilyPond'
75
76 def set_vars():
77     os.environ["CONFIGSUFFIX"] = 'www';
78     if os.name == 'nt':
79         import ntpwd
80         pw = ntpwd.getpwname(os.environ['USERNAME'])
81     else:
82         import pwd
83         pw = pwd.getpwuid (os.getuid());
84
85     __main__.fullname=pw[4]
86
87 set_vars ()
88
89 def footstr(index):
90     try:
91         footer = gulp_file (package.topdir + '/Documentation/footer.html.in')
92     except:
93         pass
94     s = footer % (index, package.Name, packager.webmaster, packager.webmaster)
95     s = s + builtstr % (package.Name, 
96                         version_tuple_to_str (package.version), fullname,
97                         packager.mail, packager.mail, 
98                         time.strftime ('%c %Z', time.localtime (time.time ())))
99     return s
100
101 banner = footstr (index_file)
102 banner_id = '<! banner_id >'
103
104
105 if changelog_file:
106     changes = gulp_file (changelog_file)
107     i = regex.search ('^\*\*', changes)
108     changes = changes[:i]
109     
110 def check_tag (tag, sub, s, bottom):
111     tag = string.lower (tag)
112     TAG = string.upper (tag)
113     s = regsub.sub (tag, TAG, s)
114     i = regex.search (TAG, s)
115     if i < 0:
116         if bottom:
117             s = s + sub + '\n'
118         else:
119             s = sub + '\n' + s
120     return s
121     
122 for f in files:
123     s = gulp_file (f)
124
125     if changelog_file:
126         s = regsub.sub ('top_of_ChangeLog', '<XMP>\n'+ changes  + '\n</XMP>\n', s)
127
128     s = check_tag ('<body', '', s, 0)
129     if regex.search ('<BODY', s) == -1:
130         s = '<BODY>\n' + s
131     s = regsub.sub ('<BODY>', '<BODY BGCOLOR=WHITE><FONT COLOR=BLACK>', s)
132     if regex.search (banner_id, s) == -1:
133         s = regsub.sub ('</body>', '</BODY>', s)
134         s = regsub.sub ('</BODY>', banner_id  + banner + '</BODY>', s)
135     else:
136         s = check_tag ('</body>', '</BODY>', s, 1)
137
138     title = '<HEAD><TITLE>' \
139         + package.Name + ' -- ' + os.path.basename (os.path.splitext(f)[0]) \
140         + '</TITLE></HEAD>'
141     s = check_tag ('<title>', title, s, 0)
142
143     s = check_tag ('<html', '', s, 0)
144     if regex.search ('<HTML', s) == -1:
145         s = '<HTML>\n' + s
146     s = check_tag ('</html>', '</HTML>', s, 1)
147
148     dump_file (f, s)
149
150