]> git.donarmstrong.com Git - lilypond.git/blob - bin/make-website.in
release: 0.1.54
[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', 'mutopia/Coriolan',
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           "coriolan",
107           "multi"]
108
109 mutopia_examples = [ "wtk1-fugue2",
110                      "standje",
111                      "preludes-1",
112                      "preludes-2",
113                      
114                      "wtk1-prelude1",
115                      "gallina",   
116                      "scsii-menuetto"]
117
118
119 def gen_html():
120     print 'generating HTML'
121     my_system (["make -f Makefile -kC .. html"]);
122     
123
124 def gen_examples(inputs):
125     print 'generating examples:\n'
126     outputs = []
127     for i in inputs:
128         try:
129                 located = multiple_find ([i + '.ly'], include_path) [0]
130         except IndexError:
131                 print 'continuing dazed & confused (%s) ' % i
132                 continue
133         outputs.append (located)
134         if not file_exist_b(i + '.dvi'):
135             my_system (['ly2dvi %s' % located])
136         if not file_exist_b(i + '.ly.txt'):
137             os.link (located, i + ".ly.txt")
138     list = map(lambda x: 'out/%s.ps.gz out/%s.gif' % (x,x), inputs)
139     my_system (['make -C .. ' + join(' ', list)])
140
141     return outputs
142
143 def gen_list(inputs, filename):
144     print "generating HTML list %s\n" % filename;
145     list = open(filename, 'w')
146     list.write ('<html><TITLE>Rendered Examples</TITLE>\n'
147      '<body>These example files are taken from the LilyPond distribution.\n'
148      'LilyPond currently only outputs TeX and MIDI. The pictures and\n'
149      'PostScript files were generated using TeX, Ghostscript and some\n'
150      'graphics tools.  The papersize used for these examples is A4.  The GIF\n'
151      'files have been scaled to eliminate aliasing.\n');
152
153     for ex in inputs:
154         print '%s, ' % ex
155         header  = read_mudela_header(ex + '.ly.txt')
156         
157         def read_dict(s, default, h =header):
158                 try:
159                     ret = h[s]
160                 except KeyError:
161                     ret = default
162                 return ret
163         head = read_dict('title', ex)
164         composer = read_dict('composer', '')
165         desc = read_dict('description', '')
166         list.write('<hr>')
167         list.write('<h1>example file: %s</h1>' % head);
168         if composer <> '':
169             list.write('<h2>%s</h2>\n' % composer)
170         if desc <> '':
171             list.write('%s<p>' % desc)
172         list.write ('<ul>')
173         def list_item(filename, desc, l = list):
174             if file_exist_b(filename):
175                 l.write ('<li><a href=%s>%s</a>\n' % (filename, desc))
176             
177         list_item(ex + '.ly.txt', 'The input')
178         for pageno in range(1,10):
179             f  = ex + '-page%d.gif' % pageno
180             if not file_exist_b (f):
181                 break
182             list_item(f, 'The output (picture, page %d)' % pageno)
183         list_item(ex + '.ps.gz', 'The output (gzipped PostScript)')
184         list_item(ex + '.midi', 'The output (MIDI)')
185         list.write ("</ul>");
186
187     list.write( "</BODY></HTML>");
188     list.close()
189
190 texstuff = ["mudela-man", "mudela-course"]
191
192 def gen_manuals():
193     print 'generating TeX doco manuals'
194     list = open('tex_manuals.html', 'w')
195     list.write( "<HTML><TITLE>PostScript Manuals</TITLE>\n" 
196      "<BODY><h1>LilyPond manuals (in PostScript)</h1>"
197      "<ul>\n")
198     todo='' 
199     for stuff in texstuff:
200         todo = todo + ' out/' + stuff + '.ps.gz'
201         list.write("<li><a href=%s.ps.gz>%s.ps.gz</a>" % (stuff, stuff))
202     list.write('</ul></BODY></HTML>')
203     list.close ()
204
205     my_system (['make -C .. ' + todo])
206
207 def file_exist_b(name):
208     try: 
209         f = open(name)
210     except IOError:
211         return 0
212     f.close ()
213     return 1
214 def copy_files():
215     print "copying files\n"
216     
217 #    my_system ("ln -s depth/out ./docxx" )
218     my_system([ "cp %s/TODO ./TODO.txt" % depth,
219     "cp %s/ANNOUNCE-0.1 ./ANNOUNCE-0.1.txt" % depth,
220     "cp %s/NEWS ./NEWS.txt" % depth,
221     "cp %s/DEDICATION ./DEDICATION.txt" % depth]);
222     my_system([ "make -C .. gifs"]);
223     
224 def docxx_update():
225     print 'docxx.. \n'
226     banner= open('/tmp/lilybanner.html', 'w');
227     banner.write (footstr('../index.html'))
228     banner.close ()
229     my_system(['BANNEROPT=\"-B /tmp/lilybanner.html\" %s/bin/make-docxx' % depth]);
230 #    os.unlink( "/tmp/lilybanner.html");
231
232 def get_glob(exts):
233     result = []
234     for a in exts:
235         result = result + glob.glob1('./', '*.' + a)
236
237     return result
238
239 def join(inter, list):
240     return reduce (lambda x,y, i=inter: x + i + y, list)
241
242 def do_tar():
243      print "tarring.\n";
244      list = get_glob( ['html', 'gif', 'ps.gz' , 'txt', 'midi']) 
245      files = join (' ', list)
246      print files
247      my_system( ['-tar zvhcf website.tar.gz ' + files + ' docxx/*'])
248
249
250 def identify():
251     print 'This is %s\n' % id_str
252     
253 def clean_tmp():
254     my_system(['-rm -f /tmp/gs*'])
255     
256 def get_top_of_NEWS():
257     i = open('NEWS.txt')
258     lines = i.readlines()
259     i.close ()
260     s = ''
261     for l in lines:
262         if regex.search('^\*\*\*\*\*\*', l) <> -1:
263             return s;
264         s = s + l
265     return s
266
267 def edit_index():
268     s = gulp_file('index.html')
269     s = regsub.sub ('top_of_NEWS', '<XMP>\n' + get_top_of_NEWS () + '\n</XMP>', s)
270     dump_file ('index.html', s)
271
272 def edit_html():
273     files = get_glob(['html'])
274     for f in files:
275
276         s = gulp_file(f)
277         if regex.search(makewebsite_id, s) <> -1:
278             continue;
279
280         s = regsub.sub ('</BODY>', footstr('index.html') + makewebsite_id + '</BODY>', s)
281         s = regsub.sub('<TITLE>\(.*\)</TITLE>$', 
282                        '<TITLE>LilyPond WWW: \\1</TITLE>', s)
283
284         dump_file (f,s)
285
286
287 def do_examples (examples, filename):
288     located_files = gen_examples (examples)
289     gen_list (examples, filename)
290 def main():
291     identify();
292
293     os.chdir (lilydirs.topdir + 'WWW')
294     
295     my_system (['-rm ../WWW/*.pod ../WWW/*.xpm ../WWW/*.doc',
296                 'ln ../Documentation/*.pod ../Documentation/*.doc ../Documentation/*.xpm .']);
297     os.chdir (lilydirs.topdir + 'WWW/out')
298     __main__.depth = "../../";
299     __main__.include_path = map(lambda p: __main__.depth + '/' + 
300                                 p, __main__.include_path)
301
302     set_vars();
303     gen_html();
304     copy_files();
305     do_examples (examples, 'examples_output.html');
306     do_examples (mutopia_examples, 'mutopiaexamples_output.html');
307     gen_manuals();
308     #set_images();
309     edit_html();
310     edit_index();
311     docxx_update()
312     do_tar()
313     clean_tmp();
314
315
316 main()
317
318