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 These example files are taken from the LilyPond distribution.
57 LilyPond currently only outputs TeX and MIDI. The pictures and
58 PostScript files were generated using TeX, Ghostscript and some
59 graphics tools. The papersize used for these examples is A4.
60 The images are in PNG format, and should be viewable with any current browser.
62 These images are generated at approximately 180dpi. If you want a better impression of the appearance do print out one the postscript version of the samples."""
66 # FIXME breaks on multiple strings.
68 def read_lilypond_header (fn):
70 s = re.sub('%.*$', '', s)
71 s = re.sub('\n', ' ', s)
74 m = re.search (r"""\\header\s*{([^}]*)}""", s)
82 m = re.search (r"""\s*(\S+)\s*=\s*([^;]+)\s*;""", s)
90 left = re.sub ('"', '', left)
91 right = re.sub ('"', '', right)
97 sys.stdout.write (r"""Usage: mutopia-index [options] INFILE OUTFILE
98 Generate index for mutopia\n
100 -h, --help print this help
101 -o,-output=FILE write output to file.
102 -s, --subdirs=DIR add subdir
103 --suffix=SUF specify suffix"""
108 def gen_list(inputs, filename):
109 print "generating HTML list %s\n" % filename
111 list = open(filename, 'w')
114 list.write ('<html><TITLE>Rendered Examples</TITLE>\n')
115 list.write ('<body bgcolor=white>')
118 list.write (headertext)
120 list.write (headertext_nopics)
124 (base, ext) = os.path.splitext (ex)
125 (base, ext2) = os.path.splitext (base)
129 header = read_lilypond_header(ex)
131 def read_dict(s, default, h =header):
137 head = read_dict('title', os.path.basename (base))
138 composer = read_dict('composer', '')
139 desc = read_dict('description', '')
141 list.write('<h1>example file: %s</h1>' % head);
143 list.write('<h2>%s</h2>\n' % composer)
145 list.write('%s<p>' % desc)
147 def list_item(filename, desc, type, l = list):
148 if file_exist_b(filename):
149 l.write ('<li><a href=%s>%s</a>' % (filename, desc))
150 size=os.stat(filename)[stat.ST_SIZE]
151 l.write (' (%s %dk)' % (type, (size + 512) / 1024))
152 pictures = ['jpeg', 'png', 'xpm']
155 list_item(base + ext, 'The input', 'ASCII')
156 for pageno in range(1,100):
157 f = base + '-page%d.png' % pageno
158 if not file_exist_b (f):
160 list_item(f, 'The output, page %d' % pageno, 'png')
161 list_item(base + '.ps.gz', 'The output', 'gzipped PostScript')
162 list_item(base + '.midi', 'The output', 'MIDI')
163 list.write ("</ul>");
165 list.write( "</BODY></HTML>");
170 (options, files) = getopt.getopt(sys.argv[1:],
171 'ho:', ['help', 'output='])
172 outfile = 'examples.html'
178 if o == '--help' or o == '-h':
180 elif o == '--output' or o == '-o':
185 dirs = dirs + find ('out-www', f)
193 allfiles = allfiles + find ('*.ly.txt', d)
197 gen_list (allfiles, outfile)