13 def find(pattern, dir = os.curdir):
15 names = os.listdir(dir)
18 if name in (os.curdir, os.pardir):
20 fullname = os.path.join(dir, name)
21 if fnmatch.fnmatch(name, pattern):
23 if os.path.isdir(fullname) and not os.path.islink(fullname):
25 if fnmatch.fnmatch(name, p):
26 if _debug: print "skip", `fullname`
29 if _debug: print "descend into", `fullname`
30 list = list + find(pattern, fullname)
43 raise 'not there' , fn
46 def file_exist_b (fn):
55 <p>You're looking at a page with some LilyPond samples.
56 These files are also included in the distribution. The output is
57 completely generated by LilyPond, without any touch up by humans.
59 <p>The PostScript files were generated using TeX and dvips at 600 dpi.
60 The pictures are 90dpi anti-aliased snapshots of the printed output.
61 The images are in PNG format, and should be viewable with any current
64 <p>If you want a better impression of the appearance, do print out one of
68 headertext_nopics= r"""
69 <p>Nothing to be seen here, move along.
73 # FIXME breaks on multiple strings.
75 def read_lilypond_header (fn):
77 s = re.sub('%.*$', '', s)
78 s = re.sub('\n', ' ', s)
81 m = re.search (r"""\\header\s*{([^}]*)}""", s)
89 m = re.search (r"""\s*(\S+)\s*=\s*([^;]+)\s*;""", s)
97 left = re.sub ('"', '', left)
98 right = re.sub ('"', '', right)
104 sys.stdout.write (r"""Usage: mutopia-index [options] INFILE OUTFILE
105 Generate index for mutopia\n
107 -h, --help print this help
108 -o,-output=FILE write output to file.
109 -s, --subdirs=DIR add subdir
110 --suffix=SUF specify suffix"""
115 def gen_list(inputs, filename):
116 print "generating HTML list %s\n" % filename
118 list = open(filename, 'w')
121 list.write ('<html><title>Rendered Examples</title>\n')
122 list.write ('<body bgcolor=white>\n')
125 list.write (headertext)
127 list.write (headertext_nopics)
131 (base, ext) = os.path.splitext (ex)
132 (base, ext2) = os.path.splitext (base)
136 header = read_lilypond_header(ex)
138 def read_dict(s, default, h =header):
144 head = read_dict('title', os.path.basename (base))
145 composer = read_dict('composer', '')
146 desc = read_dict('description', '')
148 list.write('<h1>example file: %s</h1>\n' % head);
150 list.write('<h2>%s</h2>\n' % composer)
152 list.write('%s<p>' % desc)
153 list.write ('<ul>\n')
154 def list_item(filename, desc, type, l = list):
155 if file_exist_b(filename):
157 l.write ('<li><a href="%s">%s</a>' % (filename, desc))
159 # todo: include warning if it uses \include
162 size=os.stat(filename)[stat.ST_SIZE]
163 kB=(size + 512) / 1024
165 l.write (' (%s %dkB)' % (type, kB))
167 l.write (' (%s %dcharacters)' % (type, size))
168 pictures = ['jpeg', 'png', 'xpm']
171 list_item(base + ext, 'The input', 'ASCII')
172 for pageno in range(1,100):
173 f = base + '-page%d.png' % pageno
174 if not file_exist_b (f):
176 list_item(f, 'See a picture of page %d' % pageno, 'png')
177 list_item(base + '.pdf', 'Print ', 'PDF')
178 list_item(base + '.ps.gz', 'Print ', 'gzipped PostScript')
179 list_item(base + '.midi', 'Listen', 'MIDI')
180 list.write ("</ul>\n");
182 list.write('</body></html>\n');
187 (options, files) = getopt.getopt(sys.argv[1:],
188 'ho:', ['help', 'output='])
189 outfile = 'examples.html'
195 if o == '--help' or o == '-h':
197 elif o == '--output' or o == '-o':
202 dirs = dirs + find ('out-www', f)
210 allfiles = allfiles + find ('*.ly.txt', d)
214 gen_list (allfiles, outfile)