X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=buildscripts%2Fmutopia-index.py;h=76ad6e1c5b5becaa8be65f6941f7349fad6fe879;hb=a2aa743cd6f39f0d50dd8562ce8600fca4a51483;hp=be4163087bd25fb365783db9736e676364d23134;hpb=0a92b605eb18b62d171c97f354c2101109d9e071;p=lilypond.git diff --git a/buildscripts/mutopia-index.py b/buildscripts/mutopia-index.py old mode 100755 new mode 100644 index be4163087b..76ad6e1c5b --- a/buildscripts/mutopia-index.py +++ b/buildscripts/mutopia-index.py @@ -1,65 +1,65 @@ #!@PYTHON@ # mutopia-index.py -name = 'mutopia-index' - -import find -import re +import fnmatch +import getopt import os -import sys +import os +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 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. -We don't use GIFS due to patent problems. + +

LilyPond samples

+ + +

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. +

-If you want an accurate impression of the output quality please print -out the samples first. -""" -headertext_nopics = r"""This is a subdirectory of the LilyPond example -set. We decided not to show any examples from this directory. If you -want to view them, then you have to download LilyPond and compile them -yourself.""" +The pictures are 90 dpi anti-aliased snapshots of the printed output. +If you want a better impression of the appearance, do print out one of +the PDF or PostScript files; they use scalable fonts, and should look +good at any resolution. + +""" +headertext_nopics= r""" +

Nothing to be seen here, move along. +""" # # FIXME breaks on multiple strings. # -def read_mudela_header (fn): - s = gulp_file(fn) - s = re.sub('%.*$', '', s) - s = re.sub('\n', ' ', s) +def read_lilypond_header (fn): + 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: @@ -74,107 +74,132 @@ def read_mudela_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 - --prefix=PRE specify prefix + -h, --help print this help + -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, 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 subdirs: - list.write ('

subdirectories

') - list.write ('') - - - +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 + + +''') + + list.write ('\n') + if inputs: - list.write('

Contents of this directory

\n'); - - list.write (headertext) + list.write (headertext) else: - list.write (headertext_nopics) - + list.write (headertext_nopics) 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') + print ex - def read_dict(s, default, h =header): + (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', 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 ('

\n'); -(options, files) = getopt.getopt(sys.argv[1:], - 'hp:s:', ['help', 'subdirs=', 'suffix=', 'prefix=']) -subdir_pre='' -subdir_suf ='' + list.write ('\n'); + list.close () -subdirs =[] +(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 == '--subdirs' or o == '-s': - subdirs.append (a) - elif o == '--prefix': - subdir_pre = a - elif o == '--suffix': - subdir_suf = a + if o == '--help' or o == '-h': + help () + elif o == '--output' or o == '-o': + outfile = a - -allfiles = find.find ('*.ly') + find.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)