def validate_user_options(**user_args: str) -> bool:
        """Validate the user's arguments.

        Raises a value error is something is not valid.

        Args:
            **user_args:

        """
        option_validators = validators.OptionValidator()
        option_validators.register_validator(
            'Output', validators.DirectoryValidation(key="Output")
        )

        option_validators.register_validator(
            'Input', validators.DirectoryValidation(key="Input")
        )
        invalid_messages = []
        for validation in [
            option_validators.get("Output"),
            option_validators.get("Input")

        ]:
            if not validation.is_valid(**user_args):
                invalid_messages.append(validation.explanation(**user_args))

        if len(invalid_messages) > 0:
            raise ValueError("\n".join(invalid_messages))
        return True
    def validate_user_options(**user_args: Dict[str, str]) -> bool:
        """Make sure that the options the user provided is valid.

        Args:
            **user_args:

        """
        option_validators = validators.OptionValidator()
        option_validators.register_validator(
            key=OPTION_USER_INPUT,
            validator=validators.DirectoryValidation(key=OPTION_USER_INPUT))
        option_validators.register_validator(
            key="Input Required",
            validator=RequiredValueValidation(key=OPTION_USER_INPUT))
        option_validators.register_validator(
            key="Identifier type Required",
            validator=RequiredValueValidation(key=IDENTIFIER_TYPE))
        option_validators.register_validator(
            key="Match 035 and 955",
            validator=DependentTruthyValueValidation(
                key=OPTION_035_FIELD, required_true_keys=[OPTION_955_FIELD]))

        invalid_messages = [
            validation.explanation(**user_args) for validation in [
                option_validators.get(OPTION_USER_INPUT),
                option_validators.get("Input Required"),
                option_validators.get("Identifier type Required"),
                option_validators.get('Match 035 and 955')
            ] if not validation.is_valid(**user_args)
        ]
        if invalid_messages:
            raise ValueError("\n".join(invalid_messages))
        return True
Beispiel #3
0
    def validate_user_options(**user_args: str) -> bool:
        """Validate the user's arguments.

        Raises a value error is something is not valid.

        Args:
            **user_args:

        """
        user_arguments: UserArgs = typing.cast(UserArgs, user_args)
        option_validators = validators.OptionValidator()

        option_validators.register_validator(
            'At least one output',
            OutputValidator(at_least_one_of=[
                "Output Digital Library", "Output HathiTrust"
            ]))
        option_validators.register_validator(
            'Input', validators.DirectoryValidation(key="Input"))
        invalid_messages: List[str] = []
        for validation in [
                option_validators.get('At least one output'),
                option_validators.get("Input")
        ]:
            if not validation.is_valid(**user_arguments):
                invalid_messages.append(
                    validation.explanation(**user_arguments))

        if len(invalid_messages) > 0:
            raise ValueError("\n".join(invalid_messages))
        return True
    def validate_user_options(**user_args: Dict[str, str]) -> bool:
        """Make sure that the options the user provided is valid.

        Args:
            **user_args:

        """
        option_validators = validators.OptionValidator()
        option_validators.register_validator(
            key='Input', validator=validators.DirectoryValidation(key="Input"))
        option_validators.register_validator(
            key="Input Required",
            validator=RequiredValueValidation(key="Input"))
        option_validators.register_validator(
            key="Identifier type Required",
            validator=RequiredValueValidation(key="Identifier type"))
        option_validators.register_validator(
            key="Match 035 and 955",
            validator=DependentTruthyValueValidation(
                key='Add 035 field', required_true_keys=['Add 955 field']))

        invalid_messages = []
        for validation in [
                option_validators.get("Input"),
                option_validators.get("Input Required"),
                option_validators.get("Identifier type Required"),
                option_validators.get('Match 035 and 955')
        ]:
            if not validation.is_valid(**user_args):
                invalid_messages.append(validation.explanation(**user_args))

        if len(invalid_messages) > 0:
            raise ValueError("\n".join(invalid_messages))
        return True
    def validate_user_options(**user_args: str) -> bool:
        """Validate the user's arguments.

        Raises a value error is something is not valid.

        Args:
            **user_args:

        """
        user_arguments: UserArgs = typing.cast(UserArgs, user_args)
        option_validators = validators.OptionValidator()

        option_validators.register_validator(
            'At least one output',
            MinimumOutputsValidator(
                at_least_one_of=[OUTPUT_DIGITAL_LIBRARY, OUTPUT_HATHITRUST]))
        option_validators.register_validator(
            'At least one output exists',
            OutputsValidValuesValidator(
                keys_to_check=[OUTPUT_DIGITAL_LIBRARY, OUTPUT_HATHITRUST]))

        option_validators.register_validator(
            USER_INPUT_PATH,
            validators.DirectoryValidation(key=USER_INPUT_PATH))
        invalid_messages: List[str] = []
        for validation in [
                option_validators.get('At least one output'),
                option_validators.get('At least one output exists'),
                option_validators.get(USER_INPUT_PATH)
        ]:
            if not validation.is_valid(**user_arguments):  # type: ignore
                invalid_messages.append(
                    validation.explanation(**user_arguments)  # type: ignore
                )

        if len(invalid_messages) > 0:
            raise ValueError("\n".join(invalid_messages))
        return True
Beispiel #6
0
 def __init__(self, at_least_one_of: List[str]) -> None:
     super().__init__()
     self.keys = at_least_one_of
     self._validators = []
     for k in self.keys:
         self._validators.append(validators.DirectoryValidation(k))