|
25 | 25 |
|
26 | 26 | from __future__ import annotations |
27 | 27 |
|
| 28 | +import os |
28 | 29 | import re |
29 | 30 | import subprocess |
30 | 31 | import tempfile |
@@ -614,42 +615,40 @@ def check_pofile(self, po_file: PoFile) -> list[PoReport]: |
614 | 615 |
|
615 | 616 | return reports |
616 | 617 |
|
617 | | - def check_files(self, files: list[str]) -> list[tuple[str, list[PoReport]]]: |
618 | | - """Check translations in PO files. |
| 618 | + def check_file(self, filename: str) -> list[PoReport]: |
| 619 | + """Check compilation and translations in a PO file. |
619 | 620 |
|
620 | 621 | Return a list of tuples: (filename, [PoReport, PoReport, ...]). |
621 | 622 | """ |
622 | | - result = [] |
| 623 | + po_file = PoFile(filename) |
| 624 | + # read the file |
| 625 | + try: |
| 626 | + po_file.read() |
| 627 | + except OSError as exc: |
| 628 | + return [PoReport(str(exc), "read", po_file.filename)] |
| 629 | + # compile the file (except if disabled) |
| 630 | + compile_rc = 0 |
| 631 | + if self.checks["compile"]: |
| 632 | + compile_output, compile_rc = po_file.compile() |
| 633 | + if compile_rc != 0: |
| 634 | + # compilation failed |
| 635 | + return [PoReport(compile_output, "compile", po_file.filename)] |
| 636 | + # compilation OK |
| 637 | + return self.check_pofile(po_file) |
623 | 638 |
|
624 | | - for filename in files: |
625 | | - po_file = PoFile(filename) |
626 | | - # read the file |
627 | | - try: |
628 | | - po_file.read() |
629 | | - except OSError as exc: |
630 | | - result.append( |
631 | | - ( |
632 | | - po_file.filename, |
633 | | - [PoReport(str(exc), "read", po_file.filename)], |
634 | | - ), |
635 | | - ) |
636 | | - continue |
637 | | - # compile the file (except if disabled) |
638 | | - compile_rc = 0 |
639 | | - if self.checks["compile"]: |
640 | | - compile_output, compile_rc = po_file.compile() |
641 | | - if compile_rc == 0: |
642 | | - # compilation OK |
643 | | - result.append((po_file.filename, self.check_pofile(po_file))) |
644 | | - else: |
645 | | - # compilation failed |
646 | | - result.append( |
647 | | - ( |
648 | | - po_file.filename, |
649 | | - [ |
650 | | - PoReport(compile_output, "compile", po_file.filename), |
651 | | - ], |
652 | | - ), |
653 | | - ) |
| 639 | + def check_files(self, files: list[str]) -> list[tuple[str, list[PoReport]]]: |
| 640 | + """Check compilation and translations in PO files. |
654 | 641 |
|
| 642 | + Return a list of tuples: (filename, [PoReport, PoReport, ...]). |
| 643 | + """ |
| 644 | + result: list[tuple[str, list[PoReport]]] = [] |
| 645 | + for path in files: |
| 646 | + if Path(path).is_dir(): |
| 647 | + for root, _, filenames in os.walk(path): |
| 648 | + for filename in filenames: |
| 649 | + if filename.endswith(".po"): |
| 650 | + path_po = Path(root) / filename |
| 651 | + result.append((str(path_po), self.check_file(str(path_po)))) |
| 652 | + else: |
| 653 | + result.append((path, self.check_file(path))) |
655 | 654 | return result |
0 commit comments