]> git.donarmstrong.com Git - lilypond.git/blob - bin/make-website.in
release: 0.1.53
[lilypond.git] / bin / make-website.in
1 #!@PYTHON@
2 # -*-python-*-
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
9
10 """ 
11  stupid script to generate WWW site.  
12
13  The WWW site is my test-suite for LilyPond, I usually don't
14  distribute versions that fail to complete this script 
15
16 You should set the following environment vars:
17
18 LILYPOND_SOURCEDIR
19 TEXINPUTS
20 MAILADDRESS
21
22
23  """
24
25 import sys
26 import os
27
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)
34
35 lilypath = lilypath + '/bin/'
36 sys.path.append(lilypath)
37  
38 from lilypython import *
39 import __main__
40 import glob
41
42 depth = ''
43 makewebsite_id = "<!make_website!>";
44 id_str = "make-website 0.9";
45 tar = "tar";
46 make = "make -f Makefile";
47 mailaddress = "unknown"
48 fullname = "unknown"
49 footstr = ""
50 lilyversion= ''
51
52 include_path=[ 'input', 'mutopia' , 'mutopia/J.S.Bach', 
53                'mutopia/J.S.Bach/out' ]
54
55 def set_vars():
56     __main__.lilyversion =  version_tuple_to_str(lilydirs.version_tuple())
57     os.environ["TEXINPUTS"] = os.environ["TEXINPUTS"] + ":%s/input/:" % depth;
58     
59     os.environ["LILYINCLUDE"] = join (':', __main__.include_path) +':'+ os.environ["LILYINCLUDE"];
60     os.environ["LILYTOP"] = depth;
61     __main__.mailaddress= os.environ['MAILADDRESS']
62     pw = pwd.getpwuid (os.getuid());
63
64     __main__.fullname= pw[4];
65
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>' 
72
73     
74 def footstr(index):
75      return backstr % (index, id_str, lilyversion, fullname, mailaddress, mailaddress)
76
77     
78
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:]
86         
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)
94
95 base="lilypond/";
96
97 examples=["twinkle-pop", 
98           "praeludium-fuga-E", 
99           "cadenza", 
100           "twinkle", 
101           "collisions",
102           "font16",
103           "font20",
104           #"scales", 
105           "rhythm", 
106           "multi"]
107
108 mutopia_examples = [ "wtk1-fugue2",
109                      "standje",
110                      "preludes-1",
111                      "preludes-2",
112                      "wtk1-prelude1",
113                      "gallina",   
114                      "scsii-menuetto"]
115
116
117 def gen_html():
118     print 'generating HTML'
119     my_system (["make -f Makefile -kC .. html"]);
120     
121
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)])
138
139     return outputs
140
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');
150
151     for ex in inputs:
152         print '%s, ' % ex
153         header  = read_mudela_header(ex + '.ly.txt')
154         
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))
174             
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>");
184
185     list.write( "</BODY></HTML>");
186     list.close()
187
188 texstuff = ["mudela-man", "mudela-course"]
189
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 ()
202
203     my_system (['make -C .. ' + todo])
204
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"
214     
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"]);
221     
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/make-docxx' % depth]);
228 #    os.unlink( "/tmp/lilybanner.html");
229
230 def get_glob(exts):
231     result = []
232     for a in exts:
233         result = result + glob.glob1('./', '*.' + a)
234
235     return result
236
237 def join(inter, list):
238     return reduce (lambda x,y, i=inter: x + i + y, list)
239
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/*'])
246
247
248 def identify():
249     print 'This is %s\n' % id_str
250     
251 def clean_tmp():
252     my_system(['-rm -f /tmp/gs*'])
253     
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
264
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)
269
270 def edit_html():
271     files = get_glob(['html'])
272     for f in files:
273
274         s = gulp_file(f)
275         if regex.search(makewebsite_id, s) <> -1:
276             continue;
277
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)
281
282         dump_file (f,s)
283
284
285 def do_examples (examples, filename):
286     located_files = gen_examples (examples)
287     gen_list (examples, filename)
288 def main():
289     identify();
290
291     os.chdir (lilydirs.topdir + 'WWW')
292     
293     my_system (['-rm ../WWW/*.pod ../WWW/*.xpm ../WWW/*.doc',
294                 'ln ../Documentation/*.pod ../Documentation/*.doc ../Documentation/*.xpm .']);
295     os.chdir (lilydirs.topdir + 'WWW/out')
296     __main__.depth = "../../";
297     __main__.include_path = map(lambda p: __main__.depth + '/' + 
298                                 p, __main__.include_path)
299
300     set_vars();
301     gen_html();
302     copy_files();
303     do_examples (examples, 'examples_output.html');
304     do_examples (mutopia_examples, 'mutopiaexamples_output.html');
305     gen_manuals();
306     #set_images();
307     edit_html();
308     edit_index();
309     docxx_update()
310     do_tar()
311     clean_tmp();
312
313
314 main()
315
316