]> git.donarmstrong.com Git - lilypond.git/blobdiff - buildscripts/mutopia-index.py
* buildscripts/pfx2ttf.fontforge: remove No. glyph from TTF file.
[lilypond.git] / buildscripts / mutopia-index.py
old mode 100755 (executable)
new mode 100644 (file)
index 4cb45ea..8b02ea4
@@ -1,85 +1,62 @@
 #!@PYTHON@
 # mutopia-index.py
 
-name = 'mutopia-index'
-
-# find.py -- deprecated in python 2.0
 import fnmatch
+import getopt
 import os
-
-_debug = 0
-
-_prune = ['(*)']
-
-def find(pattern, dir = os.curdir):
-        list = []
-        names = os.listdir(dir)
-        names.sort()
-        for name in names:
-                if name in (os.curdir, os.pardir):
-                        continue
-                fullname = os.path.join(dir, name)
-                if fnmatch.fnmatch(name, pattern):
-                        list.append(fullname)
-                if os.path.isdir(fullname) and not os.path.islink(fullname):
-                        for p in _prune:
-                                if fnmatch.fnmatch(name, p):
-                                        if _debug: print "skip", `fullname`
-                                        break
-                        else:
-                                if _debug: print "descend into", `fullname`
-                                list = list + find(pattern, fullname)
-        return list
-
-
-import re
 import os
-import sys
+import re
 import stat
+import sys
 
-def gulp_file (fn):
-       try:
-               f = open (fn)
-       except:
-               raise 'not there' , fn
-       return f.read ()
+def find (pat, dir):
+       f = os.popen ('find %s -name "%s"'% (dir, pat))
+       lst = []
+       for a in f.readlines():
+               a = a[:-1]
+               lst.append (a)
+       return lst
 
-def file_exist_b (fn):
-       try:
-               f = open (fn)
-               return 1
-       except:
-               return 0
 
+junk_prefix = 'out-www/'
 
 headertext= r"""
-These example files are taken from the LilyPond distribution. 
-LilyPond currently only outputs TeX and MIDI.  The pictures and 
-PostScript files were generated using TeX, Ghostscript and some 
-graphics tools.         The papersize used for these examples is A4. 
-The  images are in PNG format, and should be viewable with any current browser.
+
+<h1>LilyPond samples</h1>
+
+<p>You're looking at a page with some LilyPond samples.  These files
+are also included in the distribution. The output is completely
+generated from the source file, without any further touch up.
+
 <p>
-These images are generated at approximately 180dpi. If you want a better impression of the appearance do print out one the postscript version of the samples."""
 
+The pictures are 90 dpi anti-aliased snapshots of the printed output.
+For a good impression of the quality print out the PDF file.
+"""
+
+headertext_nopics= r"""
+<p>Nothing to be seen here, move along.
+"""
 
 #
 # FIXME breaks on multiple strings.
 #
 def read_lilypond_header (fn):
-       s = open(fn).read ()
-       s = re.sub('%.*$', '', s)
-       s = re.sub('\n', ' ', s)                
+       s = open (fn).read ()
+       s = re.sub ('%.*$', '', s)
+       s = re.sub ('\n', ' ', s)               
 
        dict = {}
        m = re.search (r"""\\header\s*{([^}]*)}""", s)
 
        if m:
-                       s = m.group(1)
+                       s = m.group (1)
        else:
                        return dict
 
        while s:
-               m = re.search (r"""\s*(\S+)\s*=\s*([^;]+)\s*;""", s)
+               m = re.search (r'''\s*(\S+)\s*=\s*"([^"]+)"''', s)
                if m == None:
                        s = ''
                else:
@@ -94,89 +71,118 @@ def read_lilypond_header (fn):
        return dict
 
 def help ():
-       sys.stdout.write (r"""Usage: mutopia-index [options] INFILE OUTFILE
-Generate index for mutopia\n
+       sys.stdout.write (r'''Usage: mutopia-index [OPTIONS] INFILE OUTFILE
+Generate index for mutopia.
+
 Options:
   -h, --help                 print this help
-  -o,-output=FILE            write output to file.
+  -o, --output=FILE          write output to file
   -s, --subdirs=DIR         add subdir
-  --suffix=SUF                  specify suffix"""
-                                         )
+      --suffix=SUF          specify suffix
+      
+''')
        sys.exit (0)
 
 # ugh.
-def gen_list(inputs, filename):
-       print "generating HTML list %s\n" % filename
-       if filename:
-               list = open(filename, 'w')
+def gen_list (inputs, file_name):
+       sys.stderr.write ("generating HTML list %s" % file_name)
+       sys.stderr.write ('\n')
+       if file_name:
+               list = open (file_name, 'w')
        else:
                list = sys.stdout
-       list.write ('<html><TITLE>Rendered Examples</TITLE>\n')
-       list.write ('<body bgcolor=white>')
+       list.write ('''<html><head><title>Rendered Examples</title>
+<style type="text/css">
+hr { border:0; height:1; color: #000000; background-color: #000000; }\n
+</style>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+</head>''')
+
+       list.write ('<body bgcolor=white>\n')
        
        if inputs:
-                       list.write (headertext)
+               list.write (headertext)
        else:
-                       list.write (headertext_nopics)
-
+               list.write (headertext_nopics)
 
        for ex in inputs:
+               print ex
+               
                (base, ext) = os.path.splitext (ex)
                (base, ext2) = os.path.splitext (base)          
                ext = ext2 + ext
                
-               print '%s, ' % ex
-               header = read_lilypond_header(ex)
-               
-               def read_dict(s, default, h =header):
+               header = read_lilypond_header (ex)
+               def read_dict (s, default, h = header):
                                try:
                                        ret = h[s]
                                except KeyError:
                                        ret = default
                                return ret
-               head = read_dict('title', os.path.basename (base))
-               composer = read_dict('composer', '')
-               desc = read_dict('description', '')
-               list.write('<hr>')
-               list.write('<h1>example file: %s</h1>' % head);
-               if composer <> '':
-                       list.write('<h2>%s</h2>\n' % composer)
-               if desc <> '':
-                       list.write('%s<p>' % desc)
-               list.write ('<ul>')
-               def list_item(filename, desc, type, l = list):
-                       if file_exist_b(filename):
-                               l.write ('<li><a href=%s>%s</a>' % (filename, desc))
-                               size=os.stat(filename)[stat.ST_SIZE]
-                               l.write (' (%s %dk)' % (type, (size + 512) / 1024))
+               head = read_dict ('title', os.path.basename (base))
+               composer = read_dict ('composer', '')
+               desc = read_dict ('description', '')
+               list.write ('<hr>\n')
+               list.write ('<h1>%s</h1>\n' % head);
+               if composer:
+                       list.write ('<h2>%s</h2>\n' % composer)
+               if desc:
+                       list.write ('%s<p>' % desc)
+               list.write ('<ul>\n')
+
+               def list_item (file_name, desc, type, lst = list):
+                       if os.path.isfile (file_name):
+                               lst.write ('<li><a href="%s">%s</a>'
+                                          % (re.sub (junk_prefix, '', file_name), desc))
+
+                               # FIXME: include warning if it uses \include
+                               # files.
+                               
+                               size = os.stat (file_name)[stat.ST_SIZE]
+                               kB = (size + 512) / 1024
+                               if kB:
+                                       lst.write (' (%s %d kB)' % (type, kB))
+                               else:
+                                       lst.write (' (%s %d characters)'
+                                                  % (type, size))
                                pictures = ['jpeg', 'png', 'xpm']
-                               l.write ('\n')
+                               lst.write ('\n')
+                       else:
+                               print "can't find" , `file_name`
+
+               list_item (base + ext, 'The input', 'ASCII')
 
-               list_item(base + ext, 'The input', 'ASCII')
-               for pageno in range(1,100):
-                       f  = base + '-page%d.png' % pageno
-                       if not file_exist_b (f):
+               pages_found = 0
+               for page in range (1, 100):
+                       f = base + '-page%d.png' % page
+                       
+                       if not os.path.isfile (f):
                                break
-                       list_item(f, 'The output, page %d' % pageno, 'png')
-               list_item(base + '.ps.gz', 'The output', 'gzipped PostScript')
-               list_item(base + '.midi', 'The output', 'MIDI')
-               list.write ("</ul>");
+                       pages_found += 1
+                       list_item (f, 'See a picture of page %d' % page, 'png')
 
-       list.write( "</BODY></HTML>");
-       list.close()
+               if pages_found == 0 and os.path.exists (base + '.png'):
+                       list_item (base + ".png",
+                                  'See a picture', 'png')
 
-import getopt
+                       
+               list_item (base + '.pdf', 'Print', 'PDF')
+               list_item (base + '.midi', 'Listen', 'MIDI')
+               list.write ('</ul>\n');
 
-(options, files) = getopt.getopt(sys.argv[1:], 
+       list.write ('</body></html>\n');
+       list.close ()
+
+(options, files) = getopt.getopt (sys.argv[1:], 
   'ho:', ['help', 'output='])
 outfile = 'examples.html'
 
-subdirs =[]
+subdirs = []
 for opt in options:
        o = opt[0]
        a = opt[1]
        if o == '--help' or o == '-h':
-               help()
+               help ()
        elif o == '--output' or o == '-o':
                outfile = a
 
@@ -192,7 +198,5 @@ allfiles = []
 for d in dirs:
        allfiles = allfiles + find ('*.ly.txt', d)
 
-print allfiles
-
 gen_list (allfiles, outfile)