X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=buildscripts%2Fmutopia-index.py;h=50e4ebbf29b5b9355694937acbf228dde47fdd1e;hb=740a37e6b00957b32c0b49f3b876f455122f6821;hp=977226317d68daa2aaed526f68b37a758d2428d1;hpb=3ea3c436c65dc74a3d84c737f6497a8f63428796;p=lilypond.git
diff --git a/buildscripts/mutopia-index.py b/buildscripts/mutopia-index.py
index 977226317d..50e4ebbf29 100644
--- a/buildscripts/mutopia-index.py
+++ b/buildscripts/mutopia-index.py
@@ -1,30 +1,30 @@
-#!@PYTHON@
+#!/usr/bin/env python
# mutopia-index.py
import fnmatch
import getopt
import os
-import os
import re
import stat
import sys
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
+ f = os.popen ('find %s -name "%s"'% (dir, pat))
+ lst = []
+ for a in f.readlines():
+ a = a[:-1]
+ lst.append (a)
+ return lst
+junk_prefix = 'out-www/'
headertext= r"""
LilyPond samples
-
-You're looking at a page with some LilyPond samples. These files
+
+
You are 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.
@@ -35,167 +35,163 @@ For a good impression of the quality print out the PDF file.
"""
headertext_nopics= r"""
-
Nothing to be seen here, move along.
+
No examples were found in this directory.
"""
#
# 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)
+ dict = {}
+ m = re.search (r"""\\header\s*{([^}]*)}""", s)
- if m:
- s = m.group (1)
- else:
- return dict
+ if m:
+ s = m.group (1)
+ else:
+ return dict
- while s:
- m = re.search (r'''\s*(\S+)\s*=\s*"([^"]+)"''', s)
- if m == None:
- s = ''
- else:
- s = s[m.end (0):]
- left = m.group (1)
- right = m.group (2)
+ while s:
+ m = re.search (r'''\s*(\S+)\s*=\s*"([^"]+)"''', s)
+ if m == None:
+ s = ''
+ else:
+ s = s[m.end (0):]
+ left = m.group (1)
+ right = m.group (2)
- left = re.sub ('"', '', left)
- right = re.sub ('"', '', right)
- dict[left] = right
+ left = re.sub ('"', '', left)
+ right = re.sub ('"', '', right)
+ dict[left] = right
- return dict
+ return dict
def help ():
- sys.stdout.write (r'''Usage: mutopia-index [OPTIONS] INFILE OUTFILE
+ 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
- -s, --subdirs=DIR add subdir
- --suffix=SUF specify suffix
-
+ -h, --help print this help
+ -o, --output=FILE write output to file
+ -s, --subdirs=DIR add subdir
+ --suffix=SUF specify suffix
+
''')
- sys.exit (0)
+ sys.exit (0)
# ugh.
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 ('''
Rendered Examples
+ 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 ('''Rendered Examples
''')
- list.write ('\n')
-
- if inputs:
- list.write (headertext)
- else:
- 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
-
- 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 ('
\n')
- list.write ('%s
\n' % head);
- if composer:
- list.write ('%s
\n' % composer)
- if desc:
- list.write ('%s' % desc)
- list.write ('
\n')
-
- def list_item (file_name, desc, type, lst = list):
- if os.path.isfile (file_name):
- lst.write ('- %s'
- % (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']
- lst.write ('\n')
- else:
- print "can't find" , `file_name`
-
- list_item (base + ext, 'The input', 'ASCII')
-
- pages_found = 0
- for page in range (1, 100):
- f = base + '-page%d.png' % page
-
- if not os.path.isfile (f):
- break
- pages_found += 1
- list_item (f, 'See a picture of page %d' % page, 'png')
-
- if pages_found == 0 and os.path.exists (base + '.png'):
- list_item (base + ".png",
- 'See a picture', 'png')
-
-
- list_item (base + '.pdf', 'Print', 'PDF')
- list_item (base + '.midi', 'Listen', 'MIDI')
- list.write ('
\n');
-
- list.write ('\n');
- list.close ()
-
-(options, files) = getopt.getopt (sys.argv[1:],
- 'ho:', ['help', 'output='])
+ list.write ('\n')
+
+ if inputs:
+ list.write (headertext)
+ else:
+ 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
+
+ header = read_lilypond_header (ex)
+ head = header.get ('title', os.path.basename (base))
+ composer = header.get ('composer', '')
+ desc = header.get ('description', '')
+ list.write ('
\n')
+ list.write ('%s
\n' % head);
+ if composer:
+ list.write ('%s
\n' % composer)
+ if desc:
+ list.write ('%s' % desc)
+ list.write ('
\n')
+
+ def list_item (file_name, desc, type, lst = list):
+ if os.path.isfile (file_name):
+ lst.write ('- %s'
+ % (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']
+ lst.write ('\n')
+ else:
+ print "cannot find" , `file_name`
+
+ list_item (base + ext, 'The input', 'ASCII')
+
+ pages_found = 0
+ for page in range (1, 100):
+ f = base + '-page%d.png' % page
+
+ if not os.path.isfile (f):
+ break
+ pages_found += 1
+ list_item (f, 'See a picture of page %d' % page, 'png')
+
+ if pages_found == 0 and os.path.exists (base + '.png'):
+ list_item (base + ".png",
+ 'See a picture', 'png')
+
+
+ list_item (base + '.pdf', 'Print', 'PDF')
+ list_item (base + '.midi', 'Listen', 'MIDI')
+ list.write ('
\n');
+
+ list.write ('\n');
+ list.close ()
+
+(options, files) = getopt.getopt (sys.argv[1:],
+ 'ho:', ['help', 'output='])
outfile = 'examples.html'
subdirs = []
-for opt in options:
- o = opt[0]
- a = opt[1]
- if o == '--help' or o == '-h':
- help ()
- elif o == '--output' or o == '-o':
- outfile = a
+for (o, a) in options:
+ if o == '--help' or o == '-h':
+ help ()
+ elif o == '--output' or o == '-o':
+ outfile = a
dirs = []
for f in files:
- dirs = dirs + find ('out-www', f)
+ dirs += find ('out-www', f)
if not dirs:
- dirs = ['.']
+ dirs = ['.']
allfiles = []
for d in dirs:
- allfiles = allfiles + find ('*.ly.txt', d)
+ allfiles += find ('*.ly', d)
-gen_list (allfiles, outfile)
+allfiles = [f for f in allfiles
+ if not f.endswith ('snippet-map.ly')
+ and not re.search ('lily-[0-9a-f]+', f)
+ and 'musicxml' not in f]
+gen_list (allfiles, outfile)