X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=buildscripts%2Fmutopia-index.py;h=399ee211a2303b6be6b4c51d376e53c9efdd7741;hb=fd58a98a46a3def26b80a895f1f7b81c92590fc3;hp=a4c4652b92869e5024bc40a9978941110f0a0466;hpb=151617937a431d3db3e94a16db011600acdb4288;p=lilypond.git diff --git a/buildscripts/mutopia-index.py b/buildscripts/mutopia-index.py index a4c4652b92..399ee211a2 100644 --- a/buildscripts/mutopia-index.py +++ b/buildscripts/mutopia-index.py @@ -3,159 +3,214 @@ name = 'mutopia-index' -import regex +import fnmatch +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 -sys.path.append ('@abs-step-bindir@') +import stat +def gulp_file (fn): + try: + f = open (fn) + except: + raise 'not there' , fn + return f.read () +def file_exist_b (fn): + try: + f = open (fn) + return 1 + except: + return 0 -header_regex = regex.compile('\\header[ \t\n]*{\([^}]*\)}') -header_entry_regex = regex.compile('[\n\t ]*\([^\n\t ]+\)[\n\t ]*=[\n \t]*\([^;]+\)[\n \t]*;') -# -# FIXME breaks on multiple strings. -# -def read_mudela_header (fn): - s = gulp_file(fn) - s = regsub.gsub('%.*$', '', s) - s = regsub.gsub('\n', ' ', s) +headertext= r""" - dict = {} - if header_regex.search(s) <> -1: - h = header_regex.group(1) - else: - return dict +

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 .ly source file, without any further touch +up. - while regex.search('=', h) <> -1: +

The PostScript files were generated using TeX and dvips at 600 dpi. +The pictures are 90 dpi anti-aliased snapshots of the printed output. +The images are in PNG format, and should be viewable with any current +browser. - if header_entry_regex.search (h) == -1: +

If you want a better impression of the appearance, do print out one of +the postscript files. +""" - raise 'format error' +headertext_nopics= r""" +

Nothing to be seen here, move along. +""" - h = regsub.sub(header_entry_regex, '', h) - left = header_entry_regex.group(1) - right = header_entry_regex.group(2) +# +# FIXME breaks on multiple strings. +# +def read_lilypond_header (fn): + s = open(fn).read () + s = re.sub('%.*$', '', s) + s = re.sub('\n', ' ', s) - right = regsub.gsub('\([^\\]\)\"', '\\1', right) - right = regsub.gsub('^"', '', right) - left = regsub.gsub('\([^\\]\)\"', '', left) - left = regsub.gsub('^"', '', left) + dict = {} + m = re.search (r"""\\header\s*{([^}]*)}""", s) - dict[left] = right + if m: + s = m.group(1) + else: + return dict - 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) + left = re.sub ('"', '', left) + right = re.sub ('"', '', right) + dict[left] = right + return dict def help (): - sys.stdout.write ("Usage: " + name + " [options] INFILE OUTFILE\n" - + "Generate index for mutopia\n\n" - + "Options:\n" - + " -h, --help print this help\n" - + " -p, --package=DIR specify package\n" - + " --prefix=PRE specify prefix\n" - + " -s, --subdirs=DIR add subdir\n" - + " --suffix=SUF specify suffix\n" - ) - sys.exit (0) - -def gen_list(inputs, subdir, filename): - (pre, subdirs, post)=subdir - print "generating HTML list %s\n" % filename - list = open(filename, 'w') - list.write ('Rendered Examples\n') - list.write ('') - if len(subdirs): - list.write ('

subdirectories

') - list.write ('') - - list.write('

Contents of this directory

\n'); - list.write ('These example files are taken from the LilyPond distribution.\n' - 'LilyPond currently only outputs TeX and MIDI. The pictures and\n' - 'PostScript files were generated using TeX, Ghostscript and some\n' - 'graphics tools. The papersize used for these examples is A4. The GIF\n' - 'files have been scaled to eliminate aliasing.\n'); - - - for ex in inputs: - ex_ext = '.ly' - print '%s, ' % ex - try: - header = read_mudela_header(ex + ex_ext + '.txt') - except: - ex_ext = '.fly' - header = read_mudela_header(ex + ex_ext + '.txt') + 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 + +""" + ) + sys.exit (0) + +# ugh. +def gen_list(inputs, filename): + print "generating HTML list %s\n" % filename + if filename: + list = open(filename, 'w') + else: + list = sys.stdout + list.write ('Rendered Examples\n') + list.write ('\n') - def read_dict(s, default, h =header): - try: - ret = h[s] - except KeyError: - ret = default - return ret - head = read_dict('title', ex) - composer = read_dict('composer', '') - desc = read_dict('description', '') - list.write('
') - list.write('

example file: %s

' % head); - if composer <> '': - list.write('

%s

\n' % composer) - if desc <> '': - list.write('%s

' % desc) - list.write ('

"); - - list.write( ""); - list.close() + if inputs: + list.write (headertext) + else: + list.write (headertext_nopics) + + + for ex in inputs: + (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"); + + list.write('\n'); + list.close() import getopt (options, files) = getopt.getopt(sys.argv[1:], - 'hp:s:', ['help', 'subdirs=', 'suffix=', 'package=', 'prefix=']) -subdir_pre='' -subdir_suf ='' + 'ho:', ['help', 'output=']) +outfile = 'examples.html' subdirs =[] for opt in options: - o = opt[0] - a = opt[1] - if o == '--subdirs' or o == '-s': - subdirs.append (a) - elif o == '--prefix': - subdir_pre = a - elif o == '-p' or o == '--package': - topdir = a - elif o == '--suffix': - subdir_suf = a - - sys.path.append (topdir + '/stepmake/bin') - from packagepython import * - package = Package (topdir) - packager = Packager () - - from flower import * + o = opt[0] + a = opt[1] + if o == '--help' or o == '-h': + help() + elif o == '--output' or o == '-o': + outfile = a - -# huh? -allfiles = multiple_find (['*.*ly.txt'], '.') +dirs = [] +for f in files: + dirs = dirs + find ('out-www', f) + +if not dirs: + dirs = ['.'] + +allfiles = [] + +for d in dirs: + allfiles = allfiles + find ('*.ly.txt', d) -gen_list (files, (subdir_pre, subdirs, subdir_suf), 'index.html') +gen_list (allfiles, outfile)