Show More
@@ -14,6 +14,8 b'' | |||
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | 16 | |
|
17 | import sys | |
|
18 | ||
|
17 | 19 | import click |
|
18 | 20 | |
|
19 | 21 | import i18n_utils |
@@ -48,6 +50,12 b' def normalize_po_files(po_files):' | |||
|
48 | 50 | for po_file in po_files: |
|
49 | 51 | i18n_utils._normalize_po_file(po_file, strip=True) |
|
50 | 52 | |
|
53 | @cli.command() | |
|
54 | @click.argument('file1') | |
|
55 | @click.argument('file2') | |
|
56 | def normalized_diff(file1, file2): | |
|
57 | """Compare two files while transparently normalizing them.""" | |
|
58 | sys.exit(i18n_utils._normalized_diff(file1, file2, strip=True)) | |
|
51 | 59 | |
|
52 | 60 | if __name__ == '__main__': |
|
53 | 61 | cli() |
@@ -15,7 +15,9 b' from __future__ import print_function' | |||
|
15 | 15 | |
|
16 | 16 | import os |
|
17 | 17 | import re |
|
18 | import shutil | |
|
18 | 19 | import subprocess |
|
20 | import tempfile | |
|
19 | 21 | |
|
20 | 22 | |
|
21 | 23 | do_debug = False # set from scripts/i18n --debug |
@@ -165,3 +167,19 b' def _normalize_po_file(po_file, strip=Fa' | |||
|
165 | 167 | normalized_content = _normalize_po(raw_content) |
|
166 | 168 | dest.write(normalized_content) |
|
167 | 169 | os.rename(po_tmp, po_file) |
|
170 | ||
|
171 | def _normalized_diff(file1, file2, strip=False): | |
|
172 | # Create temporary copies of both files | |
|
173 | temp1 = tempfile.NamedTemporaryFile(prefix=os.path.basename(file1)) | |
|
174 | temp2 = tempfile.NamedTemporaryFile(prefix=os.path.basename(file2)) | |
|
175 | debug('normalized_diff: %s -> %s / %s -> %s' % (file1, temp1.name, file2, temp2.name)) | |
|
176 | shutil.copyfile(file1, temp1.name) | |
|
177 | shutil.copyfile(file2, temp2.name) | |
|
178 | # Normalize them in place | |
|
179 | _normalize_po_file(temp1.name, strip=strip) | |
|
180 | _normalize_po_file(temp2.name, strip=strip) | |
|
181 | # Now compare | |
|
182 | try: | |
|
183 | runcmd(['diff', '-u', temp1.name, temp2.name]) | |
|
184 | except subprocess.CalledProcessError as e: | |
|
185 | return e.returncode |
General Comments 0
You need to be logged in to leave comments.
Login now