예제 #1
0
def check_xform(path_to_xform):
    """
    Check the form with the Enketo validator.

    - return code 1: raise error with the stderr content.
    - return code 0: append warning with the stdout content (possibly none).

    :param path_to_xform: Path to the XForm to be validated.
    :return: warnings or List[str]
    """
    if not _node_installed():
        raise EnvironmentError(
            "pyxform enketo validate dependency: node not found")

    returncode, timeout, stdout, stderr = run_popen_with_timeout(
        ["node", ENKETO_VALIDATE_JS, path_to_xform], 100)
    warnings = []
    stderr = decode_stream(stderr)
    stdout = decode_stream(stdout)

    if timeout:
        return ["XForm took to long to completely validate."]
    else:
        if returncode > 0:  # Error invalid
            raise EnketoValidateError('Enketo Validate Errors:\n' +
                                      ErrorCleaner.enketo_validate(stderr))
        elif returncode == 0:
            if stdout:
                warnings.append('Enketo Validate Warnings:\n' + stdout)
            return warnings
        elif returncode < 0:
            return ["Bad return code from Enketo Validate."]
예제 #2
0
def check_xform(path_to_xform):
    """
    Check the form with the Enketo validator.

    - return code 1: raise error with the stderr content.
    - return code 0: append warning with the stdout content (possibly none).

    :param path_to_xform: Path to the XForm to be validated.
    :param bin_path: Path to the Enketo-validate binary.
    :return: warnings or List[str]
    """
    if not install_exists():
        raise EnvironmentError(
            "Enketo-validate dependency not found. "
            "Please use the updater tool to install the latest version.")

    returncode, timeout, stdout, stderr = _call_validator(
        path_to_xform=path_to_xform)
    warnings = []
    stderr = decode_stream(stderr)
    stdout = decode_stream(stdout)

    if timeout:
        return ["XForm took to long to completely validate."]
    else:
        if returncode > 0:  # Error invalid
            raise EnketoValidateError(
                'Enketo Validate Errors:\n' +
                ErrorCleaner.enketo_validate(stderr))
        elif returncode == 0:
            if stdout:
                warnings.append('Enketo Validate Warnings:\n' + stdout)
            return warnings
        elif returncode < 0:
            return ["Bad return code from Enketo Validate."]
예제 #3
0
파일: __init__.py 프로젝트: XLSForm/pyxform
def check_xform(path_to_xform):
    """
    Check the form with the Enketo validator.

    - return code 1: raise error with the stderr content.
    - return code 0: append warning with the stdout content (possibly none).

    :param path_to_xform: Path to the XForm to be validated.
    :param bin_path: Path to the Enketo-validate binary.
    :return: warnings or List[str]
    """
    if not install_exists():
        raise EnvironmentError(
            "Enketo-validate dependency not found. "
            "Please use the updater tool to install the latest version."
        )

    returncode, timeout, stdout, stderr = _call_validator(path_to_xform=path_to_xform)
    warnings = []
    stderr = decode_stream(stderr)
    stdout = decode_stream(stdout)

    if timeout:
        return ["XForm took to long to completely validate."]
    else:
        if returncode > 0:  # Error invalid
            raise EnketoValidateError(
                "Enketo Validate Errors:\n" + ErrorCleaner.enketo_validate(stderr)
            )
        elif returncode == 0:
            if stdout:
                warnings.append("Enketo Validate Warnings:\n" + stdout)
            return warnings
        elif returncode < 0:
            return ["Bad return code from Enketo Validate."]
예제 #4
0
 def should_clean_enketo_validate_stacktrace(self):
     message = """Error in gugu/gaga\nError in gugu/gaga"""
     cleaned = ErrorCleaner.enketo_validate(message)
     self.assertEqual(cleaned, "Error in gugu/gaga")