From cfbe8689b937bddd0d977e622b0954046cf8bdb9 Mon Sep 17 00:00:00 2001 From: John Mandereau Date: Mon, 27 Jul 2009 10:33:08 +0200 Subject: [PATCH] Docs: update check_translation script Also add an experimental feature to update committishes for changes that are made simultaneously in all languages (to be tested and documented in the CG). --- Documentation/GNUmakefile | 2 +- python/auxiliar/buildlib.py | 16 ++++--- scripts/auxiliar/check_translation.py | 67 +++++++++++++++------------ 3 files changed, 47 insertions(+), 38 deletions(-) diff --git a/Documentation/GNUmakefile b/Documentation/GNUmakefile index 3953c1136f..f3eeb87350 100644 --- a/Documentation/GNUmakefile +++ b/Documentation/GNUmakefile @@ -246,7 +246,7 @@ new-lang: @echo "*** Please add a language definition for $(ISOLANG) in python/langdefs.py ***" CHECKED_FILES = $(ISOLANG)/index.html.in $(foreach i,learning notation application, \ - $(shell find $(ISOLANG)/$(manual) -maxdepth 1 -name '*.*te??')) \ + $(shell find $(ISOLANG)/$(manual) -name '*.*te??' -not -wholename '*out-www*')) \ $(shell find $(ISOLANG)/texidocs/ -name '*.texidoc') TELY_FILES = $(call src-wildcard,$(ISOLANG)/*.tely) diff --git a/python/auxiliar/buildlib.py b/python/auxiliar/buildlib.py index cd99586ff8..04a72c7924 100644 --- a/python/auxiliar/buildlib.py +++ b/python/auxiliar/buildlib.py @@ -20,20 +20,22 @@ def read_pipe (command): return (output, error) revision_re = re.compile ('GIT [Cc]ommittish:\s+([a-f0-9]+)') -vc_diff_cmd = 'git diff %(color_flag)s %(revision)s HEAD -- %(original)s | cat' +vc_diff_cmd = 'git diff --patience -M %(color_flag)s %(revision)s %(upper_revision)s -- %(original)s | cat' +no_committish_fatal_error = """error: %s: no 'GIT committish: ' found. +Please check the whole file against the original in English, then +fill in HEAD committish in the header. +""" -def check_translated_doc (original, translated_file, translated_contents, color=False): +def check_translated_doc (original, translated_file, translated_contents, + color=False, upper_revision='HEAD'): m = revision_re.search (translated_contents) if not m: - sys.stderr.write ('error: ' + translated_file + \ - ": no 'GIT committish: ' found.\nPlease check " + \ - 'the whole file against the original in English, then ' + \ - 'fill in HEAD committish in the header.\n') + sys.stderr.write (no_committish_fatal_error % translated_file) sys.exit (1) revision = m.group (1) if color: - color_flag = '--color' + color_flag = '--color --color-words' else: color_flag = '--no-color' c = vc_diff_cmd % vars () diff --git a/scripts/auxiliar/check_translation.py b/scripts/auxiliar/check_translation.py index d4287ff5c3..cee68dcbcb 100755 --- a/scripts/auxiliar/check_translation.py +++ b/scripts/auxiliar/check_translation.py @@ -19,8 +19,8 @@ def dir_lang (file, lang, lang_dir_index): path_components[lang_dir_index] = lang return os.path.join (*path_components) -vc_last_revision = 'git log --pretty=format:%%H %(file_name)s | head -1' -vc_last_texidoc_revision = 'git log -Stexidoc%(preferred_language)s --pretty=format:%%H %(file_name)s | head -1' +# ugh, this is complicated; where has the good old 'git rev-parse' gone? +vc_revision_parse = 'git log -1 --pretty=format:%%H %s' def do_file (file_name, lang_codes): if verbose: @@ -39,28 +39,25 @@ def do_file (file_name, lang_codes): raise Exception ('cannot determine language for ' + file_name) else: if os.path.splitext (file_name)[1] == '.texidoc': - original = file_name.replace (os.path.join ('texidocs' + os.path.sep, 'lsr' + os.path.sep, 1) - original = original.replace ('.texidoc', '.ly', 1) - - # URG dirty .texidoc files manipulation in a dirty way - if touch_committishes and buildlib.check_translated_doc (original, - file_name, - translated_contents, - color=use_colors and not update_mode)[1]: - (estimated_revision, error) = buildlib.read_pipe (vc_last_texidoc_revision % vars ()) - if error: - sys.stderr.write ('warning: %s: %s' % (file_name, error)) - estimated_revision = estimated_revision.strip () - translated_contents = re.sub (r'(?m)^%+\s*Translation of GIT committish:.*\n', '', translated_contents) - f = open (file_name, 'w') - f.write (full_translated_contents[:translated_contents_start]) - f.write ('%% Translation of GIT committish: ' + estimated_revision + '\n') - f.write (translated_contents) - f.write (full_translated_contents[translated_contents_end:]) - return - original = dir_lang (file_name, '', lang_dir_index) + original = file_name.replace (os.path.join (check_lang, 'texidocs'), 'snippets', 1) + original = original.replace ('.texidoc', '.ly', 1) + else: + original = dir_lang (file_name, '', lang_dir_index) translated_contents = open (file_name).read () + ## experimental feature + if not touch_committishes in (current_revision, 'HEAD'): + (changes_in_original, error) = \ + buildlib.check_translated_doc (original, + file_name, + translated_contents, + upper_revision=touch_committishes) + if not error and not changes_in_original in ('', '\n'): + translated_contents = \ + buildlib.revision_re.sub ('GIT committish: ' + current_revision, + translated_contents, 1) + f = open (file_name, 'w').write (translated_contents) + return (diff_string, error) \ = buildlib.check_translated_doc (original, file_name, @@ -86,7 +83,7 @@ def do_file (file_name, lang_codes): def usage (): sys.stdout.write (r''' Usage: -check-translation [--language=LANG] [--verbose] [--update] FILE... +check-translation [--language=LANG] [--verbose] [--update] [-t COMMIT] FILE... This script is licensed under the GNU GPL. ''') @@ -94,12 +91,15 @@ This script is licensed under the GNU GPL. def do_options (): global lang, verbose, update_mode, touch_committishes, use_colors - p = optparse.OptionParser (usage="check-translation [--language=LANG] [--verbose] FILE...", + p = optparse.OptionParser (usage=\ +"check-translation [--language=LANG] [--verbose] [--update] [-t COMMIT] FILE...", description="This script is licensed under the GNU GPL.") p.add_option ("--language", action='store', default=C, - dest="language") + dest="language", + metavar='LL', + help="assume document language ISO 639 code LL by default") p.add_option ("--no-color", action='store_false', default=True, @@ -111,10 +111,12 @@ def do_options (): dest="verbose", help="print details, including executed shell commands") p.add_option ('-t', - action='store_true', - default=False, + action='store', + default='HEAD', dest="touch_committishes", - help=optparse.SUPPRESS_HELP) + metavar='COMMIT', + help='[EXPERIMENTAL] update committishes of all files that were up to \ +date at commit COMMIT') p.add_option ('-u', "--update", action='store_true', default=False, @@ -131,15 +133,20 @@ def do_options (): return files def main (): - global update_mode, text_editor + global update_mode, text_editor, touch_committishes, current_revision files = do_options () if 'EDITOR' in os.environ: text_editor = os.environ['EDITOR'] else: update_mode = False - buildlib.verbose = verbose + (parsed_revision, error) = buildlib.read_pipe (vc_revision_parse % touch_committishes) + if error: + sys.stderr.write ('warning: %s' % error) + else: + touch_committishes = parsed_revision.strip () + current_revision = buildlib.read_pipe (vc_revision_parse % 'HEAD')[0] for i in files: do_file (i, langdefs.LANGDICT.keys ()) -- 2.39.5