From: John Mandereau Date: Mon, 20 Apr 2009 12:44:21 +0000 (+0200) Subject: Snippets updating: make LSR snippets input directory optional X-Git-Tag: release/2.13.1-1~42 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=608eef2e8d6162ece84317d62a46c0ea2853a0eb;p=lilypond.git Snippets updating: make LSR snippets input directory optional --- diff --git a/scripts/auxiliar/makelsr.py b/scripts/auxiliar/makelsr.py index 2e72a23272..bbe36342b1 100755 --- a/scripts/auxiliar/makelsr.py +++ b/scripts/auxiliar/makelsr.py @@ -5,9 +5,10 @@ import os import glob import re -USAGE = ''' Usage: makelsr.py LSR_SNIPPETS_DIR +USAGE = ''' Usage: makelsr.py [LSR_SNIPPETS_DIR] This script must be run from top of the source tree; it updates snippets input/lsr with snippets in input/new or LSR_SNIPPETS_DIR. +If a snippet is present in both directories, the one from input/new is preferred. ''' LY_HEADER_LSR = '''%% Do not edit this file; it is auto-generated from LSR http://lsr.dsi.unimi.it @@ -41,13 +42,14 @@ def exit_with_usage (n=0): sys.stderr.write (USAGE) sys.exit (n) -try: +if len (sys.argv) >= 2: in_dir = sys.argv[1] -except: - exit_with_usage (2) - -if not (os.path.isdir (DEST) and os.path.isdir (NEW_LYS)): - exit_with_usage (3) + if len (sys.argv) >= 3: + exit_with_usage (2) + if not (os.path.isdir (DEST) and os.path.isdir (NEW_LYS)): + exit_with_usage (3) +else: + in_dir = '' unsafe = [] unconverted = [] @@ -85,7 +87,7 @@ def copy_ly (srcdir, name, tags): texidoc_translations = texidoc_translations.replace ('\\', '\\\\') s = begin_header_re.sub ('\\g<0>\n' + texidoc_translations, s, 1) - if in_dir in srcdir: + if in_dir and in_dir in srcdir: s = LY_HEADER_LSR + add_tags (s, tags) else: s = LY_HEADER_NEW + s @@ -135,32 +137,39 @@ def read_source (src): return s, l -def dump_file_list (file, list): +def dump_file_list (file, file_list, update=False): + if update: + old_list = set (open (file, 'r').read ().splitlines ()) + old_list.update (file_list) + new_list = list (old_list) + else: + new_list = file_list f = open (file, 'w') - f.write ('\n'.join (list) + '\n') + f.write ('\n'.join (sorted (new_list)) + '\n') + +if in_dir: + ## clean out existing lys and generated files + map (os.remove, glob.glob (os.path.join (DEST, '*.ly')) + + glob.glob (os.path.join (DEST, '*.snippet-list'))) -## clean out existing lys and generated files -map (os.remove, glob.glob (os.path.join (DEST, '*.ly')) + - glob.glob (os.path.join (DEST, '*.snippet-list'))) + # read LSR source where tags are defined by subdirs + snippets, tag_lists = read_source_with_dirs (in_dir) -# read LSR source where tags are defined by subdirs -snippets, tag_lists = read_source_with_dirs (in_dir) -# read input/new where tags are directly -s, l = read_source (NEW_LYS) -snippets.update (s) -for t in TAGS: - tag_lists[t].update (l[t]) + # read input/new where tags are directly defined + s, l = read_source (NEW_LYS) + snippets.update (s) + for t in TAGS: + tag_lists[t].update (l[t]) +else: + snippets, tag_lists = read_source (NEW_LYS) for (name, (srcdir, tags)) in snippets.items (): copy_ly (srcdir, name, tags) - for (tag, file_set) in tag_lists.items (): - dump_file_list (os.path.join (DEST, tag + '.snippet-list'), sorted(file_set)) - + dump_file_list (os.path.join (DEST, tag + '.snippet-list'), file_set, update=not(in_dir)) if unconverted: sys.stderr.write ('These files could not be converted successfully by convert-ly:\n') sys.stderr.write ('\n'.join (unconverted) + '\n\n') - if notags_files: sys.stderr.write ('No tags could be found in these files:\n') sys.stderr.write ('\n'.join (notags_files) + '\n\n')