10 sys.path.append ('@abs-step-bindir@')
18 header_regex = regex.compile('\\header[ \t\n]*{\([^}]*\)}')
19 header_entry_regex = regex.compile('[\n\t ]*\([^\n\t ]+\)[\n\t ]*=[\n \t]*\([^;]+\)[\n \t]*;')
22 These example files are taken from the LilyPond distribution.
23 LilyPond currently only outputs TeX and MIDI. The pictures and
24 PostScript files were generated using TeX, Ghostscript and some
25 graphics tools. The papersize used for these examples is A4.
26 The images are in PNG format, and should be viewable with any current browser.
27 We don't use GIFS due to <a href="http://www.gnu.org/philosophy/gif.html">patent problems</a>.
29 If you want an accurate impression of the output quality please <em>print
30 out</em> the samples first.
33 headertext_nopics = r"""This is a subdirectory of the LilyPond example
34 set. We decided not to show any examples from this directory. If you
35 want to view them, then you have to download LilyPond and compile them
40 # FIXME breaks on multiple strings.
42 def read_mudela_header (fn):
44 s = regsub.gsub('%.*$', '', s)
45 s = regsub.gsub('\n', ' ', s)
48 if header_regex.search(s) <> -1:
49 h = header_regex.group(1)
53 while regex.search('=', h) <> -1:
55 if header_entry_regex.search (h) == -1:
59 h = regsub.sub(header_entry_regex, '', h)
60 left = header_entry_regex.group(1)
61 right = header_entry_regex.group(2)
63 right = regsub.gsub('\([^\\]\)\"', '\\1', right)
64 right = regsub.gsub('^"', '', right)
65 left = regsub.gsub('\([^\\]\)\"', '', left)
66 left = regsub.gsub('^"', '', left)
76 sys.stdout.write ("Usage: " + name + " [options] INFILE OUTFILE\n"
77 + "Generate index for mutopia\n\n"
79 + " -h, --help print this help\n"
80 + " -p, --package=DIR specify package\n"
81 + " --prefix=PRE specify prefix\n"
82 + " -s, --subdirs=DIR add subdir\n"
83 + " --suffix=SUF specify suffix\n"
87 def gen_list(inputs, subdir, filename):
88 (pre, subdirs, post)=subdir
89 print "generating HTML list %s\n" % filename
90 list = open(filename, 'w')
91 list.write ('<html><TITLE>Rendered Examples</TITLE>\n')
92 list.write ('<body bgcolor=white>')
94 list.write ('<h2>subdirectories</h2>')
97 print 'subdir %s ' % ex
98 list.write ('<li><a href=%s/index.html>Subdirectory: %s</a></li>\n' % (pre + ex + post , ex))
105 list.write('<h2>Contents of this directory</h2>\n');
107 list.write (headertext)
109 list.write (headertext_nopics)
116 header = read_mudela_header(ex + ex_ext + '.txt')
119 header = read_mudela_header(ex + ex_ext + '.txt')
121 def read_dict(s, default, h =header):
127 head = read_dict('title', ex)
128 composer = read_dict('composer', '')
129 desc = read_dict('description', '')
131 list.write('<h1>example file: %s</h1>' % head);
133 list.write('<h2>%s</h2>\n' % composer)
135 list.write('%s<p>' % desc)
137 def list_item(filename, desc, type, l = list):
138 if file_exist_b(filename):
139 l.write ('<li><a href=%s>%s</a>' % (filename, desc))
140 size=os.stat(filename)[stat.ST_SIZE]
141 l.write (' (%s %dk)' % (type, (size + 512) / 1024))
142 pictures = ['jpeg', 'png', 'xpm']
144 if 0 and type in pictures:
145 l.write (' <a href="http://www.gnu.org/philosophy/gif.html">no gifs due to patent problems</a>')
147 list_item(ex + ex_ext + '.txt', 'The input', 'ASCII')
148 for pageno in range(1,100):
149 f = ex + '-page%d.png' % pageno
150 if not file_exist_b (f):
152 list_item(f, 'The output, page %d' % pageno, 'png')
153 list_item(ex + '.ps.gz', 'The output', 'gzipped PostScript')
154 list_item(ex + '.midi', 'The output', 'MIDI')
155 list.write ("</ul>");
157 list.write( "</BODY></HTML>");
162 (options, files) = getopt.getopt(sys.argv[1:],
163 'hp:s:', ['help', 'subdirs=', 'suffix=', 'package=', 'prefix='])
171 if o == '--subdirs' or o == '-s':
173 elif o == '--prefix':
175 elif o == '-p' or o == '--package':
177 elif o == '--suffix':
180 sys.path.append (topdir + '/stepmake/bin')
181 from packagepython import *
182 package = Package (topdir)
183 packager = Packager ()
189 allfiles = multiple_find (['*.*ly.txt'], '.')
191 gen_list (files, (subdir_pre, subdirs, subdir_suf), 'index.html')