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