lilypond-1.3.130
[lilypond.git] / bin / mutopia-index.py
blob485578f0dc27c829036ed47763d31bd8e0fd0ddc
2 import sys
3 import os
5 lilypath =''
6 try:
7 lilypath = os.environ['LILYPOND_SOURCEDIR'] + '/'
8 except KeyError:
9 print 'Please set LILYPOND_SOURCEDIR to the toplevel source, eg LILYPOND_SOURCEDIR=/home/foobar/lilypond-1.2.3/'
10 sys.exit(1)
12 lilypath = lilypath + '/bin/'
13 sys.path.append(lilypath)
15 from lilypython import *
19 def gen_list(inputs, subdir, filename):
20 (pre, subdirs, post)=subdir
21 print "generating HTML list %s\n" % filename
22 list = open(filename, 'w')
23 list.write ('<html><TITLE>Rendered Examples</TITLE>\n')
24 list.write ('<body>')
25 if len(subdirs):
26 list.write ('<h2>subdirectories</h2>')
27 list.write ('<ul>')
28 for ex in subdirs:
29 print 'subdir %s ' % ex
30 list.write ('<li><a href=%s/index.html>Subdirectory: %s</a></li>\n' % (pre + ex + post , ex))
32 list.write ('</ul>')
34 list.write('<h2>Contents of this directory</h2>\n');
35 list.write ('These example files are taken from the LilyPond distribution.\n'
36 'LilyPond currently only outputs TeX and MIDI. The pictures and\n'
37 'PostScript files were generated using TeX, Ghostscript and some\n'
38 'graphics tools. The papersize used for these examples is A4. The GIF\n'
39 'files have been scaled to eliminate aliasing.\n');
42 for ex in inputs:
43 print '%s, ' % ex
44 header = read_mudela_header(ex + '.ly.txt')
46 def read_dict(s, default, h =header):
47 try:
48 ret = h[s]
49 except KeyError:
50 ret = default
51 return ret
52 head = read_dict('title', ex)
53 composer = read_dict('composer', '')
54 desc = read_dict('description', '')
55 list.write('<hr>')
56 list.write('<h1>example file: %s</h1>' % head);
57 if composer <> '':
58 list.write('<h2>%s</h2>\n' % composer)
59 if desc <> '':
60 list.write('%s<p>' % desc)
61 list.write ('<ul>')
62 def list_item(filename, desc, l = list):
63 if file_exist_b(filename):
64 l.write ('<li><a href=%s>%s</a>\n' % (filename, desc))
66 list_item(ex + '.ly.txt', 'The input')
67 for pageno in range(1,10):
68 f = ex + '-page%d.gif' % pageno
69 if not file_exist_b (f):
70 break
71 list_item(f, 'The output (picture, page %d)' % pageno)
72 list_item(ex + '.ps.gz', 'The output (gzipped PostScript)')
73 list_item(ex + '.midi', 'The output (MIDI)')
74 list.write ("</ul>");
76 list.write( "</BODY></HTML>");
77 list.close()
79 allfiles = multiple_find (['*.ly.txt'], '.')
81 import getopt
83 (cl_options, files) = getopt.getopt(sys.argv[1:],
84 'hs:', ['help', 'subdirs=', 'suffix=', 'prefix='])
85 subdir_pre=''
86 subdir_suf =''
88 subdirs =[]
89 for opt in cl_options:
90 o = opt[0]
91 a = opt[1]
92 if o == '--subdirs' or o == '-s':
93 subdirs.append (a)
94 elif o == '--prefix':
95 subdir_pre = a
96 elif o == '--suffix':
97 subdir_suf = a
99 gen_list (files, (subdir_pre, subdirs, subdir_suf), 'index.html')