New glyph (black diamond) and two harmonic-like notehead styles using it.
[lilypond.git] / buildscripts / mutopia-index.py
blobc73481aabad094643f2451c76a230d1efd92aa35
1 #!@PYTHON@
2 # mutopia-index.py
4 import fnmatch
5 import getopt
6 import os
7 import os
8 import re
9 import stat
10 import sys
12 def find (pat, dir):
13 f = os.popen ('find %s -name "%s"'% (dir, pat))
14 lst = []
15 for a in f.readlines():
16 a = a[:-1]
17 lst.append (a)
18 return lst
21 junk_prefix = 'out-www/'
23 headertext= r"""
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.
32 <p>
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.
36 """
38 headertext_nopics= r"""
39 <p>No examples were found in this directory.
40 """
43 # FIXME breaks on multiple strings.
45 def read_lilypond_header (fn):
46 s = open (fn).read ()
47 s = re.sub ('%.*$', '', s)
48 s = re.sub ('\n', ' ', s)
50 dict = {}
51 m = re.search (r"""\\header\s*{([^}]*)}""", s)
53 if m:
54 s = m.group (1)
55 else:
56 return dict
58 while s:
59 m = re.search (r'''\s*(\S+)\s*=\s*"([^"]+)"''', s)
60 if m == None:
61 s = ''
62 else:
63 s = s[m.end (0):]
64 left = m.group (1)
65 right = m.group (2)
67 left = re.sub ('"', '', left)
68 right = re.sub ('"', '', right)
69 dict[left] = right
71 return dict
73 def help ():
74 sys.stdout.write (r'''Usage: mutopia-index [OPTIONS] INFILE OUTFILE
75 Generate index for mutopia.
77 Options:
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
83 ''')
84 sys.exit (0)
86 # ugh.
87 def gen_list (inputs, file_name):
88 sys.stderr.write ("generating HTML list %s" % file_name)
89 sys.stderr.write ('\n')
90 if file_name:
91 list = open (file_name, 'w')
92 else:
93 list = sys.stdout
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
97 </style>
98 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
99 </head>''')
101 list.write ('<body bgcolor=white>\n')
103 if inputs:
104 list.write (headertext)
105 else:
106 list.write (headertext_nopics)
108 for ex in inputs:
109 print ex
111 (base, ext) = os.path.splitext (ex)
112 (base, ext2) = os.path.splitext (base)
113 ext = ext2 + ext
115 header = read_lilypond_header (ex)
116 def read_dict (s, default, h = header):
117 try:
118 ret = h[s]
119 except KeyError:
120 ret = default
121 return ret
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);
127 if composer:
128 list.write ('<h2>%s</h2>\n' % composer)
129 if desc:
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
139 # files.
141 size = os.stat (file_name)[stat.ST_SIZE]
142 kB = (size + 512) / 1024
143 if kB:
144 lst.write (' (%s %d kB)' % (type, kB))
145 else:
146 lst.write (' (%s %d characters)'
147 % (type, size))
148 pictures = ['jpeg', 'png', 'xpm']
149 lst.write ('\n')
150 else:
151 print "cannot find" , `file_name`
153 list_item (base + ext, 'The input', 'ASCII')
155 pages_found = 0
156 for page in range (1, 100):
157 f = base + '-page%d.png' % page
159 if not os.path.isfile (f):
160 break
161 pages_found += 1
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');
174 list.close ()
176 (options, files) = getopt.getopt (sys.argv[1:],
177 'ho:', ['help', 'output='])
178 outfile = 'examples.html'
180 subdirs = []
181 for opt in options:
182 o = opt[0]
183 a = opt[1]
184 if o == '--help' or o == '-h':
185 help ()
186 elif o == '--output' or o == '-o':
187 outfile = a
189 dirs = []
190 for f in files:
191 dirs = dirs + find ('out-www', f)
193 if not dirs:
194 dirs = ['.']
196 allfiles = []
198 for d in dirs:
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)