X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scripts%2Fauxiliar%2Fmakelsr.py;h=88731719c1e6a3562d5f5ce85518adce7c4e4b1c;hb=69f0ec479a6ade46d0a227755bb02562112c6743;hp=80628cbf164e82a629227a9ea10bbdcd37cc6433;hpb=1423508c355989fa26a8cfe5985b0d6e1ab0a538;p=lilypond.git diff --git a/scripts/auxiliar/makelsr.py b/scripts/auxiliar/makelsr.py index 80628cbf16..88731719c1 100755 --- a/scripts/auxiliar/makelsr.py +++ b/scripts/auxiliar/makelsr.py @@ -5,23 +5,31 @@ import os import glob import re +os.environ['PYTHONPATH'] += ':python' +import langdefs + +DEST = os.path.join ('Documentation', 'snippets') +NEW_LYS = os.path.join ('Documentation', 'snippets', 'new') +TEXIDOCS = [os.path.join ('Documentation', language_code, 'texidocs') + for language_code in langdefs.LANGDICT] + 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 +it updates snippets %(DEST)s with snippets +from %(NEW_LYS)s or LSR_SNIPPETS_DIR. +If a snippet is present in both directories, the one +from %(NEW_LYS)s is preferred. +''' % vars () + +LY_HEADER_LSR = '''%% Do not edit this file; it is automatically +%% generated from LSR http://lsr.dsi.unimi.it %% This file is in the public domain. ''' -LY_HEADER_NEW = '''%% Do not edit this file; it is auto-generated from input/new +LY_HEADER_NEW = '''%% Do not edit this file; it is automatically +%% generated from %s %% This file is in the public domain. -''' - -DEST = os.path.join ('input', 'lsr') -NEW_LYS = os.path.join ('input', 'new') -TEXIDOCS = os.path.join ('input', 'texidocs') +''' % NEW_LYS TAGS = [] # NR 1 @@ -70,11 +78,13 @@ ly_new_version_re = re.compile (r'\\version\s*"(.+?)"') # add tags to ly files from LSR def add_tags (ly_code, tags): - return begin_header_re.sub ('\\g<0>\n lsrtags = "' + tags + '"\n', ly_code, 1) + return begin_header_re.sub ('\\g<0>\n lsrtags = "' + tags + '"\n', + ly_code, 1) # for snippets from input/new, add message for earliest working version def add_version (ly_code): - return '''%% Note: this file works from version ''' + ly_new_version_re.search (ly_code).group (1) + '\n' + return '''%% Note: this file works from version ''' + \ + ly_new_version_re.search (ly_code).group (1) + '\n' def copy_ly (srcdir, name, tags): global unsafe @@ -83,15 +93,16 @@ def copy_ly (srcdir, name, tags): tags = ', '.join (tags) s = open (os.path.join (srcdir, name)).read () - texidoc_translations_path = os.path.join (TEXIDOCS, - os.path.splitext (name)[0] + '.texidoc') - if os.path.exists (texidoc_translations_path): - texidoc_translations = open (texidoc_translations_path).read () - # Since we want to insert the translations verbatim using a - # regexp, \\ is understood as ONE escaped backslash. So we have - # to escape those backslashes once more... - texidoc_translations = texidoc_translations.replace ('\\', '\\\\') - s = begin_header_re.sub ('\\g<0>\n' + texidoc_translations, s, 1) + for path in TEXIDOCS: + texidoc_translation_path = \ + os.path.join (path, os.path.splitext (name)[0] + '.texidoc') + if os.path.exists (texidoc_translation_path): + texidoc_translation = open (texidoc_translation_path).read () + # Since we want to insert the translations verbatim using a + # regexp, \\ is understood as ONE escaped backslash. So we have + # to escape those backslashes once more... + texidoc_translation = texidoc_translation.replace ('\\', '\\\\') + s = begin_header_re.sub ('\\g<0>\n' + texidoc_translation, s, 1) if in_dir and in_dir in srcdir: s = LY_HEADER_LSR + add_tags (s, tags) @@ -188,7 +199,7 @@ if unsafe: sys.stderr.write (''' Unsafe files printed in lsr-unsafe.txt: CHECK MANUALLY! - git add input/lsr/*.ly + git add %s/*.ly xargs git diff HEAD < lsr-unsafe.txt -''') +''' % DEST)