9 sys.path.append ('@abs-step-bindir@')
13 header_regex = regex.compile('\\header[ \t\n]*{\([^}]*\)}')
14 header_entry_regex = regex.compile('[\n\t ]*\([^\n\t ]+\)[\n\t ]*=[\n \t]*\([^;]+\)[\n \t]*;')
17 # FIXME breaks on multiple strings.
19 def read_mudela_header (fn):
21 s = regsub.gsub('%.*$', '', s)
22 s = regsub.gsub('\n', ' ', s)
25 if header_regex.search(s) <> -1:
26 h = header_regex.group(1)
30 while regex.search('=', h) <> -1:
32 if header_entry_regex.search (h) == -1:
36 h = regsub.sub(header_entry_regex, '', h)
37 left = header_entry_regex.group(1)
38 right = header_entry_regex.group(2)
40 right = regsub.gsub('\([^\\]\)\"', '\\1', right)
41 right = regsub.gsub('^"', '', right)
42 left = regsub.gsub('\([^\\]\)\"', '', left)
43 left = regsub.gsub('^"', '', left)
53 sys.stdout.write ("Usage: " + name + " [options] INFILE OUTFILE\n"
54 + "Generate index for mutopia\n\n"
56 + " -h, --help print this help\n"
57 + " -p, --package=DIR specify package\n"
58 + " --prefix=PRE specify prefix\n"
59 + " -s, --subdirs=DIR add subdir\n"
60 + " --suffix=SUF specify suffix\n"
64 def gen_list(inputs, subdir, filename):
65 (pre, subdirs, post)=subdir
66 print "generating HTML list %s\n" % filename
67 list = open(filename, 'w')
68 list.write ('<html><TITLE>Rendered Examples</TITLE>\n')
69 list.write ('<body bgcolor=white>')
71 list.write ('<h2>subdirectories</h2>')
74 print 'subdir %s ' % ex
75 list.write ('<li><a href=%s/index.html>Subdirectory: %s</a></li>\n' % (pre + ex + post , ex))
79 list.write('<h2>Contents of this directory</h2>\n');
80 list.write ('These example files are taken from the LilyPond distribution.\n'
81 'LilyPond currently only outputs TeX and MIDI. The pictures and\n'
82 'PostScript files were generated using TeX, Ghostscript and some\n'
83 'graphics tools. The papersize used for these examples is A4. The GIF\n'
84 'files have been scaled to eliminate aliasing.\n');
91 header = read_mudela_header(ex + ex_ext + '.txt')
94 header = read_mudela_header(ex + ex_ext + '.txt')
96 def read_dict(s, default, h =header):
102 head = read_dict('title', ex)
103 composer = read_dict('composer', '')
104 desc = read_dict('description', '')
106 list.write('<h1>example file: %s</h1>' % head);
108 list.write('<h2>%s</h2>\n' % composer)
110 list.write('%s<p>' % desc)
112 def list_item(filename, desc, l = list):
113 if file_exist_b(filename):
114 l.write ('<li><a href=%s>%s</a>\n' % (filename, desc))
116 list_item(ex + ex_ext + '.txt', 'The input')
117 for pageno in range(1,100):
118 f = ex + '-page%d.gif' % pageno
119 if not file_exist_b (f):
121 list_item(f, 'The output (picture, page %d)' % pageno)
122 list_item(ex + '.ps.gz', 'The output (gzipped PostScript)')
123 list_item(ex + '.midi', 'The output (MIDI)')
124 list.write ("</ul>");
126 list.write( "</BODY></HTML>");
131 (options, files) = getopt.getopt(sys.argv[1:],
132 'hp:s:', ['help', 'subdirs=', 'suffix=', 'package=', 'prefix='])
140 if o == '--subdirs' or o == '-s':
142 elif o == '--prefix':
144 elif o == '-p' or o == '--package':
146 elif o == '--suffix':
149 sys.path.append (topdir + '/stepmake/bin')
150 from packagepython import *
151 package = Package (topdir)
152 packager = Packager ()
158 allfiles = multiple_find (['*.*ly.txt'], '.')
160 gen_list (files, (subdir_pre, subdirs, subdir_suf), 'index.html')