13 f
= os
.popen ('find %s -name "%s"'% (dir, pat
))
15 for a
in f
.readlines():
21 junk_prefix
= 'out-www/'
25 <h1>LilyPond samples</h1>
28 <p>You're looking at a page with some LilyPond samples. These files
29 are also included in the distribution. The output is completely
30 generated from the source file, without any further touch up.
34 The pictures are 90 dpi anti-aliased snapshots of the printed output.
35 For a good impression of the quality print out the PDF file.
38 headertext_nopics
= r
"""
39 <p>No examples were found in this directory.
43 # FIXME breaks on multiple strings.
45 def read_lilypond_header (fn
):
47 s
= re
.sub ('%.*$', '', s
)
48 s
= re
.sub ('\n', ' ', s
)
51 m
= re
.search (r
"""\\header\s*{([^}]*)}""", s
)
59 m
= re
.search (r
'''\s*(\S+)\s*=\s*"([^"]+)"''', s
)
67 left
= re
.sub ('"', '', left
)
68 right
= re
.sub ('"', '', right
)
74 sys
.stdout
.write (r
'''Usage: mutopia-index [OPTIONS] INFILE OUTFILE
75 Generate index for mutopia.
78 -h, --help print this help
79 -o, --output=FILE write output to file
80 -s, --subdirs=DIR add subdir
81 --suffix=SUF specify suffix
87 def gen_list (inputs
, file_name
):
88 sys
.stderr
.write ("generating HTML list %s" % file_name
)
89 sys
.stderr
.write ('\n')
91 list = open (file_name
, 'w')
94 list.write ('''<html><head><title>Rendered Examples</title>
95 <style type="text/css">
96 hr { border:0; height:1; color: #000000; background-color: #000000; }\n
98 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
101 list.write ('<body bgcolor=white>\n')
104 list.write (headertext
)
106 list.write (headertext_nopics
)
111 (base
, ext
) = os
.path
.splitext (ex
)
112 (base
, ext2
) = os
.path
.splitext (base
)
115 header
= read_lilypond_header (ex
)
116 def read_dict (s
, default
, h
= header
):
122 head
= read_dict ('title', os
.path
.basename (base
))
123 composer
= read_dict ('composer', '')
124 desc
= read_dict ('description', '')
125 list.write ('<hr>\n')
126 list.write ('<h1>%s</h1>\n' % head
);
128 list.write ('<h2>%s</h2>\n' % composer
)
130 list.write ('%s<p>' % desc
)
131 list.write ('<ul>\n')
133 def list_item (file_name
, desc
, type, lst
= list):
134 if os
.path
.isfile (file_name
):
135 lst
.write ('<li><a href="%s">%s</a>'
136 % (re
.sub (junk_prefix
, '', file_name
), desc
))
138 # FIXME: include warning if it uses \include
141 size
= os
.stat (file_name
)[stat
.ST_SIZE
]
142 kB
= (size
+ 512) / 1024
144 lst
.write (' (%s %d kB)' % (type, kB
))
146 lst
.write (' (%s %d characters)'
148 pictures
= ['jpeg', 'png', 'xpm']
151 print "cannot find" , `file_name`
153 list_item (base
+ ext
, 'The input', 'ASCII')
156 for page
in range (1, 100):
157 f
= base
+ '-page%d.png' % page
159 if not os
.path
.isfile (f
):
162 list_item (f
, 'See a picture of page %d' % page
, 'png')
164 if pages_found
== 0 and os
.path
.exists (base
+ '.png'):
165 list_item (base
+ ".png",
166 'See a picture', 'png')
169 list_item (base
+ '.pdf', 'Print', 'PDF')
170 list_item (base
+ '.midi', 'Listen', 'MIDI')
171 list.write ('</ul>\n');
173 list.write ('</body></html>\n');
176 (options
, files
) = getopt
.getopt (sys
.argv
[1:],
177 'ho:', ['help', 'output='])
178 outfile
= 'examples.html'
184 if o
== '--help' or o
== '-h':
186 elif o
== '--output' or o
== '-o':
191 dirs
= dirs
+ find ('out-www', f
)
199 allfiles
= allfiles
+ find ('*.ly', d
)
201 allfiles
= filter (lambda x
: not x
.endswith ('snippet-map.ly') and not re
.search ('lily-[0-9a-f]+', x
), allfiles
)
203 gen_list (allfiles
, outfile
)