From bc25d998d722c5d55b6a98956e4d4c6adaa7caeb Mon Sep 17 00:00:00 2001 From: Joachim Bauch Date: Fri, 12 Aug 2016 16:21:25 +0200 Subject: [PATCH] Add special "hook" mode to polint to fix language detection. The language is detected from the filename which doesn't work when called from the hook where a temporary file is processed. --- src/hooks/pre-commit.hook | 2 +- src/i18n/helpers/polint.py | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/hooks/pre-commit.hook b/src/hooks/pre-commit.hook index 04c2dac0..780bdeda 100755 --- a/src/hooks/pre-commit.hook +++ b/src/hooks/pre-commit.hook @@ -78,7 +78,7 @@ fi for file in `git diff-index --cached --name-only HEAD --diff-filter=ACMR| grep "\.po$"` ; do echo "Checking ${file}" nf=`git checkout-index --temp ${file} | cut -f 1` - ./src/i18n/helpers/polint.py "${nf}" + ./src/i18n/helpers/polint.py --hook "${nf}" "${file}" r=$? rm "${nf}" if [ $r != 0 ] ; then diff --git a/src/i18n/helpers/polint.py b/src/i18n/helpers/polint.py index 614c28ed..380275c4 100755 --- a/src/i18n/helpers/polint.py +++ b/src/i18n/helpers/polint.py @@ -187,13 +187,28 @@ def main(): _, POT_DATA, _ = parsepo(os.path.join(ROOT, 'messages.pot')) errors = 0 - filenames = sys.argv[1:] + try: + sys.argv.remove('--hook') + except ValueError: + is_hook = False + else: + is_hook = True + + if is_hook: + filename, orig_filename = sys.argv[1:] + filenames = [filename] + else: + orig_filename = None + filenames = sys.argv[1:] show_filenames = False if not filenames: filenames = glob.glob(os.path.join(ROOT, 'messages-*.po')) show_filenames = True for filename in filenames: - language = os.path.basename(filename)[9:-3] + if orig_filename: + language = os.path.basename(orig_filename)[9:-3] + else: + language = os.path.basename(filename)[9:-3] if show_filenames: print 'Checking %s (%s)' % (filename, language) try: