]> git.donarmstrong.com Git - lilypond.git/blob - stepmake/bin/add-html-footer.py
release: 1.3.7
[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 import re
7 import sys
8 import os
9 import time
10 import string 
11 import getopt
12 import __main__
13
14 fullname = "unknown"
15 index_file=''
16 banner_file = ''
17 changelog_file=''
18 changes =''
19 package_version = ''
20
21 mail_address = '(address unknown)'
22 try:
23         mail_address= os.environ['MAILADDRESS']
24 except KeyError:
25         pass
26
27
28 webmaster= mail_address
29 try:
30         webmaster= os.environ['WEBMASTER']
31 except KeyError:
32         pass
33
34
35
36 footer_fn = ''
37 footer = r"""<hr>Please take me <a href=%s>back to the index</a>
38 of %s
39 <!-- package name %s>
40  <!-- webmaster fields. %s %s>
41 """
42
43 builtstr = r"""<hr><font size=-1>
44 This page was built from %s-%s by 
45 <address><br>%s &lt<a href=\"mailto:%s\">%s</a>&gt,  %s.</address><p></font>"""
46
47 package_name = ''
48
49 (options, files) = getopt.getopt(sys.argv[1:], 'c:hp:', [
50         'name=', 'footer=', 'version=',
51         'changelog=', 'help', 'news=', 'index=']) 
52
53 def gulp_file(f):
54         try:
55                 i = open(f)
56                 i.seek (0, 2)
57                 n = i.tell ()
58                 i.seek (0,0)
59         except:
60                 sys.stderr.write ("can't open file: %s\n" % f)
61                 return ''
62         s = i.read (n)
63         if len (s) <= 0:
64                 sys.stderr.write ("gulped empty file: %s\n" % f)
65         i.close ()
66         return s
67
68 def help ():
69         sys.stdout.write (r"""Usage: add-html-footer [OPTION]... HTML-FILE
70 Add a nice footer, add the top of the ChangLog file (up to the ********)
71 Options:
72 -h, --help                print this help
73 --version                 package version
74 --name                    package_name
75 --footer                  footer file
76 """)
77         sys.exit (0)
78
79 for opt in options:
80         o = opt[0]
81         a = opt[1]
82         if o == '--news' or o == '--changelog' or o == '-c':
83                 changelog_file = a
84         elif o == '--index':
85                 index_file = a
86         elif o == '--footer':
87                 footer_fn = a
88         elif o == '--name':
89                 package_name = a
90         elif o == '-h' or o == '--help':
91                 help ()
92         elif o == '--version':
93                 package_version = a
94         else:
95                 raise 'unknown opt ', o
96 def set_vars():
97         os.environ["CONFIGSUFFIX"] = 'www';
98         if os.name == 'nt':
99                 import ntpwd
100                 pw = ntpwd.getpwname(os.environ['USERNAME'])
101         else:
102                 import pwd
103                 pw = pwd.getpwuid (os.getuid());
104
105         f =pw[4]
106         f = string.split (f, ',')[0]
107         __main__.fullname=f 
108 set_vars ()
109
110
111 def footstr(index):
112         ft = __main__.footer
113
114         if footer_fn:
115                 try:
116                         ft = open (footer_fn).read ()
117                 except:
118                         raise 'oops: ' , footer_fn
119
120
121         s = ft % (index, package_name, package_name, webmaster, webmaster)
122         s = s + builtstr % (package_name, package_version, fullname,
123                             mail_address, mail_address, 
124                             time.strftime ('%c %Z', time.localtime (time.time ())))
125         return s
126
127 banner = footstr (index_file)
128 banner_id = '<! banner_id >'
129
130
131
132
133 def do_file (s):
134
135         if changelog_file:
136                 changes = gulp_file (changelog_file)
137                 # urg?
138                 #m = re.search ('^\\\\*\\\\*', changes)
139                 m = re.search (r'\*\*\*', changes)
140                 if m:
141                         changes = changes[:m.start (0)]
142                 s = re.sub ('top_of_ChangeLog', '<XMP>\n'+ changes  + '\n</XMP>\n', s)
143
144
145         if re.search (banner_id, s) == None:
146                 s = banner_id + s
147         else:
148                 return s
149
150         s = re.sub ('(?i)<body>', '<BODY BGCOLOR=WHITE><FONT COLOR=BLACK>', s)
151         # do title.
152         #s = check_tag ('<body', '', s, 0)
153         if re.search ('(?i)</body', s):
154                 s = re.sub ('(?i)</body>', banner + '</BODY>', s)
155         elif re.search ('(?i)</html', s):               
156                 s = re.sub ('(?i)</html>', banner + '</HTML>', s)
157         else:
158                 s = s + banner
159
160         return s
161
162 for f in files:
163         s = gulp_file (f)
164         s = do_file (s)
165         open (f, 'w').write (s)
166
167 if 0:
168         title = '<HEAD><TITLE>' \
169                 + package_name + ' -- ' + os.path.basename (os.path.splitext(f)[0]) \
170                 + '</TITLE></HEAD>'
171         s = check_tag ('<title>', title, s, 0)
172
173         s = check_tag ('<html', '', s, 0)
174         if regex.search ('<HTML', s) == -1:
175                 s = '<HTML>\n' + s
176         s = check_tag ('</html>', '</HTML>', s, 1)
177
178         dump_file (f, s)
179
180