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