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