diff options
author | Jan Klass <kissaki@posteo.de> | 2021-03-01 20:54:31 +0300 |
---|---|---|
committer | Jan Klass <kissaki@posteo.de> | 2021-03-03 21:09:16 +0300 |
commit | 85667cccaef8809262c07115c6c2b180e67b0b0d (patch) | |
tree | 42c9fdfec0be3ead7ed41fe4f5183fc732fc1087 | |
parent | 0c8c0bd9b85a86868579db142eadc50e9425aac4 (diff) |
MAINT: Enable number heuristic for translation updates
-rwxr-xr-x | scripts/updatetranslations.py | 89 |
1 files changed, 44 insertions, 45 deletions
diff --git a/scripts/updatetranslations.py b/scripts/updatetranslations.py index 38a88605e..cad4ca1ed 100755 --- a/scripts/updatetranslations.py +++ b/scripts/updatetranslations.py @@ -5,7 +5,7 @@ # that can be found in the LICENSE file at the root of the
# Mumble source tree or at <https://www.mumble.info/LICENSE>.
#
-# Updates the translation files src/mumble/mumble_*.ts from source and commits the changes.
+# Updates the translation files src/mumble/mumble_*.ts from source and commits the changes. #
# The main actions this script performs:
# * lupdate to update translation strings
@@ -28,36 +28,35 @@ def FindLupdate(vcpkg_triplet: Optional[str] = None) -> Optional[str]: return which('lupdate', path=vcpkgbin)
return None
-def CheckForGitHasTsFileChanges(tsfiles: list) -> bool:
- res = subprocess.run(["git", "status", '--porcelain', '--'] + tsfiles, capture_output=True)
- return res.returncode == 0 and len(res.stdout) > 0
+def CheckForGitHasTsFileChanges(tsfiles: list) -> bool: + res = subprocess.run(["git", "status", '--porcelain', '--'] + tsfiles, capture_output=True) + return res.returncode == 0 and len(res.stdout) > 0 -def Commit(tsfiles: list) -> None:
+def Commit(tsfiles: list) -> None: res = subprocess.run(["git", "reset", '--mixed'], capture_output=True)
- if res.returncode != 0:
- logging.error('The git reset call returned an error status code ' + res.returncode)
+ if res.returncode != 0: + logging.error('The git reset call returned an error status code ' + res.returncode) logging.debug('stdout: ' + res.stdout)
exit(1)
res = subprocess.run(["git", "add"] + tsfiles, capture_output=True)
- if res.returncode != 0:
- logging.error('The git add call returned an error status code ' + res.returncode)
+ if res.returncode != 0: + logging.error('The git add call returned an error status code ' + res.returncode) logging.debug('stdout: ' + res.stdout)
exit(1)
res = subprocess.run(["git", "commit", '-m', 'TRANSLATION: Update translation files'], capture_output=True)
- if res.returncode != 0:
- logging.error('The git commit call returned an error status code ' + res.returncode)
+ if res.returncode != 0: + logging.error('The git commit call returned an error status code ' + res.returncode) logging.debug('stdout: ' + res.stdout)
exit(1)
def Update(lupdatebin, tsfile: str, debuglupdate: bool) -> (int, int, int):
- res = subprocess.run([
+ res = subprocess.run([ lupdatebin
# Do not explain what is being done.
, '-no-ui-lines'
# {sametext|similartext|number}
, '-disable-heuristic', 'sametext'
, '-disable-heuristic', 'similartext'
- , '-disable-heuristic', 'number'
# {absolute|relative|none}
, '-locations', 'none'
, '-no-obsolete'
@@ -67,11 +66,11 @@ def Update(lupdatebin, tsfile: str, debuglupdate: bool) -> (int, int, int): , './src', './src/mumble'
# target
, '-ts', tsfile
- ], capture_output=True)
+ ], capture_output=True) if debuglupdate:
logging.debug(res.stdout)
- if res.returncode != 0:
- logging.error('lupdate failed with error code %d', res.returncode)
+ if res.returncode != 0: + logging.error('lupdate failed with error code %d', res.returncode) logging.debug('stdout: ' + res.stdout)
exit(1)
p = re.compile('Found (?P<nsrc>[0-9]+) source text\(s\) \((?P<nnew>[0-9]+) new and (?P<nsame>[0-9]+) already existing\)')
@@ -79,41 +78,41 @@ def Update(lupdatebin, tsfile: str, debuglupdate: bool) -> (int, int, int): logging.debug('Found %s texts where %s new and %s same', m.group('nsrc'), m.group('nnew'), m.group('nsame'))
return (m.group('nsrc'), m.group('nnew'), m.group('nsame'))
-if __name__ == '__main__':
- parser = argparse.ArgumentParser()
- parser.add_argument('--vcpkg-triplet', type=str, required=False, help='the vcpkg triplet to use the lupdate tool from, e.g. "x64-windows-static-md"')
- parser.add_argument('--debug', dest='debug', action='store_true')
+if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('--vcpkg-triplet', type=str, required=False, help='the vcpkg triplet to use the lupdate tool from, e.g. "x64-windows-static-md"') + parser.add_argument('--debug', dest='debug', action='store_true') parser.add_argument('--debug-lupdate', dest='debuglupdate', action='store_true')
parser.set_defaults(debug=False, debuglupdate=False)
- args = parser.parse_args()
+ args = parser.parse_args() - loglevel = logging.DEBUG if args.debug else logging.INFO
- logging.basicConfig(stream=sys.stdout, level=loglevel, format='%(levelname)s: %(message)s')
+ loglevel = logging.DEBUG if args.debug else logging.INFO + logging.basicConfig(stream=sys.stdout, level=loglevel, format='%(levelname)s: %(message)s') - lupdatebin = FindLupdate(args.vcpkg_triplet)
- if lupdatebin is None:
- logging.error('Could not find `lupdate` executable')
- exit(1)
+ lupdatebin = FindLupdate(args.vcpkg_triplet) + if lupdatebin is None: + logging.error('Could not find `lupdate` executable') + exit(1) - # cd into repository root directory
- os.chdir(os.path.dirname(os.path.abspath(__file__)) + "/..")
- logging.info('Working in directory %s', os.getcwd())
+ # cd into repository root directory + os.chdir(os.path.dirname(os.path.abspath(__file__)) + "/..") + logging.info('Working in directory %s', os.getcwd()) - tsfiles = glob.glob(os.path.join('src', 'mumble', 'mumble_*.ts'))
- logging.debug('Identified these ts files: %s', tsfiles)
+ tsfiles = glob.glob(os.path.join('src', 'mumble', 'mumble_*.ts')) + logging.debug('Identified these ts files: %s', tsfiles) - logging.info('Ensuring ts files have no local changes…')
- if CheckForGitHasTsFileChanges(tsfiles):
- logging.error('There are ts files with local changes. Cancelling execution.')
- exit(1)
+ logging.info('Ensuring ts files have no local changes…') + if CheckForGitHasTsFileChanges(tsfiles): + logging.error('There are ts files with local changes. Cancelling execution.') + exit(1) - logging.info('Updating ts files…')
+ logging.info('Updating ts files…') nsrc: Optional[int] = None
nnew: Optional[int] = None
nsame: Optional[int] = None
mismatch = False
- for tsfile in tsfiles:
- logging.debug('Updating ts file ' + tsfile + '…')
+ for tsfile in tsfiles: + logging.debug('Updating ts file ' + tsfile + '…') (resnsrc, resnnew, resnsame) = Update(lupdatebin, tsfile, args.debuglupdate)
if nsrc is None:
nsrc = resnsrc
@@ -127,10 +126,10 @@ if __name__ == '__main__': if nsrc is not None:
logging.info('Found %s texts where %s new and %s same', nsrc, nnew, nsame)
- if CheckForGitHasTsFileChanges(tsfiles):
- logging.info('Committing changes…')
- Commit(tsfiles)
- else:
- logging.info('No changes to commit.')
+ if CheckForGitHasTsFileChanges(tsfiles): + logging.info('Committing changes…') + Commit(tsfiles) + else: + logging.info('No changes to commit.') - logging.info('The updating of the translation files successfully completed.')
+ logging.info('The updating of the translation files successfully completed.') |