]> git.donarmstrong.com Git - lilypond.git/blob - bin/make-website.py
release: 0.1.59
[lilypond.git] / bin / make-website.py
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 outdir=out-www";
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
98 def gen_html():
99     print 'generating HTML'
100     my_system (["make -f Makefile -kC .. html"]);
101     
102
103
104 texstuff = ["mudela"]
105
106 def gen_manuals():
107     print 'generating TeX doco manuals'
108     list = open('tex_manuals.html', 'w')
109     list.write( "<HTML><TITLE>PostScript Manuals</TITLE>\n" 
110      "<BODY><h1>LilyPond manuals (in PostScript)</h1>"
111      "<ul>\n")
112     todo='' 
113     for stuff in texstuff:
114         todo = todo + ' out/' + stuff + '.ps.gz'
115         list.write("<li><a href=%s.ps.gz>%s.ps.gz</a>" % (stuff, stuff))
116     list.write('</ul></BODY></HTML>')
117     list.close ()
118
119     my_system (['make -C .. ' + todo])
120
121
122 def copy_files():
123     print "copying files\n"
124     
125 #    my_system ("ln -s depth/out ./docxx" )
126     my_system([ "cp %s/TODO ./TODO.txt" % depth,
127     "cp %s/ANNOUNCE-0.1 ./ANNOUNCE-0.1.txt" % depth,
128     "cp %s/NEWS ./NEWS.txt" % depth,
129     "cp %s/DEDICATION ./DEDICATION.txt" % depth]);
130     my_system([ "make -C .. gifs"]);
131     
132 def docxx_update():
133     print 'docxx.. \n'
134     banner= open('/tmp/lilybanner.html', 'w');
135     banner.write (footstr('../index.html'))
136     banner.close ()
137     my_system(['BANNEROPT=\"-B /tmp/lilybanner.html\" %s/bin/out/make-docxx' % depth]);
138 #    os.unlink( "/tmp/lilybanner.html");
139
140 def get_glob(exts):
141     result = []
142     for a in exts:
143         result = result + glob.glob1('./', '*.' + a)
144
145     return result
146
147 def join(inter, list):
148     return reduce (lambda x,y, i=inter: x + i + y, list)
149
150 def do_tar():
151      print "tarring.\n";
152      list = get_glob( ['html', 'gif', 'ps.gz' , 'txt', 'midi']) 
153      files = join (' ', list)
154      print files
155      my_system( ['-tar zvhcf website.tar.gz ' + files + ' docxx/*'])
156
157
158 def identify():
159     print 'This is %s\n' % id_str
160     
161 def clean_tmp():
162     my_system(['-rm -f /tmp/gs*'])
163     
164 def get_top_of_NEWS():
165     i = open('NEWS.txt')
166     lines = i.readlines()
167     i.close ()
168     s = ''
169     for l in lines:
170         if regex.search('^\*\*\*\*\*\*', l) <> -1:
171             return s;
172         s = s + l
173     return s
174
175 def edit_index():
176     s = gulp_file('index.html')
177     s = regsub.sub ('top_of_NEWS', '<XMP>\n' + get_top_of_NEWS () + '\n</XMP>', s)
178     dump_file ('index.html', s)
179
180 def edit_html():
181     files = get_glob(['html'])
182     for f in files:
183
184         s = gulp_file(f)
185         if regex.search(makewebsite_id, s) <> -1:
186             continue;
187
188         s = regsub.sub ('</BODY>', footstr('index.html') + makewebsite_id + '</BODY>', s)
189         s = regsub.sub('<TITLE>\(.*\)</TITLE>$', 
190                        '<TITLE>LilyPond WWW: \\1</TITLE>', s)
191
192         dump_file (f,s)
193
194
195 def do_examples (examples, filename):
196     located_files = gen_examples (examples)
197     gen_list (examples, filename)
198 def main():
199     identify();
200
201     os.chdir (lilydirs.topdir + 'Documentation')
202     
203 #    my_system (['-rm ../WWW/*.pod ../WWW/*.xpm ../WWW/*.doc',
204 #               'ln ../Documentation/*.pod ../Documentation/*.doc ../Documentation/*.xpm .']);
205     os.chdir (lilydirs.topdir + 'Documentation/out/')
206     __main__.depth = "../../";
207     __main__.include_path = map(lambda p: __main__.depth + '/' + 
208                                 p, __main__.include_path)
209
210     set_vars();
211     gen_html();
212     copy_files();
213     do_examples (examples, 'examples_output.html');
214     do_examples (mutopia_examples, 'mutopiaexamples_output.html');
215     gen_manuals();
216     #set_images();
217     edit_html();
218     edit_index();
219     docxx_update()
220     do_tar()
221     clean_tmp();
222
223
224 main()
225
226