15 def find (pattern, dir = os.curdir):
17 names = os.listdir (dir)
20 if name in (os.curdir, os.pardir):
22 fullname = os.path.join (dir, name)
23 if fnmatch.fnmatch (name, pattern):
25 if os.path.isdir (fullname) and not os.path.islink (fullname):
27 if fnmatch.fnmatch (name, p):
29 print "skip", `fullname`
33 print "descend into", `fullname`
34 lst = lst + find (pattern, fullname)
39 <h1>LilyPond samples</h1>
42 <p>You're looking at a page with some LilyPond samples. These files
43 are also included in the distribution. The output is completely
44 generated from the <tt>.ly</tt> source file, without any further touch
49 The pictures are 90 dpi anti-aliased snapshots of the printed output.
50 If you want a better impression of the appearance, do print out one of
51 the PDF or PostScript files; they use scalable fonts, and should look
52 good at any resolution.
56 headertext_nopics= r"""
57 <p>Nothing to be seen here, move along.
61 # FIXME breaks on multiple strings.
63 def read_lilypond_header (fn):
65 s = re.sub ('%.*$', '', s)
66 s = re.sub ('\n', ' ', s)
69 m = re.search (r"""\\header\s*{([^}]*)}""", s)
77 m = re.search (r'''\s*(\S+)\s*=\s*"([^"]+)"''', s)
85 left = re.sub ('"', '', left)
86 right = re.sub ('"', '', right)
92 sys.stdout.write (r'''Usage: mutopia-index [OPTIONS] INFILE OUTFILE
93 Generate index for mutopia.
96 -h, --help print this help
97 -o, --output=FILE write output to file
98 -s, --subdirs=DIR add subdir
99 --suffix=SUF specify suffix
105 def gen_list (inputs, file_name):
106 sys.stderr.write ("generating HTML list %s" % file_name)
107 sys.stderr.write ('\n')
109 list = open (file_name, 'w')
112 list.write ('''<html><head><title>Rendered Examples</title>
113 <style type="text/css">
114 hr { border:0; height:1; color: #000000; background-color: #000000; }\n
116 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
119 list.write ('<body bgcolor=white>\n')
122 list.write (headertext)
124 list.write (headertext_nopics)
127 (base, ext) = os.path.splitext (ex)
128 (base, ext2) = os.path.splitext (base)
131 header = read_lilypond_header (ex)
132 def read_dict (s, default, h = header):
138 head = read_dict ('title', os.path.basename (base))
139 composer = read_dict ('composer', '')
140 desc = read_dict ('description', '')
141 list.write ('<hr>\n')
142 list.write ('<h1>%s</h1>\n' % head);
144 list.write ('<h2>%s</h2>\n' % composer)
146 list.write ('%s<p>' % desc)
147 list.write ('<ul>\n')
149 def list_item (file_name, desc, type, lst = list):
150 if os.path.isfile (file_name):
151 lst.write ('<li><a href="%s">%s</a>'
154 # FIXME: include warning if it uses \include
157 size = os.stat (file_name)[stat.ST_SIZE]
158 kB = (size + 512) / 1024
160 lst.write (' (%s %d kB)' % (type, kB))
162 lst.write (' (%s %d characters)'
164 pictures = ['jpeg', 'png', 'xpm']
167 list_item (base + ext, 'The input', 'ASCII')
168 for page in range (1, 100):
169 f = base + '-page%d.png' % page
170 if not os.path.isfile (f):
172 list_item (f, 'See a picture of page %d' % page, 'png')
173 list_item (base + '.pdf', 'Print', 'PDF')
174 list_item (base + '.midi', 'Listen', 'MIDI')
175 list.write ('</ul>\n');
177 list.write ('</body></html>\n');
180 (options, files) = getopt.getopt (sys.argv[1:],
181 'ho:', ['help', 'output='])
182 outfile = 'examples.html'
188 if o == '--help' or o == '-h':
190 elif o == '--output' or o == '-o':
195 dirs = dirs + find ('out-www', f)
203 allfiles = allfiles + find ('*.ly.txt', d)
205 gen_list (allfiles, outfile)