Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: make verify-mo.py compatible with securedrop #1668

Merged
merged 2 commits into from
Sep 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions scripts/verify-mo.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@
import os
import shlex
import subprocess
from collections.abc import Iterator
from pathlib import Path
from types import TracebackType
from typing import Optional, Set
from typing import Any, Iterator, Optional, Set
cfm marked this conversation as resolved.
Show resolved Hide resolved

import polib
from translate.tools.pocompile import convertmo
Expand All @@ -34,7 +32,8 @@
parser.add_argument(
"locale",
nargs="+",
help="""one or more locale directories, each of which must contain an "LC_MESSAGES" directory""",
help="""one or more locale directories, each of which must contain an
"LC_MESSAGES" directory""",
)
parser.add_argument(
"--domain", default="messages", help="""the gettext domain to load (defaults to "messages")"""
Expand All @@ -60,9 +59,9 @@ def __enter__(self) -> "CatalogVerifier":

def __exit__(
self,
exc_type: Optional[type[BaseException]],
exc_value: Optional[BaseException],
traceback: Optional[TracebackType],
exc_type: Optional[Any],
exc_value: Optional[Any],
traceback: Optional[Any],
) -> None:
"""Clean up."""

Expand Down Expand Up @@ -99,7 +98,7 @@ def diffoscope_args(self, a: Path, b: Path, filtered: bool = True) -> Iterator[s
for stray in self.strays:
yield f"--diff-mask {shlex.quote(stray)}" # tell diffoscope to mask strays
yield "| grep -Fv '[masked]'" # ignore things we've masked
yield "| grep -E '│ (-|\+)msg(id|str)'" # ignore context; we only care about real diffs
yield "| grep -E '│ (-|\\+)msg(id|str)'" # ignore context; we only care about real diffs

def diffoscope_call(
self, a: Path, b: Path, filtered: bool = True
Expand All @@ -113,7 +112,8 @@ def diffoscope_call(
# We silence Bandit and Semgrep warnings on `shell=True`
# because we want to inherit the Python virtual environment
# in which we're invoked.
return subprocess.run( # nosec B602 nosemgrep: python.lang.security.audit.subprocess-shell-true.subprocess-shell-true
# nosemgrep: python.lang.security.audit.subprocess-shell-true.subprocess-shell-true
return subprocess.run( # nosec B602
cmd,
capture_output=True,
env=os.environ,
Expand Down