]> git.donarmstrong.com Git - lilypond.git/blob - bin/make-website.py
ac6d865af606e7f1d965fd29112074653488cb48
[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     os.environ["CONFIGSUFFIX"] = 'www';
59     
60     os.environ["LILYINCLUDE"] = join (':', __main__.include_path) +':'+ os.environ["LILYINCLUDE"];
61     os.environ["LILYTOP"] = depth;
62     __main__.mailaddress= os.environ['MAILADDRESS']
63     pw = pwd.getpwuid (os.getuid());
64
65     __main__.fullname= pw[4];
66
67 backstr = '\n<hr>Please take me <a href=%s>back to the index</a>\n\
68 of LilyPond -- The GNU Project Music typesetter\n\
69 <hr><font size=-1>\n\
70 This page was built using <code>%s</code> from lilypond-%s by <p>\n\
71 <address><br>%s <a href=mailto:%s>&lt<!bla>%s</a>&gt</address>\n\
72 <p></font>' 
73
74     
75 def footstr(index):
76      return backstr % (index, id_str, lilyversion, fullname, mailaddress, mailaddress)
77
78     
79
80 # do something, check return status
81 def my_system(cmds):
82     for cmd in cmds:
83         ignoreret=0;
84         if cmd[0] == '-':
85             ignoreret = 1
86             cmd = cmd[1:]
87         
88         ret = os.system (cmd)
89         if ret:
90             if ignoreret: 
91                 sys.stderr.write( "ignoring failed command `%s\' (status %d)\n" % (cmd, ret))
92             else:
93                 sys.stderr.write( 'make-website: failed on command %s (status %d)\n' % (cmd, ret))
94                 sys.exit (2)
95
96 base="lilypond/";
97
98
99 def gen_html():
100     print 'generating HTML'
101     my_system (["make -f Makefile -kC .. html"]);
102     
103
104
105 texstuff = ["mudela"]
106
107 def gen_manuals():
108     print 'generating TeX doco manuals'
109     list = open('tex_manuals.html', 'w')
110     list.write( "<HTML><TITLE>PostScript Manuals</TITLE>\n" 
111      "<BODY><h1>LilyPond manuals (in PostScript)</h1>"
112      "<ul>\n")
113     todo='' 
114     for stuff in texstuff:
115         todo = todo + ' out/' + stuff + '.ps.gz'
116         list.write("<li><a href=%s.ps.gz>%s.ps.gz</a>" % (stuff, stuff))
117     list.write('</ul></BODY></HTML>')
118     list.close ()
119
120     my_system (['make -C .. ' + todo])
121
122
123 def copy_files():
124     print "copying files\n"
125     
126 #    my_system ("ln -s depth/out ./docxx" )
127     my_system([ "cp %s/TODO ./TODO.txt" % depth,
128     "cp %s/ANNOUNCE-0.1 ./ANNOUNCE-0.1.txt" % depth,
129     "cp %s/NEWS ./NEWS.txt" % depth,
130     "cp %s/DEDICATION ./DEDICATION.txt" % depth]);
131     my_system([ "make -C .. gifs"]);
132     
133 def docxx_update():
134     print 'docxx.. \n'
135     banner= open('/tmp/lilybanner.html', 'w');
136     banner.write (footstr('../index.html'))
137     banner.close ()
138     my_system(['BANNEROPT=\"-B /tmp/lilybanner.html\" %s/bin/out/make-docxx' % depth]);
139 #    os.unlink( "/tmp/lilybanner.html");
140
141 def get_glob(exts):
142     result = []
143     for a in exts:
144         result = result + glob.glob1('./', '*.' + a)
145
146     return result
147
148 def join(inter, list):
149     return reduce (lambda x,y, i=inter: x + i + y, list)
150
151 def do_tar():
152      print "tarring.\n";
153      list = get_glob( ['html', 'gif', 'ps.gz' , 'txt', 'midi']) 
154      files = join (' ', list)
155      print files
156      my_system( ['-tar zvhcf website.tar.gz ' + files + ' docxx/*'])
157
158
159 def identify():
160     print 'This is %s\n' % id_str
161     
162 def clean_tmp():
163     my_system(['-rm -f /tmp/gs*'])
164     
165 def get_top_of_NEWS():
166     i = open('NEWS.txt')
167     lines = i.readlines()
168     i.close ()
169     s = ''
170     for l in lines:
171         if regex.search('^\*\*\*\*\*\*', l) <> -1:
172             return s;
173         s = s + l
174     return s
175
176 def edit_index():
177     s = gulp_file('index.html')
178     s = regsub.sub ('top_of_NEWS', '<XMP>\n' + get_top_of_NEWS () + '\n</XMP>', s)
179     dump_file ('index.html', s)
180
181 def edit_html():
182     files = get_glob(['html'])
183     for f in files:
184
185         s = gulp_file(f)
186         if regex.search(makewebsite_id, s) <> -1:
187             continue;
188
189         s = regsub.sub ('</BODY>', footstr('index.html') + makewebsite_id + '</BODY>', s)
190         s = regsub.sub('<TITLE>\(.*\)</TITLE>$', 
191                        '<TITLE>LilyPond WWW: \\1</TITLE>', s)
192
193         dump_file (f,s)
194
195
196 def do_examples (examples, filename):
197     located_files = gen_examples (examples)
198     gen_list (examples, filename)
199 def main():
200     identify();
201
202     os.chdir (lilydirs.topdir + 'Documentation')
203     
204 #    my_system (['-rm ../WWW/*.pod ../WWW/*.xpm ../WWW/*.doc',
205 #               'ln ../Documentation/*.pod ../Documentation/*.doc ../Documentation/*.xpm .']);
206     os.chdir (lilydirs.topdir + 'Documentation/out/')
207     __main__.depth = "../../";
208     __main__.include_path = map(lambda p: __main__.depth + '/' + 
209                                 p, __main__.include_path)
210
211     set_vars();
212     gen_html();
213     copy_files();
214     do_examples (examples, 'examples_output.html');
215     do_examples (mutopia_examples, 'mutopiaexamples_output.html');
216     gen_manuals();
217     #set_images();
218     edit_html();
219     edit_index();
220     docxx_update()
221     do_tar()
222     clean_tmp();
223
224
225 main()
226
227