7 USAGE = ''' Usage: makelsr.py LSR_SNIPPETS_DIR
8 This script must be run from top of the source tree;
9 it updates snippets input/lsr with snippets in input/new or LSR_SNIPPETS_DIR.
12 LY_HEADER = '''%%%% Do not edit this file; it is auto-generated from LSR!
16 DEST = os.path.join ('input', 'lsr')
17 NEW_LYS = os.path.join ('input', 'new')
21 TAGS.extend (['pitches', 'rhythms', 'expressive-marks',
22 'repeats', 'simultaneous-notes', 'staff-notation', 'editorial-and-educational-use', 'text'])
24 TAGS.extend (['vocal-music', 'chords', 'piano-music',
25 'percussion', 'guitar', 'strings', 'bagpipes', 'ancient-notation'])
29 def exit_with_usage (n=0):
30 sys.stderr.write (USAGE)
38 if not (os.path.isdir (DEST) and os.path.isdir (NEW_LYS)):
44 def copy_ly (srcdir, name, tags):
47 dest = os.path.join (DEST, name)
49 f.write (LY_HEADER % ', '.join (tags))
50 f.write (open (os.path.join (srcdir, name)).read ())
52 e = os.system('convert-ly -e ' + dest)
54 unconverted.append (dest)
55 if os.path.exists (dest + '~'):
56 os.remove (dest + '~')
57 # -V seems to make unsafe snippets fail nicer/sooner
58 e = os.system ('nice lilypond -V -dno-print-pages -dsafe -o /tmp/lsrtest ' + dest)
62 def read_source (src):
66 srcdir = os.path.join (src, tag)
67 l[tag] = set (map (os.path.basename, glob.glob (os.path.join (srcdir, '*.ly'))))
72 s[f] = (srcdir, [tag])
75 def dump_file_list (file, list):
77 f.write ('\n'.join (list) + '\n')
79 ## clean out existing lys and generated files
80 map (os.remove, glob.glob (os.path.join (DEST, '*.ly')) +
81 glob.glob (os.path.join (DEST, '*.snippet-list')))
84 snippets, tag_lists = read_source (in_dir)
86 s, l = read_source (NEW_LYS)
89 tag_lists[t].update (l[t])
91 for (name, (srcdir, tags)) in snippets.items ():
92 copy_ly (srcdir, name, tags)
94 for (tag, file_set) in tag_lists.items ():
95 dump_file_list (os.path.join (DEST, tag + '.snippet-list'), file_set)
98 sys.stderr.write ('These files could not be converted successfully by convert-ly:\n')
99 sys.stderr.write ('\n'.join (unconverted))
101 dump_file_list ('lsr-unsafe.txt', unsafe)
102 sys.stderr.write ('''
104 Unsafe files printed in lsr-unsafe.txt: CHECK MANUALLY!
105 xargs git-diff < lsr-unsafe.txt