12 f = os.popen ('find %s -name "%s"'% (dir, pat))
14 for a in f.readlines():
20 junk_prefix = 'out-www/'
24 <h1>LilyPond samples</h1>
27 <p>You are looking at a page with some LilyPond samples. These files
28 are also included in the distribution. The output is completely
29 generated from the source file, without any further touch up.
33 The pictures are 90 dpi anti-aliased snapshots of the printed output.
34 For a good impression of the quality print out the PDF file.
37 headertext_nopics= r"""
38 <p>No examples were found in this directory.
42 # FIXME breaks on multiple strings.
44 def read_lilypond_header (fn):
46 s = re.sub ('%.*$', '', s)
47 s = re.sub ('\n', ' ', s)
50 m = re.search (r"""\\header\s*{([^}]*)}""", s)
58 m = re.search (r'''\s*(\S+)\s*=\s*"([^"]+)"''', s)
66 left = re.sub ('"', '', left)
67 right = re.sub ('"', '', right)
73 sys.stdout.write (r'''Usage: mutopia-index [OPTIONS] INFILE OUTFILE
74 Generate index for mutopia.
77 -h, --help print this help
78 -o, --output=FILE write output to file
79 -s, --subdirs=DIR add subdir
80 --suffix=SUF specify suffix
86 def gen_list (inputs, file_name):
87 sys.stderr.write ("generating HTML list %s" % file_name)
88 sys.stderr.write ('\n')
90 list = open (file_name, 'w')
93 list.write ('''<html><head><title>Rendered Examples</title>
94 <style type="text/css">
95 hr { border:0; height:1; color: #000000; background-color: #000000; }\n
97 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
100 list.write ('<body bgcolor=white>\n')
103 list.write (headertext)
105 list.write (headertext_nopics)
110 (base, ext) = os.path.splitext (ex)
111 (base, ext2) = os.path.splitext (base)
114 header = read_lilypond_header (ex)
115 head = header.get ('title', os.path.basename (base))
116 composer = header.get ('composer', '')
117 desc = header.get ('description', '')
118 list.write ('<hr>\n')
119 list.write ('<h1>%s</h1>\n' % head);
121 list.write ('<h2>%s</h2>\n' % composer)
123 list.write ('%s<p>' % desc)
124 list.write ('<ul>\n')
126 def list_item (file_name, desc, type, lst = list):
127 if os.path.isfile (file_name):
128 lst.write ('<li><a href="%s">%s</a>'
129 % (re.sub (junk_prefix, '', file_name), desc))
131 # FIXME: include warning if it uses \include
134 size = os.stat (file_name)[stat.ST_SIZE]
135 kB = (size + 512) / 1024
137 lst.write (' (%s %d kB)' % (type, kB))
139 lst.write (' (%s %d characters)'
141 pictures = ['jpeg', 'png', 'xpm']
144 print "cannot find" , `file_name`
146 list_item (base + ext, 'The input', 'ASCII')
149 for page in range (1, 100):
150 f = base + '-page%d.png' % page
152 if not os.path.isfile (f):
155 list_item (f, 'See a picture of page %d' % page, 'png')
157 if pages_found == 0 and os.path.exists (base + '.png'):
158 list_item (base + ".png",
159 'See a picture', 'png')
162 list_item (base + '.pdf', 'Print', 'PDF')
163 list_item (base + '.midi', 'Listen', 'MIDI')
164 list.write ('</ul>\n');
166 list.write ('</body></html>\n');
169 (options, files) = getopt.getopt (sys.argv[1:],
170 'ho:', ['help', 'output='])
171 outfile = 'examples.html'
174 for (o, a) in options:
175 if o == '--help' or o == '-h':
177 elif o == '--output' or o == '-o':
182 dirs += find ('out-www', f)
190 allfiles += find ('*.ly', d)
192 allfiles = [f for f in allfiles
193 if not f.endswith ('snippet-map.ly')
194 and not re.search ('lily-[0-9a-f]+', f)
195 and 'musicxml' not in f]
197 gen_list (allfiles, outfile)