10 sys.path.append ('@abs-step-bindir@')
14 header_regex = regex.compile('\\header[ \t\n]*{\([^}]*\)}')
15 header_entry_regex = regex.compile('[\n\t ]*\([^\n\t ]+\)[\n\t ]*=[\n \t]*\([^;]+\)[\n \t]*;')
18 # FIXME breaks on multiple strings.
20 def read_mudela_header (fn):
22 s = regsub.gsub('%.*$', '', s)
23 s = regsub.gsub('\n', ' ', s)
26 if header_regex.search(s) <> -1:
27 h = header_regex.group(1)
31 while regex.search('=', h) <> -1:
33 if header_entry_regex.search (h) == -1:
37 h = regsub.sub(header_entry_regex, '', h)
38 left = header_entry_regex.group(1)
39 right = header_entry_regex.group(2)
41 right = regsub.gsub('\([^\\]\)\"', '\\1', right)
42 right = regsub.gsub('^"', '', right)
43 left = regsub.gsub('\([^\\]\)\"', '', left)
44 left = regsub.gsub('^"', '', left)
54 sys.stdout.write ("Usage: " + name + " [options] INFILE OUTFILE\n"
55 + "Generate index for mutopia\n\n"
57 + " -h, --help print this help\n"
58 + " -p, --package=DIR specify package\n"
59 + " --prefix=PRE specify prefix\n"
60 + " -s, --subdirs=DIR add subdir\n"
61 + " --suffix=SUF specify suffix\n"
65 def gen_list(inputs, subdir, filename):
66 (pre, subdirs, post)=subdir
67 print "generating HTML list %s\n" % filename
68 list = open(filename, 'w')
69 list.write ('<html><TITLE>Rendered Examples</TITLE>\n')
70 list.write ('<body bgcolor=white>')
72 list.write ('<h2>subdirectories</h2>')
75 print 'subdir %s ' % ex
76 list.write ('<li><a href=%s/index.html>Subdirectory: %s</a></li>\n' % (pre + ex + post , ex))
80 list.write('<h2>Contents of this directory</h2>\n');
82 'These example files are taken from the LilyPond distribution. '
83 'LilyPond currently only outputs TeX and MIDI. The pictures and '
84 'PostScript files were generated using TeX, Ghostscript and some '
85 'graphics tools. The papersize used for these examples is A4. '
86 'As you know, <a href="http://www.gnu.org/philosophy/gif.html">no gifs due to patent problems</a>, '
87 'but the png images should be viewable with any current browser '
88 '(jpeg is inappropriate for music images).'
96 header = read_mudela_header(ex + ex_ext + '.txt')
99 header = read_mudela_header(ex + ex_ext + '.txt')
101 def read_dict(s, default, h =header):
107 head = read_dict('title', ex)
108 composer = read_dict('composer', '')
109 desc = read_dict('description', '')
111 list.write('<h1>example file: %s</h1>' % head);
113 list.write('<h2>%s</h2>\n' % composer)
115 list.write('%s<p>' % desc)
117 def list_item(filename, desc, type, l = list):
118 if file_exist_b(filename):
119 l.write ('<li><a href=%s>%s</a>' % (filename, desc))
120 size=os.stat(filename)[stat.ST_SIZE]
121 l.write (' (%s %dk)' % (type, (size + 512) / 1024))
122 pictures = ['jpeg', 'png', 'xpm']
124 if 0 and type in pictures:
125 l.write (' <a href="http://www.gnu.org/philosophy/gif.html">no gifs due to patent problems</a>')
127 list_item(ex + ex_ext + '.txt', 'The input', 'ASCII')
128 for pageno in range(1,100):
129 f = ex + '-page%d.png' % pageno
130 if not file_exist_b (f):
132 list_item(f, 'The output, page %d' % pageno, 'png')
133 list_item(ex + '.ps.gz', 'The output', 'gzipped PostScript')
134 list_item(ex + '.midi', 'The output', 'MIDI')
135 list.write ("</ul>");
137 list.write( "</BODY></HTML>");
142 (options, files) = getopt.getopt(sys.argv[1:],
143 'hp:s:', ['help', 'subdirs=', 'suffix=', 'package=', 'prefix='])
151 if o == '--subdirs' or o == '-s':
153 elif o == '--prefix':
155 elif o == '-p' or o == '--package':
157 elif o == '--suffix':
160 sys.path.append (topdir + '/stepmake/bin')
161 from packagepython import *
162 package = Package (topdir)
163 packager = Packager ()
169 allfiles = multiple_find (['*.*ly.txt'], '.')
171 gen_list (files, (subdir_pre, subdirs, subdir_suf), 'index.html')