lilypond-0.1.47
[lilypond.git] / bin / make-website.py
bloba2243a78f913e0e884e98bfa06cdcf80e1f8c7ca
1 #!@PYTHON@
2 #
3 # make-website.py -- implement The lilypond WWW site
4 #
5 # source file of the GNU LilyPond music typesetter
6 #
7 # (c) 1997, 1998 Han-Wen Nienhuys <hanwen@stack.nl>
8 #
10 """
11 stupid script to generate WWW site.
13 The WWW site is my test-suite for LilyPond, I usually don't
14 distribute versions that fail to complete this script
16 You should set the following environment vars:
18 LILYPOND_SOURCEDIR
19 TEXINPUTS
20 MAILADDRESS
23 """
25 import sys
26 import os
28 lilypath =''
29 try:
30 lilypath = os.environ['LILYPOND_SOURCEDIR'] + '/'
31 except KeyError:
32 print 'Please set LILYPOND_SOURCEDIR to the toplevel source, eg LILYPOND_SOURCEDIR=/home/foobar/lilypond-1.2.3/'
33 sys.exit(1)
35 lilypath = lilypath + '/bin/'
36 sys.path.append(lilypath)
38 from lilypython import *
39 import __main__
40 import glob
42 depth = ''
43 makewebsite_id = "<!make_website!>";
44 id_str = "make-website 0.8";
45 tar = "tar";
46 make = "make";
47 mailaddress = "unknown"
48 fullname = "unknown"
49 footstr = ""
50 lilyversion= ''
52 include_path=[ 'input', 'mutopia' , 'mutopia/J.S.Bach',
53 'mutopia/J.S.Bach/out' ]
55 def set_vars():
56 __main__.lilyversion = version_tuple_to_str(lilydirs.version_tuple())
57 os.environ["TEXINPUTS"] = os.environ["TEXINPUTS"] + ":%s/input/:" % depth;
59 os.environ["LILYINCLUDE"] = join (':', __main__.include_path)
60 os.environ["LILYTOP"] = depth;
61 __main__.mailaddress= os.environ['MAILADDRESS']
62 pw = pwd.getpwuid (os.getuid());
64 __main__.fullname= pw[4];
66 backstr = '\n<hr>Please take me <a href=%s>back to the index</a>\n\
67 of LilyPond -- The GNU Project Music typesetter\n\
68 <hr><font size=-1>\n\
69 This page was built using <code>%s</code> from lilypond-%s by <p>\n\
70 <address><br>%s <a href=mailto:%s>&lt<!bla>%s</a>&gt</address>\n\
71 <p></font>'
74 def footstr(index):
75 return backstr % (index, id_str, lilyversion, fullname, mailaddress, mailaddress)
79 # do something, check return status
80 def my_system(cmds):
81 for cmd in cmds:
82 ignoreret=0;
83 if cmd[0] == '-':
84 ignoreret = 1
85 cmd = cmd[1:]
87 ret = os.system (cmd)
88 if ret:
89 if ignoreret:
90 sys.stderr.write( "ignoring failed command \`%s\' (status %d)\n" % (cmd, ret))
91 else:
92 sys.stderr.write( 'make-website: failed on command %s (status %d)\n' % (cmd, ret))
93 sys.exit (2)
95 base="lilypond/";
97 examples=["twinkle-pop",
98 "praeludium-fuga-E",
99 "cadenza",
100 "twinkle",
101 "collisions",
102 "font16",
103 "font20",
104 #"scales",
105 "rhythm",
106 "multi"]
108 mutopia_examples = [ "wtk1-fugue2",
109 "standje",
110 "preludes-1",
111 "preludes-2",
112 "wtk1-prelude1",
113 "gallina",
114 "scsii-menuetto"]
117 def gen_html():
118 print 'generating HTML'
119 my_system (["make -kC .. html"]);
122 def gen_examples(inputs):
123 print 'generating examples:\n'
124 outputs = []
125 for i in inputs:
126 try:
127 located = multiple_find ([i + '.ly'], include_path) [0]
128 except IndexError:
129 print 'continuing dazed & confused (%s) ' % i
130 continue
131 outputs.append (located)
132 if not file_exist_b(i + '.dvi'):
133 my_system (['ly2dvi %s' % located])
134 if not file_exist_b(i + '.ly.txt'):
135 os.link (located, i + ".ly.txt")
136 list = map(lambda x: 'out/%s.ps.gz out/%s.gif' % (x,x), inputs)
137 my_system (['make -C .. ' + join(' ', list)])
139 return outputs
141 def gen_list(inputs, filename):
142 print "generating HTML list %s\n" % filename;
143 list = open(filename, 'w')
144 list.write ('<html><TITLE>Rendered Examples</TITLE>\n'
145 '<body>These example files are taken from the LilyPond distribution.\n'
146 'LilyPond currently only outputs TeX and MIDI. The pictures and\n'
147 'PostScript files were generated using TeX, Ghostscript and some\n'
148 'graphics tools. The papersize used for these examples is A4. The GIF\n'
149 'files have been scaled to eliminate aliasing.\n');
151 for ex in inputs:
152 print '%s, ' % ex
153 header = read_mudela_header(ex + '.ly.txt')
155 def read_dict(s, default, h =header):
156 try:
157 ret = h[s]
158 except KeyError:
159 ret = default
160 return ret
161 head = read_dict('title', ex)
162 composer = read_dict('composer', '')
163 desc = read_dict('description', '')
164 list.write('<hr>')
165 list.write('<h1>example file: %s</h1>' % head);
166 if composer <> '':
167 list.write('<h2>%s</h2>\n' % composer)
168 if desc <> '':
169 list.write('%s<p>' % desc)
170 list.write ('<ul>')
171 def list_item(filename, desc, l = list):
172 if file_exist_b(filename):
173 l.write ('<li><a href=%s>%s</a>\n' % (filename, desc))
175 list_item(ex + '.ly.txt', 'The input')
176 for pageno in range(1,10):
177 f = ex + '-page%d.gif' % pageno
178 if not file_exist_b (f):
179 break
180 list_item(f, 'The output (picture, page %d)' % pageno)
181 list_item(ex + '.ps.gz', 'The output (gzipped PostScript)')
182 list_item(ex + '.midi', 'The output (MIDI)')
183 list.write ("</ul>");
185 list.write( "</BODY></HTML>");
186 list.close()
188 texstuff = ["mudela-man", "mudela-course"]
190 def gen_manuals():
191 print 'generating TeX doco manuals'
192 list = open('tex_manuals.html', 'w')
193 list.write( "<HTML><TITLE>PostScript Manuals</TITLE>\n"
194 "<BODY><h1>LilyPond manuals (in PostScript)</h1>"
195 "<ul>\n")
196 todo=''
197 for stuff in texstuff:
198 todo = todo + ' out/' + stuff + '.ps.gz'
199 list.write("<li><a href=%s.ps.gz>%s.ps.gz</a>" % (stuff, stuff))
200 list.write('</ul></BODY></HTML>')
201 list.close ()
203 my_system (['make -C .. ' + todo])
205 def file_exist_b(name):
206 try:
207 f = open(name)
208 except IOError:
209 return 0
210 f.close ()
211 return 1
212 def copy_files():
213 print "copying files\n"
215 # my_system ("ln -s depth/out ./docxx" )
216 my_system([ "cp %s/TODO ./TODO.txt" % depth,
217 "cp %s/ANNOUNCE-0.1 ./ANNOUNCE.txt" % depth,
218 "cp %s/NEWS ./NEWS.txt" % depth,
219 "cp %s/DEDICATION ./DEDICATION.txt" % depth]);
220 my_system([ "make -C .. gifs"]);
222 def docxx_update():
223 print 'docxx.. \n'
224 banner= open('/tmp/lilybanner.html', 'w');
225 banner.write (footstr('../index.html'))
226 banner.close ()
227 my_system(['BANNEROPT=\"-B /tmp/lilybanner.html\" %s/bin/out/make-docxx' % depth]);
228 # os.unlink( "/tmp/lilybanner.html");
230 def get_glob(exts):
231 result = []
232 for a in exts:
233 result = result + glob.glob1('./', '*.' + a)
235 return result
237 def join(inter, list):
238 return reduce (lambda x,y, i=inter: x + i + y, list)
240 def do_tar():
241 print "tarring.\n";
242 list = get_glob( ['html', 'gif', 'ps.gz' , 'txt', 'midi'])
243 files = join (' ', list)
244 print files
245 my_system( ['-tar zvhcf website.tar.gz ' + files + ' docxx/*'])
248 def identify():
249 print 'This is %s\n' % id_str
251 def clean_tmp():
252 my_system(['rm -f /tmp/gs*'])
254 def get_top_of_NEWS():
255 i = open('NEWS.txt')
256 lines = i.readlines()
257 i.close ()
258 s = ''
259 for l in lines:
260 if regex.search('^\*\*\*\*\*\*', l) <> -1:
261 return s;
262 s = s + l
263 return s
265 def edit_index():
266 s = gulp_file('index.html')
267 s = regsub.sub ('top_of_NEWS', '<XMP>\n' + get_top_of_NEWS () + '\n</XMP>', s)
268 dump_file ('index.html', s)
270 def edit_html():
271 files = get_glob(['html'])
272 for f in files:
274 s = gulp_file(f)
275 if regex.search(makewebsite_id, s) <> -1:
276 continue;
278 s = regsub.sub ('</BODY>', footstr('index.html') + makewebsite_id + '</BODY>', s)
279 s = regsub.sub('<TITLE>\(.*\)</TITLE>$',
280 '<TITLE>LilyPond WWW: \\1</TITLE>', s)
282 dump_file (f,s)
285 def do_examples (examples, filename):
286 located_files = gen_examples (examples)
287 gen_list (examples, filename)
288 def main():
289 identify();
291 os.chdir (lilydirs.topdir + 'Documentation/out')
292 __main__.depth = "../../";
293 __main__.include_path = map(lambda p: __main__.depth + '/' +
294 p, __main__.include_path)
296 set_vars();
297 gen_html();
298 copy_files();
299 do_examples (examples, 'examples_output.html');
300 do_examples (mutopia_examples, 'mutopiaexamples_output.html');
301 gen_manuals();
302 #set_images();
303 edit_html();
304 edit_index();
305 docxx_update()
306 do_tar()
307 clean_tmp();
310 main()