6 # find.py -- deprecated in python 2.0
14 def find(pattern
, dir = os
.curdir
):
16 names
= os
.listdir(dir)
19 if name
in (os
.curdir
, os
.pardir
):
21 fullname
= os
.path
.join(dir, name
)
22 if fnmatch
.fnmatch(name
, pattern
):
24 if os
.path
.isdir(fullname
) and not os
.path
.islink(fullname
):
26 if fnmatch
.fnmatch(name
, p
):
27 if _debug
: print "skip", `fullname`
30 if _debug
: print "descend into", `fullname`
31 list = list + find(pattern
, fullname
)
44 raise 'not there' , fn
47 def file_exist_b (fn
):
56 <p>You're looking at a page with some LilyPond samples.
57 These files are also included in the distribution. The output is
58 completely generated by LilyPond, without any touch up by humans.
60 <p>The PostScript files were generated using TeX and dvips. The pictures
61 are 90dpi anti-aliased snapshots of the printed output. The images
62 are in PNG format, and should be viewable with any current browser.
64 <p>If you want a better impression of the appearance, do print out one of
70 # FIXME breaks on multiple strings.
72 def read_lilypond_header (fn
):
74 s
= re
.sub('%.*$', '', s
)
75 s
= re
.sub('\n', ' ', s
)
78 m
= re
.search (r
"""\\header\s*{([^}]*)}""", s
)
86 m
= re
.search (r
"""\s*(\S+)\s*=\s*([^;]+)\s*;""", s
)
94 left
= re
.sub ('"', '', left
)
95 right
= re
.sub ('"', '', right
)
101 sys
.stdout
.write (r
"""Usage: mutopia-index [options] INFILE OUTFILE
102 Generate index for mutopia\n
104 -h, --help print this help
105 -o,-output=FILE write output to file.
106 -s, --subdirs=DIR add subdir
107 --suffix=SUF specify suffix"""
112 def gen_list(inputs
, filename
):
113 print "generating HTML list %s\n" % filename
115 list = open(filename
, 'w')
118 list.write ('<html><title>Rendered Examples</title>\n')
119 list.write ('<body bgcolor=white>\n')
122 list.write (headertext
)
124 list.write (headertext_nopics
)
128 (base
, ext
) = os
.path
.splitext (ex
)
129 (base
, ext2
) = os
.path
.splitext (base
)
133 header
= read_lilypond_header(ex
)
135 def read_dict(s
, default
, h
=header
):
141 head
= read_dict('title', os
.path
.basename (base
))
142 composer
= read_dict('composer', '')
143 desc
= read_dict('description', '')
145 list.write('<h1>example file: %s</h1>\n' % head
);
147 list.write('<h2>%s</h2>\n' % composer
)
149 list.write('%s<p>' % desc
)
150 list.write ('<ul>\n')
151 def list_item(filename
, desc
, type, l
= list):
152 if file_exist_b(filename
):
153 l
.write ('<li><a href="%s">%s</a>' % (filename
, desc
))
154 size
=os
.stat(filename
)[stat
.ST_SIZE
]
155 l
.write (' (%s %dk)' % (type, (size
+ 512) / 1024))
156 pictures
= ['jpeg', 'png', 'xpm']
159 list_item(base
+ ext
, 'The input', 'ASCII')
160 for pageno
in range(1,100):
161 f
= base
+ '-page%d.png' % pageno
162 if not file_exist_b (f
):
164 list_item(f
, 'See a picture of page %d' % pageno
, 'png')
165 list_item(base
+ '.ps.gz', 'Print ', 'gzipped PostScript')
166 list_item(base
+ '.midi', 'Listen', 'MIDI')
167 list.write ("</ul>\n");
169 list.write('</body></html>\n');
174 (options
, files
) = getopt
.getopt(sys
.argv
[1:],
175 'ho:', ['help', 'output='])
176 outfile
= 'examples.html'
182 if o
== '--help' or o
== '-h':
184 elif o
== '--output' or o
== '-o':
189 dirs
= dirs
+ find ('out-www', f
)
197 allfiles
= allfiles
+ find ('*.ly.txt', d
)
201 gen_list (allfiles
, outfile
)