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):
56 <h1>LilyPond samples</h1>
59 <p>You're looking at a page with some LilyPond samples. These files
60 are also included in the distribution. The output is completely
61 generated from the <tt>.ly</tt> source file, without any further touch
66 The pictures are 90 dpi anti-aliased snapshots of the printed output.
67 If you want a better impression of the appearance, do print out one of
68 the PDF or PostScript files; they use scalable fonts, and should look
69 good at any resolution.
73 headertext_nopics= r"""
74 <p>Nothing to be seen here, move along.
78 # FIXME breaks on multiple strings.
80 def read_lilypond_header (fn):
82 s = re.sub('%.*$', '', s)
83 s = re.sub('\n', ' ', s)
86 m = re.search (r"""\\header\s*{([^}]*)}""", s)
94 m = re.search (r'''\s*(\S+)\s*=\s*"([^"]+)"''', s)
102 left = re.sub ('"', '', left)
103 right = re.sub ('"', '', right)
109 sys.stdout.write (r"""Usage: mutopia-index [OPTIONS] INFILE OUTFILE
110 Generate index for mutopia.
113 -h, --help print this help
114 -o, --output=FILE write output to file
115 -s, --subdirs=DIR add subdir
116 --suffix=SUF specify suffix
123 def gen_list(inputs, filename):
124 print "generating HTML list %s\n" % filename
126 list = open(filename, 'w')
129 list.write ('''<html><head><title>Rendered Examples</title>
130 <style type="text/css">
131 hr { border:0; height:1; color: #000000; background-color: #000000; }\n
133 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
136 list.write ('<body bgcolor=white>\n')
139 list.write (headertext)
141 list.write (headertext_nopics)
145 (base, ext) = os.path.splitext (ex)
146 (base, ext2) = os.path.splitext (base)
149 header = read_lilypond_header(ex)
150 def read_dict(s, default, h =header):
156 head = read_dict('title', os.path.basename (base))
157 composer = read_dict('composer', '')
158 desc = read_dict('description', '')
160 list.write('<h1>%s</h1>\n' % head);
162 list.write('<h2>%s</h2>\n' % composer)
164 list.write('%s<p>' % desc)
165 list.write ('<ul>\n')
166 def list_item(filename, desc, type, l = list):
167 if file_exist_b(filename):
169 l.write ('<li><a href="%s">%s</a>' % (filename, desc))
171 # todo: include warning if it uses \include
174 size=os.stat(filename)[stat.ST_SIZE]
175 kB=(size + 512) / 1024
177 l.write (' (%s %d kB)' % (type, kB))
179 l.write (' (%s %d characters)' % (type, size))
180 pictures = ['jpeg', 'png', 'xpm']
183 list_item(base + ext, 'The input', 'ASCII')
184 for pageno in range(1,100):
185 f = base + '-page%d.png' % pageno
186 if not file_exist_b (f):
188 list_item(f, 'See a picture of page %d' % pageno, 'png')
189 list_item(base + '.pdf', 'Print', 'PDF')
190 list_item(base + '.midi', 'Listen', 'MIDI')
191 list.write ("</ul>\n");
193 list.write('</body></html>\n');
198 (options, files) = getopt.getopt(sys.argv[1:],
199 'ho:', ['help', 'output='])
200 outfile = 'examples.html'
206 if o == '--help' or o == '-h':
208 elif o == '--output' or o == '-o':
213 dirs = dirs + find ('out-www', f)
221 allfiles = allfiles + find ('*.ly.txt', d)
223 gen_list (allfiles, outfile)