Skip to content

Commit 2b05279

Browse files
committed
Agrega pequeñas mejores a check_spell.po
* Imprime mapeo de archivos sólo si hay errores * Path.glob() produce un map en vez de una lista. Este map se consume en el primer loop (al crear los archivos temporales), después del cual no se pueden consumir más elementos. Esto quiere decir que, en caso de haber fallos de ortografía, el último for que imprime el mapeo entre archivos no imprimía nada, dado que el objecto map ya no entregaba resultados. * Usa shutil para copiar de un archivo a otro. Signed-off-by: Rodrigo Tobar <[email protected]>
1 parent be65505 commit 2b05279

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

scripts/check_spell.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55

66
from pathlib import Path
7+
import shutil
78
import sys
89
import tempfile
910

@@ -43,7 +44,7 @@ def check_spell(po_files=None):
4344

4445
# Run pospell either against all files or the file given on the command line
4546
if not po_files:
46-
po_files = Path(".").glob("*/*.po")
47+
po_files = list(Path(".").glob("*/*.po"))
4748

4849
# Workaround issue #3324 FIXME
4950
# It seems that all code snippets have line breaks '\n'. This causes the
@@ -52,10 +53,9 @@ def check_spell(po_files=None):
5253
# Create temporary copies of the original files.
5354
po_files_tmp = []
5455
for po_file in po_files:
55-
with open(tempfile.mktemp(), "w") as temp_file:
56-
# Copy content of the .po file
57-
with open(po_file, "r", encoding="utf-8") as f:
58-
temp_file.write(f.read())
56+
with open(tempfile.mktemp(), "wb") as temp_file:
57+
with open(po_file, "rb") as original_file:
58+
shutil.copyfileobj(original_file, temp_file)
5959
po_files_tmp.append(temp_file.name)
6060

6161
# Don't translate probably code entries
@@ -66,8 +66,9 @@ def check_spell(po_files=None):
6666
polib_temp_file.save()
6767

6868
detected_errors = pospell.spell_check(po_files_tmp, personal_dict=output_filename, language="es_ES")
69-
for tmp, orig in zip(po_files_tmp, po_files):
70-
print(tmp, " == ", orig)
69+
if detected_errors:
70+
for tmp, orig in zip(po_files_tmp, po_files):
71+
print(tmp, " == ", orig)
7172
return detected_errors
7273

7374

0 commit comments

Comments
 (0)