示例#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
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 check_xform(path_to_xform):
    """Run ODK Validate against the XForm in `path_to_xform`.

    Returns an array of warnings if the form is valid.
    Throws an exception if it is not
    """
    # check for available java version
    check_java_version()

    # resultcode indicates validity of the form
    # timeout indicates whether validation ran out of time to complete
    # stdout is not used because it has some warnings that always
    # appear and can be ignored.
    # stderr is treated as a warning if the form is valid or an error
    # if it is invalid.
    returncode, timeout, _stdout, stderr = _call_validator(
        path_to_xform=path_to_xform)
    warnings = []
    stderr = decode_stream(stderr)

    if timeout:
        return ["XForm took to long to completely validate."]
    else:
        if returncode > 0:  # Error invalid
            raise ODKValidateError("ODK Validate Errors:\n" +
                                   ErrorCleaner.odk_validate(stderr))
        elif returncode == 0:
            if stderr:
                warnings.append("ODK Validate Warnings:\n" + stderr)
        elif returncode < 0:
            return ["Bad return code from ODK Validate."]

    return warnings
示例#5
0
def check_xform(path_to_xform):
    """
    Returns an array of warnings if the form is valid.
    Throws an exception if it is not
    """
    # provide useful error message if java is not installed
    if not _java_installed():
        raise EnvironmentError(
            "pyxform odk validate dependency: java not found")

    # resultcode indicates validity of the form
    # timeout indicates whether validation ran out of time to complete
    # stdout is not used because it has some warnings that always
    # appear and can be ignored.
    # stderr is treated as a warning if the form is valid or an error
    # if it is invalid.
    returncode, timeout, stdout, stderr = run_popen_with_timeout(
        ["java", "-jar", ODK_VALIDATE_JAR, path_to_xform], 100)
    warnings = []
    stderr = decode_stream(stderr)

    if timeout:
        return ["XForm took to long to completely validate."]
    else:
        if returncode > 0:  # Error invalid
            raise ODKValidateError(
                'ODK Validate Errors:\n' + ErrorCleaner.odk_validate(stderr))
        elif returncode == 0:
            if stderr:
                warnings.append('ODK Validate Warnings:\n' + stderr)
            return warnings
        elif returncode < 0:
            return ["Bad return code from ODK Validate."]
示例#6
0
def check_xform(path_to_xform):
    """Run ODK Validate against the XForm in `path_to_xform`.

    Returns an array of warnings if the form is valid.
    Throws an exception if it is not
    """
    # check for available java version
    check_java_version()

    # resultcode indicates validity of the form
    # timeout indicates whether validation ran out of time to complete
    # stdout is not used because it has some warnings that always
    # appear and can be ignored.
    # stderr is treated as a warning if the form is valid or an error
    # if it is invalid.
    returncode, timeout, _stdout, stderr = _call_validator(path_to_xform=path_to_xform)
    warnings = []
    stderr = decode_stream(stderr)

    if timeout:
        return ["XForm took to long to completely validate."]
    else:
        if returncode > 0:  # Error invalid
            raise ODKValidateError(
                b"ODK Validate Errors:\n"
                + ErrorCleaner.odk_validate(stderr).encode("utf-8")
            )
        elif returncode == 0:
            if stderr:
                warnings.append("ODK Validate Warnings:\n" + stderr)
        elif returncode < 0:
            return ["Bad return code from ODK Validate."]

    return warnings