예제 #1
0
def msgfmt_check(po_contents, ispot=False, with_exceptions=True):
    """Run a `msgfmt -c` on the file contents.

    Raise a PoParseError in case the stderror has errors/warnings or
    the command execution returns Error.
    """
    try:
        if ispot:
            command = 'msgfmt -o /dev/null --check-format --check-domain -'
        else:
            command = 'msgfmt -o /dev/null -c -'
        status, stdout, stderr = run_command(
            command, _input=po_contents.encode('UTF-8'),
            with_extended_output=True, with_exceptions=with_exceptions
        )
        # Not sure why msgfmt sends its output to stderr instead of stdout
        #if 'warning:' in stderr or 'too many errors, aborting' in stderr:
        if 'too many errors, aborting' in stderr:
            logger.warning('msgfmt %s: %s' % (status, stderr, ))
            raise CommandError(command, status, stderr)
    except CommandError, e:
        logger.warning("pofile: The 'msgfmt -c' check failed.")
        raise PoParseError, ugettext("Your file failed a correctness check "
            "(msgfmt -c). It returned the following error:\n\n%s\n\n"
            "Please run this command on "
            "your system to see the errors for yourself." % e.stderr.lstrip('<stdin>:'))
예제 #2
0
파일: pofile.py 프로젝트: hfeeki/transifex
def msgfmt_check(po_contents, ispot=False, with_exceptions=True):
    """
    Run a `msgfmt -c` on the file contents.

    Raise a FileCheckError in case the stderror has errors/warnings or
    the command execution returns Error.
    """
    try:
        if ispot:
            command = "msgfmt -o /dev/null --check-format --check-domain -"
        else:
            command = "msgfmt -o /dev/null -c -"
        status, stdout, stderr = run_command(
            command, _input=po_contents, with_extended_output=True, with_exceptions=with_exceptions
        )
        # Not sure why msgfmt sends its output to stderr instead of stdout
        # if 'warning:' in stderr or 'too many errors, aborting' in stderr:
        if "too many errors, aborting" in stderr:
            raise CommandError(command, status, stderr)
    except CommandError:
        logger.debug("pofile: The 'msgfmt -c' check failed.")
        raise FileCheckError, ugettext(
            "Your file failed a correctness check "
            "(msgfmt -c). Please run this command on "
            "your system to see the errors."
        )