13 def find(pattern, dir = os.curdir):
15 names = os.listdir(dir)
18 if name in (os.curdir, os.pardir):
20 fullname = os.path.join(dir, name)
21 if fnmatch.fnmatch(name, pattern):
23 if os.path.isdir(fullname) and not os.path.islink(fullname):
25 if fnmatch.fnmatch(name, p):
26 if _debug: print "skip", `fullname`
29 if _debug: print "descend into", `fullname`
30 list = list + find(pattern, fullname)
43 raise 'not there' , fn
46 def file_exist_b (fn):
56 <p>You're looking at a page with some LilyPond samples. These files
57 are also included in the distribution. The output is completely
58 generated from the <tt>.ly</tt> source file, without any further touch
63 The pictures are 90 dpi anti-aliased snapshots of the printed output.
64 If you want a better impression of the appearance, do print out one of
65 the PDF or PostScript files; they use scalable fonts, and should look
66 good at any resolution.
70 headertext_nopics= r"""
71 <p>Nothing to be seen here, move along.
75 # FIXME breaks on multiple strings.
77 def read_lilypond_header (fn):
79 s = re.sub('%.*$', '', s)
80 s = re.sub('\n', ' ', s)
83 m = re.search (r"""\\header\s*{([^}]*)}""", s)
91 m = re.search (r'''\s*(\S+)\s*=\s*"([^"]+)"''', s)
99 left = re.sub ('"', '', left)
100 right = re.sub ('"', '', right)
106 sys.stdout.write (r"""Usage: mutopia-index [OPTIONS] INFILE OUTFILE
107 Generate index for mutopia.
110 -h, --help print this help
111 -o, --output=FILE write output to file
112 -s, --subdirs=DIR add subdir
113 --suffix=SUF specify suffix
120 def gen_list(inputs, filename):
121 print "generating HTML list %s\n" % filename
123 list = open(filename, 'w')
126 list.write ('<html><head><title>Rendered Examples</title>\n')
127 list.write ('<style type="text/css">\n')
128 list.write ('hr { border:0; height:1; color: #000000; background-color: #000000; }\n')
129 list.write ('</style></head>\n')
131 list.write ('<body bgcolor=white>\n')
134 list.write (headertext)
136 list.write (headertext_nopics)
140 (base, ext) = os.path.splitext (ex)
141 (base, ext2) = os.path.splitext (base)
144 header = read_lilypond_header(ex)
145 def read_dict(s, default, h =header):
151 head = read_dict('title', os.path.basename (base))
152 composer = read_dict('composer', '')
153 desc = read_dict('description', '')
155 list.write('<h1>%s</h1>\n' % head);
157 list.write('<h2>%s</h2>\n' % composer)
159 list.write('%s<p>' % desc)
160 list.write ('<ul>\n')
161 def list_item(filename, desc, type, l = list):
162 if file_exist_b(filename):
164 l.write ('<li><a href="%s">%s</a>' % (filename, desc))
166 # todo: include warning if it uses \include
169 size=os.stat(filename)[stat.ST_SIZE]
170 kB=(size + 512) / 1024
172 l.write (' (%s %d kB)' % (type, kB))
174 l.write (' (%s %d characters)' % (type, size))
175 pictures = ['jpeg', 'png', 'xpm']
178 list_item(base + ext, 'The input', 'ASCII')
179 for pageno in range(1,100):
180 f = base + '-page%d.png' % pageno
181 if not file_exist_b (f):
183 list_item(f, 'See a picture of page %d' % pageno, 'png')
184 list_item(base + '.pdf', 'Print', 'PDF')
185 list_item(base + '.midi', 'Listen', 'MIDI')
186 list.write ("</ul>\n");
188 list.write('</body></html>\n');
193 (options, files) = getopt.getopt(sys.argv[1:],
194 'ho:', ['help', 'output='])
195 outfile = 'examples.html'
201 if o == '--help' or o == '-h':
203 elif o == '--output' or o == '-o':
208 dirs = dirs + find ('out-www', f)
216 allfiles = allfiles + find ('*.ly.txt', d)
218 gen_list (allfiles, outfile)