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