annotate scripts/i18n @ 8365:d5e77cc4a4f2 i18n

Merge divergent i18n changes that were caused by broken weblate repo access
author Mads Kiilerich <mads@kiilerich.com>
date Mon, 04 May 2020 18:59:36 +0200
parents 80ffe0f29857
children 68eee0e7f4f5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8313
4bc712f1ec93 scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff changeset
1 #!/usr/bin/env python3
4bc712f1ec93 scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff changeset
2
4bc712f1ec93 scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff changeset
3 # -*- coding: utf-8 -*-
4bc712f1ec93 scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff changeset
4 # This program is free software: you can redistribute it and/or modify
4bc712f1ec93 scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff changeset
5 # it under the terms of the GNU General Public License as published by
4bc712f1ec93 scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff changeset
6 # the Free Software Foundation, either version 3 of the License, or
4bc712f1ec93 scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff changeset
7 # (at your option) any later version.
4bc712f1ec93 scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff changeset
8 #
4bc712f1ec93 scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff changeset
9 # This program is distributed in the hope that it will be useful,
4bc712f1ec93 scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff changeset
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
4bc712f1ec93 scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff changeset
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4bc712f1ec93 scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff changeset
12 # GNU General Public License for more details.
4bc712f1ec93 scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff changeset
13 #
4bc712f1ec93 scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff changeset
14 # You should have received a copy of the GNU General Public License
4bc712f1ec93 scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff changeset
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
4bc712f1ec93 scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff changeset
16
8316
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
17 import os
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
18 import shutil
8315
93dabafa567e scripts/i18n: add command 'normalized-diff'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8314
diff changeset
19 import sys
93dabafa567e scripts/i18n: add command 'normalized-diff'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8314
diff changeset
20
8313
4bc712f1ec93 scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff changeset
21 import click
4bc712f1ec93 scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff changeset
22
4bc712f1ec93 scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff changeset
23 import i18n_utils
4bc712f1ec93 scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff changeset
24
4bc712f1ec93 scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff changeset
25
4bc712f1ec93 scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff changeset
26 """
4bc712f1ec93 scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff changeset
27 Tool for maintenance of .po and .pot files
8314
ae9d205f4407 scripts/i18n: add command 'normalize-po-files'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8313
diff changeset
28
ae9d205f4407 scripts/i18n: add command 'normalize-po-files'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8313
diff changeset
29 Normally, the i18n-related files contain for each translatable string a
ae9d205f4407 scripts/i18n: add command 'normalize-po-files'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8313
diff changeset
30 reference to all the source code locations where this string is found. This
ae9d205f4407 scripts/i18n: add command 'normalize-po-files'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8313
diff changeset
31 meta data is useful for translators to assess how strings are used, but is not
ae9d205f4407 scripts/i18n: add command 'normalize-po-files'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8313
diff changeset
32 relevant for normal development nor for running Kallithea. Such meta data, or
ae9d205f4407 scripts/i18n: add command 'normalize-po-files'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8313
diff changeset
33 derived data like kallithea.pot, will inherently be outdated, and create
ae9d205f4407 scripts/i18n: add command 'normalize-po-files'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8313
diff changeset
34 unnecessary churn and repository growth, making it harder to spot actual and
ae9d205f4407 scripts/i18n: add command 'normalize-po-files'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8313
diff changeset
35 important changes.
8313
4bc712f1ec93 scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff changeset
36 """
4bc712f1ec93 scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff changeset
37
4bc712f1ec93 scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff changeset
38 @click.group()
4bc712f1ec93 scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff changeset
39 @click.option('--debug/--no-debug', default=False)
4bc712f1ec93 scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff changeset
40 def cli(debug):
4bc712f1ec93 scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff changeset
41 if (debug):
4bc712f1ec93 scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff changeset
42 i18n_utils.do_debug = True
4bc712f1ec93 scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff changeset
43 pass
4bc712f1ec93 scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff changeset
44
8314
ae9d205f4407 scripts/i18n: add command 'normalize-po-files'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8313
diff changeset
45 @cli.command()
ae9d205f4407 scripts/i18n: add command 'normalize-po-files'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8313
diff changeset
46 @click.argument('po_files', nargs=-1)
8317
5553ecc962e0 scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents: 8316
diff changeset
47 @click.option('--merge-pot-file', default=None)
5553ecc962e0 scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents: 8316
diff changeset
48 @click.option('--strip/--no-strip', default=False)
5553ecc962e0 scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents: 8316
diff changeset
49 def normalize_po_files(po_files, merge_pot_file, strip):
8314
ae9d205f4407 scripts/i18n: add command 'normalize-po-files'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8313
diff changeset
50 """Normalize the specified .po and .pot files.
ae9d205f4407 scripts/i18n: add command 'normalize-po-files'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8313
diff changeset
51
8317
5553ecc962e0 scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents: 8316
diff changeset
52 By default, only actual translations and essential headers will be
5553ecc962e0 scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents: 8316
diff changeset
53 preserved, just as we want it in the main branches with minimal noise.
5553ecc962e0 scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents: 8316
diff changeset
54
5553ecc962e0 scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents: 8316
diff changeset
55 If a .pot file is specified, the po files will instead be updated by
5553ecc962e0 scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents: 8316
diff changeset
56 running GNU msgmerge with this .pot file, thus updating source code
5553ecc962e0 scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents: 8316
diff changeset
57 references and preserving comments and outdated translations.
8314
ae9d205f4407 scripts/i18n: add command 'normalize-po-files'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8313
diff changeset
58 """
ae9d205f4407 scripts/i18n: add command 'normalize-po-files'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8313
diff changeset
59 for po_file in po_files:
8317
5553ecc962e0 scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents: 8316
diff changeset
60 i18n_utils._normalize_po_file(po_file, merge_pot_file=merge_pot_file, strip=strip)
8314
ae9d205f4407 scripts/i18n: add command 'normalize-po-files'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8313
diff changeset
61
8315
93dabafa567e scripts/i18n: add command 'normalized-diff'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8314
diff changeset
62 @cli.command()
8316
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
63 @click.argument('local')
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
64 @click.argument('base')
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
65 @click.argument('other')
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
66 @click.argument('output')
8317
5553ecc962e0 scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents: 8316
diff changeset
67 @click.option('--merge-pot-file', default=None)
5553ecc962e0 scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents: 8316
diff changeset
68 @click.option('--strip/--no-strip', default=False)
5553ecc962e0 scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents: 8316
diff changeset
69 def normalized_merge(local, base, other, output, merge_pot_file, strip):
8316
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
70 """Merge tool for use with 'hg merge/rebase/graft --tool'
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
71
8317
5553ecc962e0 scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents: 8316
diff changeset
72 i18n files are partially manually editored original source of content, and
5553ecc962e0 scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents: 8316
diff changeset
73 partially automatically generated and updated. That create a lot of churn
5553ecc962e0 scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents: 8316
diff changeset
74 and often cause a lot of merge conflicts.
5553ecc962e0 scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents: 8316
diff changeset
75
5553ecc962e0 scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents: 8316
diff changeset
76 To avoid that, this merge tool wrapper will normalize .po content before
5553ecc962e0 scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents: 8316
diff changeset
77 running the merge tool.
5553ecc962e0 scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents: 8316
diff changeset
78
5553ecc962e0 scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents: 8316
diff changeset
79 By default, only actual translations and essential headers will be
5553ecc962e0 scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents: 8316
diff changeset
80 preserved, just as we want it in the main branches with minimal noise.
5553ecc962e0 scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents: 8316
diff changeset
81
5553ecc962e0 scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents: 8316
diff changeset
82 If a .pot file is specified, the po files will instead be updated by
5553ecc962e0 scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents: 8316
diff changeset
83 running GNU msgmerge with this .pot file, thus updating source code
5553ecc962e0 scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents: 8316
diff changeset
84 references and preserving comments and outdated translations.
8316
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
85
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
86 Add the following to your user or repository-specific .hgrc file to use it:
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
87 [merge-tools]
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
88 i18n.executable = /path/to/scripts/i18n
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
89 i18n.args = normalized-merge $local $base $other $output
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
90
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
91 and then invoke merge/rebase/graft with the additional argument '--tool i18n'.
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
92 """
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
93 from mercurial import (
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
94 context,
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
95 simplemerge,
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
96 ui as uimod,
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
97 )
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
98
8335
80ffe0f29857 scripts/i18n: tweak messages
Mads Kiilerich <mads@kiilerich.com>
parents: 8319
diff changeset
99 print('i18n normalized-merge: normalizing and merging %s' % output)
8316
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
100
8317
5553ecc962e0 scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents: 8316
diff changeset
101 i18n_utils._normalize_po_file(local, merge_pot_file=merge_pot_file, strip=strip)
5553ecc962e0 scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents: 8316
diff changeset
102 i18n_utils._normalize_po_file(base, merge_pot_file=merge_pot_file, strip=strip)
5553ecc962e0 scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents: 8316
diff changeset
103 i18n_utils._normalize_po_file(other, merge_pot_file=merge_pot_file, strip=strip)
5553ecc962e0 scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents: 8316
diff changeset
104 i18n_utils._normalize_po_file(output, merge_pot_file=merge_pot_file, strip=strip)
8316
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
105
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
106 # simplemerge will write markers to 'local' if it fails, keep a copy without markers
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
107 localkeep = local + '.keep'
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
108 shutil.copyfile(local, localkeep)
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
109
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
110 ret = simplemerge.simplemerge(uimod.ui.load(),
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
111 context.arbitraryfilectx(local.encode('utf-8')),
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
112 context.arbitraryfilectx(base.encode('utf-8')),
8319
f8314738030a scripts/i18n: let 'normalized-merge' leave 3-way conflict markers in output file
Mads Kiilerich <mads@kiilerich.com>
parents: 8317
diff changeset
113 context.arbitraryfilectx(other.encode('utf-8')),
f8314738030a scripts/i18n: let 'normalized-merge' leave 3-way conflict markers in output file
Mads Kiilerich <mads@kiilerich.com>
parents: 8317
diff changeset
114 label=[b'local', b'other', b'base'],
f8314738030a scripts/i18n: let 'normalized-merge' leave 3-way conflict markers in output file
Mads Kiilerich <mads@kiilerich.com>
parents: 8317
diff changeset
115 mode='merge',
8316
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
116 )
8319
f8314738030a scripts/i18n: let 'normalized-merge' leave 3-way conflict markers in output file
Mads Kiilerich <mads@kiilerich.com>
parents: 8317
diff changeset
117 shutil.copyfile(local, output) # simplemerge wrote to local - either resolved or with conflict markers
8316
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
118 if ret:
8319
f8314738030a scripts/i18n: let 'normalized-merge' leave 3-way conflict markers in output file
Mads Kiilerich <mads@kiilerich.com>
parents: 8317
diff changeset
119 shutil.copyfile(localkeep, local)
8316
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
120 basekeep = base + '.keep'
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
121 otherkeep = other + '.keep'
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
122 shutil.copyfile(base, basekeep)
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
123 shutil.copyfile(other, otherkeep)
8335
80ffe0f29857 scripts/i18n: tweak messages
Mads Kiilerich <mads@kiilerich.com>
parents: 8319
diff changeset
124 sys.stderr.write("Error: simple merge failed and %s is left with conflict markers. Resolve the conflicts, then use 'hg resolve -m'.\n" % output)
8316
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
125 sys.stderr.write('Resolve with e.g.: kdiff3 %s %s %s -o %s\n' % (basekeep, localkeep, otherkeep, output))
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
126 sys.exit(ret)
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
127
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
128 os.remove(localkeep)
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
129
46e78e583ed3 scripts/i18n: add command 'normalized-merge' for use with Mercurial's 'merge-tool' option
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8315
diff changeset
130 @cli.command()
8315
93dabafa567e scripts/i18n: add command 'normalized-diff'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8314
diff changeset
131 @click.argument('file1')
93dabafa567e scripts/i18n: add command 'normalized-diff'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8314
diff changeset
132 @click.argument('file2')
8317
5553ecc962e0 scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents: 8316
diff changeset
133 @click.option('--merge-pot-file', default=None)
5553ecc962e0 scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents: 8316
diff changeset
134 @click.option('--strip/--no-strip', default=False)
5553ecc962e0 scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents: 8316
diff changeset
135 def normalized_diff(file1, file2, merge_pot_file, strip):
8315
93dabafa567e scripts/i18n: add command 'normalized-diff'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8314
diff changeset
136 """Compare two files while transparently normalizing them."""
8317
5553ecc962e0 scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents: 8316
diff changeset
137 sys.exit(i18n_utils._normalized_diff(file1, file2, merge_pot_file=merge_pot_file, strip=strip))
8314
ae9d205f4407 scripts/i18n: add command 'normalize-po-files'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 8313
diff changeset
138
8313
4bc712f1ec93 scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff changeset
139 if __name__ == '__main__':
4bc712f1ec93 scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff changeset
140 cli()