Mercurial > kallithea
annotate scripts/i18n @ 8773:c6b4788337b5
repo-scan: overwrite_git_hooks also implies install_git_hooks
(Otherwise, we should probably report an error when ignoring it.)
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Fri, 20 Nov 2020 16:11:55 +0100 |
parents | 68eee0e7f4f5 |
children | 419329d436fd |
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 import i18n_utils |
4bc712f1ec93
scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff
changeset
|
23 |
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 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
|
27 |
ae9d205f4407
scripts/i18n: add command 'normalize-po-files'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
8313
diff
changeset
|
28 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
|
29 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
|
30 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
|
31 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
|
32 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
|
33 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
|
34 important changes. |
8313
4bc712f1ec93
scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff
changeset
|
35 """ |
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 @click.group() |
4bc712f1ec93
scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff
changeset
|
38 @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
|
39 def cli(debug): |
4bc712f1ec93
scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff
changeset
|
40 if (debug): |
4bc712f1ec93
scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff
changeset
|
41 i18n_utils.do_debug = True |
4bc712f1ec93
scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff
changeset
|
42 pass |
4bc712f1ec93
scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff
changeset
|
43 |
8314
ae9d205f4407
scripts/i18n: add command 'normalize-po-files'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
8313
diff
changeset
|
44 @cli.command() |
ae9d205f4407
scripts/i18n: add command 'normalize-po-files'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
8313
diff
changeset
|
45 @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
|
46 @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
|
47 @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
|
48 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
|
49 """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
|
50 |
8317
5553ecc962e0
scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents:
8316
diff
changeset
|
51 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
|
52 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
|
53 |
5553ecc962e0
scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents:
8316
diff
changeset
|
54 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
|
55 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
|
56 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
|
57 """ |
ae9d205f4407
scripts/i18n: add command 'normalize-po-files'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
8313
diff
changeset
|
58 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
|
59 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
|
60 |
8315
93dabafa567e
scripts/i18n: add command 'normalized-diff'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
8314
diff
changeset
|
61 @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
|
62 @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
|
63 @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
|
64 @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
|
65 @click.argument('output') |
8317
5553ecc962e0
scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents:
8316
diff
changeset
|
66 @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
|
67 @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
|
68 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
|
69 """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
|
70 |
8317
5553ecc962e0
scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents:
8316
diff
changeset
|
71 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
|
72 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
|
73 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
|
74 |
5553ecc962e0
scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents:
8316
diff
changeset
|
75 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
|
76 running the merge tool. |
5553ecc962e0
scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents:
8316
diff
changeset
|
77 |
5553ecc962e0
scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents:
8316
diff
changeset
|
78 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
|
79 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
|
80 |
5553ecc962e0
scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents:
8316
diff
changeset
|
81 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
|
82 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
|
83 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
|
84 |
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 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
|
86 [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
|
87 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
|
88 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
|
89 |
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 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
|
91 """ |
8599
68eee0e7f4f5
isort: upgrade to 5.1.2
Mads Kiilerich <mads@kiilerich.com>
parents:
8335
diff
changeset
|
92 from mercurial import context, simplemerge |
68eee0e7f4f5
isort: upgrade to 5.1.2
Mads Kiilerich <mads@kiilerich.com>
parents:
8335
diff
changeset
|
93 from mercurial import ui as uimod |
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
|
94 |
8335
80ffe0f29857
scripts/i18n: tweak messages
Mads Kiilerich <mads@kiilerich.com>
parents:
8319
diff
changeset
|
95 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
|
96 |
8317
5553ecc962e0
scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents:
8316
diff
changeset
|
97 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
|
98 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
|
99 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
|
100 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
|
101 |
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
|
102 # 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
|
103 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
|
104 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
|
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 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
|
107 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
|
108 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
|
109 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
|
110 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
|
111 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
|
112 ) |
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 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
|
114 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
|
115 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
|
116 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
|
117 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
|
118 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
|
119 shutil.copyfile(other, otherkeep) |
8335
80ffe0f29857
scripts/i18n: tweak messages
Mads Kiilerich <mads@kiilerich.com>
parents:
8319
diff
changeset
|
120 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
|
121 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
|
122 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
|
123 |
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
|
124 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
|
125 |
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 @cli.command() |
8315
93dabafa567e
scripts/i18n: add command 'normalized-diff'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
8314
diff
changeset
|
127 @click.argument('file1') |
93dabafa567e
scripts/i18n: add command 'normalized-diff'
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
8314
diff
changeset
|
128 @click.argument('file2') |
8317
5553ecc962e0
scripts/i18n: introduce --merge-pot-file to control normalization
Mads Kiilerich <mads@kiilerich.com>
parents:
8316
diff
changeset
|
129 @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
|
130 @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
|
131 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
|
132 """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
|
133 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
|
134 |
8313
4bc712f1ec93
scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff
changeset
|
135 if __name__ == '__main__': |
4bc712f1ec93
scripts/i18n: introduce new i18n maintenance script
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents:
diff
changeset
|
136 cli() |