Files
auto-archiver/src/auto_archiver/core/validators.py
Patrick Robertson b301f60ea3 Fix using validators set in __manifest__.py
E.g. you can use the validator 'is_file' to check if a config is a valid file
2025-02-04 13:37:26 +01:00

19 lines
596 B
Python

# used as validators for config values. Should raise an exception if the value is invalid.
from pathlib import Path
import argparse
def example_validator(value):
if "example" not in value:
raise argparse.ArgumentTypeError(f"{value} is not a valid value for this argument")
return value
def positive_number(value):
if value < 0:
raise argparse.ArgumentTypeError(f"{value} is not a positive number")
return value
def valid_file(value):
if not Path(value).is_file():
raise argparse.ArgumentTypeError(f"File '{value}' does not exist.")
return value