]> git.donarmstrong.com Git - lilypond.git/blob - bin/mutopia-index.py
partial: 1.0.1.jcn
[lilypond.git] / bin / mutopia-index.py
1
2 import sys
3 import os
4
5 lilypath =''
6 try:
7     lilypath = os.environ['LILYPOND_SOURCEDIR'] + '/'
8 except KeyError:
9     print 'Please set LILYPOND_SOURCEDIR to the toplevel source, eg LILYPOND_SOURCEDIR=/home/foobar/lilypond-1.2.3/'
10     sys.exit(1)
11
12 lilypath = lilypath + '/bin/'
13 sys.path.append(lilypath)
14  
15 from lilypython import *
16
17
18
19 def gen_list(inputs, subdir, filename):
20     (pre, subdirs, post)=subdir
21     print "generating HTML list %s\n" % filename
22     list = open(filename, 'w')
23     list.write ('<html><TITLE>Rendered Examples</TITLE>\n')
24     list.write ('<body>')
25     if len(subdirs):
26         list.write  ('<h2>subdirectories</h2>')
27         list.write  ('<ul>')    
28         for ex in subdirs:
29             print 'subdir %s ' % ex
30             list.write ('<li><a href=%s/index.html>Subdirectory: %s</a></li>\n' % (pre + ex + post , ex))
31
32         list.write ('</ul>')
33
34     list.write('<h2>Contents of this directory</h2>\n');
35     list.write ('These example files are taken from the LilyPond distribution.\n'
36      'LilyPond currently only outputs TeX and MIDI. The pictures and\n'
37      'PostScript files were generated using TeX, Ghostscript and some\n'
38      'graphics tools.  The papersize used for these examples is A4.  The GIF\n'
39      'files have been scaled to eliminate aliasing.\n');
40
41
42     for ex in inputs:
43         print '%s, ' % ex
44         header  = read_mudela_header(ex + '.ly.txt')
45         
46         def read_dict(s, default, h =header):
47                 try:
48                     ret = h[s]
49                 except KeyError:
50                     ret = default
51                 return ret
52         head = read_dict('title', ex)
53         composer = read_dict('composer', '')
54         desc = read_dict('description', '')
55         list.write('<hr>')
56         list.write('<h1>example file: %s</h1>' % head);
57         if composer <> '':
58             list.write('<h2>%s</h2>\n' % composer)
59         if desc <> '':
60             list.write('%s<p>' % desc)
61         list.write ('<ul>')
62         def list_item(filename, desc, l = list):
63             if file_exist_b(filename):
64                 l.write ('<li><a href=%s>%s</a>\n' % (filename, desc))
65             
66         list_item(ex + '.ly.txt', 'The input')
67         for pageno in range(1,10):
68             f  = ex + '-page%d.gif' % pageno
69             if not file_exist_b (f):
70                 break
71             list_item(f, 'The output (picture, page %d)' % pageno)
72         list_item(ex + '.ps.gz', 'The output (gzipped PostScript)')
73         list_item(ex + '.midi', 'The output (MIDI)')
74         list.write ("</ul>");
75
76     list.write( "</BODY></HTML>");
77     list.close()
78
79 allfiles = multiple_find (['*.ly.txt'], '.')
80
81 import getopt
82
83 (cl_options, files) = getopt.getopt(sys.argv[1:], 
84                                     'hs:', ['help', 'subdirs=', 'suffix=', 'prefix='])
85 subdir_pre=''
86 subdir_suf =''
87
88 subdirs =[]
89 for opt in cl_options:
90     o = opt[0]
91     a = opt[1]
92     if o == '--subdirs' or o == '-s':
93         subdirs.append (a)
94     elif o == '--prefix':
95         subdir_pre = a
96     elif o == '--suffix':
97         subdir_suf = a
98         
99 gen_list (files, (subdir_pre, subdirs, subdir_suf), 'index.html')