[open-ils-commits] [GIT] Evergreen ILS branch rel_3_0 updated. ea16dca8f7a285845f1b81b6be15215c29acdff2
Evergreen Git
git at git.evergreen-ils.org
Mon Mar 12 15:49:27 EDT 2018
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Evergreen ILS".
The branch, rel_3_0 has been updated
via ea16dca8f7a285845f1b81b6be15215c29acdff2 (commit)
from da2889c41fe4d6ada9c2fef7dcaa91d566e71318 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit ea16dca8f7a285845f1b81b6be15215c29acdff2
Author: Chris Sharp <csharp at georgialibraries.org>
Date: Wed Feb 21 16:25:15 2018 -0500
LP#1750912 - Add add_translations.py convenience script to i18n tools.
This script was authored by Jason Stephenson, who has kindly
agreed to add it to the Evergreen source tree. As Jason suggested,
I modified the GPL version number to 2 to be in line with the
Evergreen project's licensing requirements.
Signed-off-by: Chris Sharp <csharp at georgialibraries.org>
Signed-off-by: Jason Stephenson <jason at sigio.com>
Signed-off-by: Galen Charlton <gmc at equinoxinitiative.org>
diff --git a/build/i18n/scripts/add_translations.py b/build/i18n/scripts/add_translations.py
new file mode 100755
index 0000000..ec0282f
--- /dev/null
+++ b/build/i18n/scripts/add_translations.py
@@ -0,0 +1,139 @@
+#!/usr/bin/env python3
+# -*- Mode: python; coding: utf-8 -*-
+# ---------------------------------------------------------------
+# Copyright © 2015 Jason J.A. Stephenson <jason at sigio.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+# ---------------------------------------------------------------
+
+"""A program to assist with the process of adding new po and pot files
+into the Evergreen git repository.
+"""
+
+import argparse, os, re, subprocess
+
+__version__ = "1.0.2"
+
+modifiedFiles = []
+acceptedFiles = []
+rejectedFiles = []
+
+def cd_root():
+ """Change working directory to the root of the git repository."""
+ with subprocess.Popen(['git', 'rev-parse', '--show-toplevel'],
+ stdout=subprocess.PIPE) as git:
+ output = git.stdout.read().decode('utf8')
+ directory = output.strip()
+ if directory != os.getcwd():
+ os.chdir(directory)
+
+def commit():
+ """Commit the accepted files into git with a default message."""
+ with subprocess.Popen(['git', 'commit', '-sm',
+ 'Translation updates - newpot'],
+ stdout=subprocess.PIPE) as git:
+ output = git.stdout.read().decode('utf8')
+ return output
+
+def get_files():
+ """Get list of changed or new files in build/i18n/po."""
+ args = ['git', 'status', '--porcelain', '--', 'build/i18n/po']
+ with subprocess.Popen(args, stdout=subprocess.PIPE) as git:
+ lines = git.stdout.read().decode('utf8').splitlines()
+ for line in lines:
+ if line.startswith(' M'):
+ modifiedFiles.append(line[3:])
+ elif line.startswith('??'):
+ path = line[3:]
+ if os.path.isdir(path):
+ path += '.'
+ acceptedFiles.append(path)
+
+def add_files():
+ """Stage (git add) accepted files to be committed."""
+ args = ['git', 'add']
+ args += acceptedFiles
+ with subprocess.Popen(args, stdout=subprocess.PIPE) as git:
+ output = git.stdout.read().decode('utf8')
+ return output
+
+def reset_files():
+ """'Reset' rejected file changes by checking the files out again."""
+ args = ['git', 'checkout', '--']
+ args += rejectedFiles
+ with subprocess.Popen(args, stdout=subprocess.PIPE) as git:
+ output = git.stdout.read().decode('utf8')
+ return output
+
+def diff_file(file):
+ """Run git diff to get file changes."""
+ with subprocess.Popen(['git', 'diff', file], stdout=subprocess.PIPE) as git:
+ output = git.stdout.read().decode('utf8')
+ return output
+
+def process_modified():
+ """Process diff output and ask human if a change should be kept."""
+ for file in modifiedFiles:
+ print(diff_file(file))
+ print('==================== K for keep ==')
+ x = input()
+ if x == 'k' or x == 'K':
+ acceptedFiles.append(file)
+ else:
+ rejectedFiles.append(file)
+
+def autoprocess_modified():
+ """Process diff output without human intervention."""
+ isDiff = re.compile(r'^(?:\+[^\+]|-[^-])')
+ isMeta = re.compile(r'^(?:\+|-)"[-a-zA-z]+: ')
+ for file in modifiedFiles:
+ keep = False
+ diffLines = diff_file(file).splitlines()
+ for line in diffLines:
+ if re.match(isDiff, line) and not re.match(isMeta, line):
+ keep = True
+ break
+ if keep:
+ acceptedFiles.append(file)
+ else:
+ rejectedFiles.append(file)
+
+def parse_arguments():
+ """Parse command line arguments."""
+ parser = argparse.ArgumentParser(
+ description=__doc__,
+ epilog="Run this in your Evergreen git repo after running make newpot."
+ )
+ parser.add_argument("-m", "--manual", action="store_true",
+ help="manually decide which files to add")
+ parser.add_argument("-c", "--commit", action="store_true",
+ help="automatically commit added files")
+ return parser.parse_args()
+
+def main():
+ arguments = parse_arguments()
+ cd_root()
+ get_files()
+ if arguments.manual:
+ process_modified()
+ else:
+ autoprocess_modified()
+ if len(rejectedFiles) > 0:
+ reset_files()
+ if len(acceptedFiles) > 0:
+ add_files()
+ if arguments.commit:
+ print(commit())
+
+########################################
+
+if __name__ == '__main__':
+ main()
-----------------------------------------------------------------------
Summary of changes:
build/i18n/scripts/add_translations.py | 139 ++++++++++++++++++++++++++++++++
1 files changed, 139 insertions(+), 0 deletions(-)
create mode 100755 build/i18n/scripts/add_translations.py
hooks/post-receive
--
Evergreen ILS
More information about the open-ils-commits
mailing list