]> git.donarmstrong.com Git - lilypond.git/blob - bin/make-website.py
8604c5c8928fcc074aac9d4066a254915507fd2b
[lilypond.git] / bin / make-website.py
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 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 import sys
17 import os
18
19 lilypath =''
20 try:
21     lilypath = os.environ['LILYPOND_SOURCEDIR'] + '/'
22 except IndexError:
23     lilypath = os.environ['HOME'] + 'musix/current'
24 lilypath = lilypath + '/bin/'
25 sys.path.append(lilypath)
26  
27 from lilypython import *
28 import __main__
29 import glob
30
31 depth = ''
32 makewebsite_id = "<!make_website!>";
33 id_str = "make-website 0.7";
34 tar = "tar";
35 make = "make";
36 mailaddress = "unknown"
37 fullname = "unknown"
38 footstr = ""
39 lilyversion= ''
40
41 def set_vars():
42     __main__.lilyversion =  version_tuple_to_str(lilydirs.version_tuple())
43     os.environ["TEXINPUTS"] = os.environ["TEXINPUTS"] + ":%s/input/:" % depth;
44     os.environ["LILYINCLUDE"] = "%s/input/:%s/mutopia/:%s/mutopia/J.S.Bach" \
45                                 % ((depth, ) *3);
46     os.environ["LILYTOP"] = depth;
47     __main__.mailaddress= os.environ['MAILADDRESS']
48     pw = pwd.getpwuid (os.getuid());
49
50     __main__.fullname= pw[4];
51
52 backstr = '\n<hr>Please take me <a href=%s>back to the index</a>\n\
53 of LilyPond -- The GNU Project Music typesetter\n\
54 <hr><font size=-1>\n\
55 This page was built using <code>%s</code> from lilypond-%s by <p>\n\
56 <address><br>%s <a href=mailto:%s>&lt<!bla>%s</a>&gt</address>\n\
57 <p></font>' 
58
59     
60 def footstr(index):
61      return backstr % (index, id_str, lilyversion, fullname, mailaddress, mailaddress)
62
63     
64
65 # do something, check return status
66 def my_system(cmds):
67     for cmd in cmds:
68         ignoreret=0;
69         if cmd[0] == '-':
70             ignoreret = 1
71             cmd = cmd[1:]
72         
73         ret = os.system (cmd)
74         if ret:
75             if ignoreret: 
76                 sys.stderr.write( "ignoring failed command \`%s\' (status %d)\n" % (cmd, ret))
77             else:
78                 sys.stderr.write( 'make-website: failed on command %s (status %d)\n' % (cmd, ret))
79                 sys.exit (2)
80
81 base="lilypond/";
82
83 examples=["twinkle-pop", 
84           "toccata-fuga-E", 
85           "cadenza", 
86           "twinkle", 
87           "collisions",
88           "font16",
89           "font20",
90           #"scales", 
91           "rhythm", 
92           "multi"]
93
94 mutopia_examples = [ "wtk1-fugue2",
95                      "standchen-16", 
96                      "standchen-20", 
97                      "standje",
98                      "wtk1-prelude1",
99                      "gallina",   
100                      "scsii-menuetto"]
101
102
103 def gen_html():
104     print 'generating HTML'
105     my_system (["make -kC .. html"]);
106     
107
108 def gen_examples(inputs):
109     print 'generating examples:\n'
110     list = map(lambda x: 'out/%s.ps.gz out/%s.gif out/%s.ly.txt' % (x,x,x), inputs)
111     my_system (['make -C .. ' + join(' ', list)])
112
113
114 def gen_list(inputs, filename):
115     print "generating HTML list %s\n" % filename;
116     list = open(filename, 'w')
117     list.write ('<html><TITLE>Rendered Examples</TITLE>\n'
118      '<body>These example files are taken from the LilyPond distribution.\n'
119      'LilyPond currently only outputs TeX and MIDI. The pictures and\n'
120      'PostScript files were generated using TeX, Ghostscript and some\n'
121      'graphics tools.  The papersize used for these examples is A4.  The GIF\n'
122      'files have been scaled to eliminate aliasing.\n');
123
124     for ex in inputs:
125         header  = read_mudela_header(ex + '.ly.txt')
126         def read_dict(s, default, h =header):
127                 try:
128                     ret = h[s]
129                 except KeyError:
130                     ret = default
131                 return ret
132         head = read_dict('title', ex)
133         composer = read_dict('composer', '')
134         desc = read_dict('description', '')
135         list.write('<hr>')
136         list.write('<h1>example file: %s</h1>' % head);
137         if composer <> '':
138             list.write('<h2>%s</h2>\n' % composer)
139         if desc <> '':
140             list.write('%s<p>' % desc)
141         list.write ('<ul>')
142         def list_item(filename, desc, l = list):
143             if file_exist_b(filename):
144                 l.write ('<li><a href=%s>%s</a>\n' % (filename, desc))
145             
146         list_item(ex + '.ly.txt', 'The input')
147         for pageno in range(1,10):
148             f  = ex + '-page%d.gif' % pageno
149             if not file_exist_b (f):
150                 break
151             list_item(f, 'The output (picture, page %d)' % pageno)
152         list_item(ex + '.ps.gz', 'The output (gzipped PostScript)')
153         list_item(ex + '.midi', 'The output (MIDI)')
154         list.write ("</ul>");
155
156     list.write( "</BODY></HTML>");
157     list.close()
158
159 texstuff = ["mudela-man", "mudela-course"]
160
161 def gen_manuals():
162     print 'generating TeX doco manuals'
163     list = open('tex_manuals.html', 'w')
164     list.write( "<HTML><TITLE>PostScript Manuals</TITLE>\n" 
165      "<BODY><h1>LilyPond manuals (in PostScript)</h1>"
166      "<ul>\n")
167     todo='' 
168     for stuff in texstuff:
169         todo = todo + ' out/' + stuff + '.ps.gz'
170         list.write("<li><a href=%s.ps.gz>%s.ps.gz</a>" % (stuff, stuff))
171     list.write('</ul></BODY></HTML>')
172     list.close ()
173
174     my_system (['make -C .. ' + todo])
175
176 def file_exist_b(name):
177     try: 
178         f = open(name)
179     except IOError:
180         return 0
181     f.close ()
182     return 1
183 def copy_files():
184     print "copying files\n"
185     
186 #    my_system ("ln -s depth/out ./docxx" )
187     my_system([ "cp %s/TODO ./TODO.txt" % depth,
188     "cp %s/ANNOUNCE-0.1 ./ANNOUNCE.txt" % depth,
189     "cp %s/NEWS ./NEWS.txt" % depth,
190     "cp %s/DEDICATION ./DEDICATION.txt" % depth]);
191     my_system([ "make -C .. gifs"]);
192     
193 def docxx_update():
194     print 'docxx.. \n'
195     banner= open('/tmp/lilybanner.html', 'w');
196     banner.write (footstr('../index.html'))
197     banner.close ()
198     my_system(['BANNEROPT=\"-B /tmp/lilybanner.html\" %s/bin/out/make-docxx' % depth]);
199 #    os.unlink( "/tmp/lilybanner.html");
200
201 def get_glob(exts):
202     result = []
203     for a in exts:
204         result = result + glob.glob1('./', '*.' + a)
205
206     return result
207
208 def join(inter, list):
209     return reduce (lambda x,y, i=inter: x + i + y, list)
210
211 def do_tar():
212      print "tarring.\n";
213      list = get_glob( ['html', 'gif', 'ps.gz' , 'txt', 'midi']) 
214      files = join (' ', list)
215      print files
216      my_system( ['-tar zvhcf website.tar.gz ' + files + ' docxx/*'])
217
218
219 def identify():
220     print 'This is %s\n' % id_str
221     
222 def clean_tmp():
223     my_system(['rm -f /tmp/gs*'])
224     
225 def get_top_of_NEWS():
226     i = open('NEWS.txt')
227     lines = i.readlines()
228     i.close ()
229     s = ''
230     for l in lines:
231         if regex.search('^\*\*\*\*\*\*', l) <> -1:
232             return s;
233         s = s + l
234     return s
235
236 def edit_index():
237     s = gulp_file('index.html')
238     s = regsub.sub ('top_of_NEWS', '<XMP>\n' + get_top_of_NEWS () + '\n</XMP>', s)
239     dump_file ('index.html', s)
240
241 def edit_html():
242     files = get_glob(['html'])
243     for f in files:
244
245         s = gulp_file(f)
246         if regex.search(makewebsite_id, s) <> -1:
247             continue;
248
249         s = regsub.sub ('</BODY>', footstr('index.html') + makewebsite_id + '</BODY>', s)
250         s = regsub.sub('<TITLE>\(.*\)</TITLE>$', 
251                        '<TITLE>LilyPond WWW: \\1</TITLE>', s)
252         dump_file (f,s)
253
254 def main():
255     identify();
256
257     os.chdir (lilydirs.topdir + 'Documentation/out')
258     __main__.depth = "../../";
259
260     set_vars();
261     gen_html();
262     copy_files();
263     gen_examples(examples);
264     gen_list(examples, 'examples_output.html');
265
266     gen_examples(mutopia_examples);
267     gen_list(mutopia_examples, 'mutopiaexamples_output.html');
268     gen_manuals();
269     #set_images();
270     edit_html();
271     edit_index();
272     docxx_update()
273     do_tar()
274     clean_tmp();
275
276
277 main()
278
279