From 52bb30c9de08dbfcd952200a819afd151b95912d Mon Sep 17 00:00:00 2001 From: WilsonWang Date: Thu, 7 Jun 2018 22:24:59 +0800 Subject: [PATCH 1/4] Update git show to take an arbitrary hash * Add original_po_file_commit_hash to main func argument * Add argument to argv --- scripts/fix_diffs.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/scripts/fix_diffs.py b/scripts/fix_diffs.py index 1c774ec..07abfd9 100644 --- a/scripts/fix_diffs.py +++ b/scripts/fix_diffs.py @@ -53,8 +53,8 @@ def get_msgs(lines): lineno += 1 return msgids, msgstrs -def main(fp): - p = subprocess.Popen(['git', 'show', 'HEAD:' + fp], stdout=subprocess.PIPE) +def main(fp, original_po_commit='HEAD'): + p = subprocess.Popen(['git', 'show', '{}:'.format(original_po_commit) + fp], stdout=subprocess.PIPE) out, err = p.communicate() head_po = out.decode().splitlines() msgids, msgstrs = get_msgs(head_po) @@ -95,10 +95,15 @@ def main(fp): if __name__ == '__main__': import sys if len(sys.argv) < 2: - print('Usage: python fix_diffs.py ') + print('Usage: python fix_diffs.py ') fp = sys.argv[1] - output_lines = main(fp) + output_lines = None + if len(sys.argv) == 3: + original_hash = sys.argv[2] + output_lines = main(fp, original_hash) + else: + output_lines = main(fp) with open(fp, 'w') as f: f.writelines([s + '\n' for s in output_lines]) From 703baf7840fe4a9bf5e523ffaadf3e0bbbaf10ef Mon Sep 17 00:00:00 2001 From: WilsonWang Date: Thu, 7 Jun 2018 22:59:26 +0800 Subject: [PATCH 2/4] Add current working directory to file path * Avoid a path checking thrown by git show (will lead to crash) --- scripts/fix_diffs.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/fix_diffs.py b/scripts/fix_diffs.py index 07abfd9..5fb0071 100644 --- a/scripts/fix_diffs.py +++ b/scripts/fix_diffs.py @@ -94,10 +94,11 @@ def main(fp, original_po_commit='HEAD'): if __name__ == '__main__': import sys + if len(sys.argv) < 2: print('Usage: python fix_diffs.py ') - fp = sys.argv[1] + fp = './' + sys.argv[1] output_lines = None if len(sys.argv) == 3: original_hash = sys.argv[2] From d9d9612ee630a77635ff65193a0c6cc7e91c0d3d Mon Sep 17 00:00:00 2001 From: WilsonWang Date: Sun, 10 Jun 2018 14:54:21 +0800 Subject: [PATCH 3/4] Update to using f-string in Popen command --- scripts/fix_diffs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/fix_diffs.py b/scripts/fix_diffs.py index 5fb0071..9fde7a0 100644 --- a/scripts/fix_diffs.py +++ b/scripts/fix_diffs.py @@ -54,7 +54,7 @@ def get_msgs(lines): return msgids, msgstrs def main(fp, original_po_commit='HEAD'): - p = subprocess.Popen(['git', 'show', '{}:'.format(original_po_commit) + fp], stdout=subprocess.PIPE) + p = subprocess.Popen(['git', 'show', f'{original_po_commit}:{fp}'], stdout=subprocess.PIPE) out, err = p.communicate() head_po = out.decode().splitlines() msgids, msgstrs = get_msgs(head_po) From 3765d1dd8a70117ffc77a36bda19bc9f2953b383 Mon Sep 17 00:00:00 2001 From: WilsonWang Date: Sun, 10 Jun 2018 15:43:31 +0800 Subject: [PATCH 4/4] Update usage message * Update argument naming * Add exit against wrong arguments input --- scripts/fix_diffs.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/fix_diffs.py b/scripts/fix_diffs.py index 9fde7a0..5f99d97 100644 --- a/scripts/fix_diffs.py +++ b/scripts/fix_diffs.py @@ -96,13 +96,17 @@ def main(fp, original_po_commit='HEAD'): import sys if len(sys.argv) < 2: - print('Usage: python fix_diffs.py ') + print('Usage:') + print('\tpython fix_diffs.py []') + print('Option:') + print('\t: The original .po file(s) commit record (default to HEAD).') + sys.exit(1) fp = './' + sys.argv[1] output_lines = None if len(sys.argv) == 3: - original_hash = sys.argv[2] - output_lines = main(fp, original_hash) + original_commit = sys.argv[2] + output_lines = main(fp, original_commit) else: output_lines = main(fp)