16 raise 'not there' , fn
19 def file_exist_b (fn):
28 These example files are taken from the LilyPond distribution.
29 LilyPond currently only outputs TeX and MIDI. The pictures and
30 PostScript files were generated using TeX, Ghostscript and some
31 graphics tools. The papersize used for these examples is A4.
32 The images are in PNG format, and should be viewable with any current browser.
33 We don't use GIFS due to <a href="http://www.gnu.org/philosophy/gif.html">patent problems</a>.
35 If you want an accurate impression of the output quality please <em>print
36 out</em> the samples first.
39 headertext_nopics = r"""This is a subdirectory of the LilyPond example
40 set. We decided not to show any examples from this directory. If you
41 want to view them, then you have to download LilyPond and compile them
46 # FIXME breaks on multiple strings.
48 def read_mudela_header (fn):
50 s = re.sub('%.*$', '', s)
51 s = re.sub('\n', ' ', s)
54 m = re.search (r"""\\header\s*{([^}]*)}""", s)
62 m = re.search (r"""\s*(\S+)\s*=\s*([^;]+)\s*;""", s)
70 left = re.sub ('"', '', left)
71 right = re.sub ('"', '', right)
77 sys.stdout.write (r"""Usage: mutopia-index [options] INFILE OUTFILE
78 Generate index for mutopia\n
80 -h, --help print this help
81 --prefix=PRE specify prefix
82 -s, --subdirs=DIR add subdir
83 --suffix=SUF specify suffix"""
88 def gen_list(inputs, subdir, filename):
89 (pre, subdirs, post)=subdir
90 print "generating HTML list %s\n" % filename
91 list = open(filename, 'w')
92 list.write ('<html><TITLE>Rendered Examples</TITLE>\n')
93 list.write ('<body bgcolor=white>')
95 list.write ('<h2>subdirectories</h2>')
98 print 'subdir %s ' % ex
99 list.write ('<li><a href=%s/index.html>Subdirectory: %s</a></li>\n' % (pre + ex + post , ex))
106 list.write('<h2>Contents of this directory</h2>\n');
108 list.write (headertext)
110 list.write (headertext_nopics)
117 header = read_mudela_header(ex + ex_ext + '.txt')
120 header = read_mudela_header(ex + ex_ext + '.txt')
122 def read_dict(s, default, h =header):
128 head = read_dict('title', ex)
129 composer = read_dict('composer', '')
130 desc = read_dict('description', '')
132 list.write('<h1>example file: %s</h1>' % head);
134 list.write('<h2>%s</h2>\n' % composer)
136 list.write('%s<p>' % desc)
138 def list_item(filename, desc, type, l = list):
139 if file_exist_b(filename):
140 l.write ('<li><a href=%s>%s</a>' % (filename, desc))
141 size=os.stat(filename)[stat.ST_SIZE]
142 l.write (' (%s %dk)' % (type, (size + 512) / 1024))
143 pictures = ['jpeg', 'png', 'xpm']
145 list_item(ex + ex_ext + '.txt', 'The input', 'ASCII')
146 for pageno in range(1,100):
147 f = ex + '-page%d.png' % pageno
148 if not file_exist_b (f):
150 list_item(f, 'The output, page %d' % pageno, 'png')
151 list_item(ex + '.ps.gz', 'The output', 'gzipped PostScript')
152 list_item(ex + '.midi', 'The output', 'MIDI')
153 list.write ("</ul>");
155 list.write( "</BODY></HTML>");
160 (options, files) = getopt.getopt(sys.argv[1:],
161 'hp:s:', ['help', 'subdirs=', 'suffix=', 'prefix='])
169 if o == '--subdirs' or o == '-s':
171 elif o == '--prefix':
173 elif o == '--suffix':
177 allfiles = find.find ('*.ly') + find.find ('*.ly.txt')
179 gen_list (files, (subdir_pre, subdirs, subdir_suf), 'index.html')