padpo/padpo/checkers/baseclass.py

40 lines
1.0 KiB
Python
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Base class for checkers."""
from abc import ABC, abstractmethod
import simplelogging
from padpo.pofile import PoFile, PoItem
log = simplelogging.get_logger()
class Checker(ABC):
"""Base class for checkers."""
name = "UnknownChecker" # name displayed in error messages
def check_file(self, pofile: PoFile):
"""Check a `*.po` file."""
if not isinstance(pofile, PoFile):
log.error("%s is not an instance of PoFile", str(pofile))
for item in pofile.content:
self.check_item(item)
@abstractmethod
def check_item(self, item: PoItem):
"""Check an item in a `*.po` file."""
return NotImplementedError
def add_arguments(self, parser):
"""Let any checker register argparse arguments."""
def configure(self, args):
"""Store the result of parse_args, to get back arguments from self.add_arguments."""
def replace_quotes(match):
"""Replace match with « xxxxxxx »."""
length = len(match.group(0)) - 4
return "« " + length * "x" + " »"