From c1ba085b6f6f00534d0b38cc6503dbae1b3efb33 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Date: Tue, 23 Apr 2024 17:03:14 +0500 Subject: [PATCH] Add catalog validate script to validate catalog structure --- apps_validation/scripts/catalog_validate.py | 39 +++++++++++++++++++++ setup.py | 3 +- 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 apps_validation/scripts/catalog_validate.py diff --git a/apps_validation/scripts/catalog_validate.py b/apps_validation/scripts/catalog_validate.py new file mode 100644 index 0000000..191f902 --- /dev/null +++ b/apps_validation/scripts/catalog_validate.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python +import argparse + +from apps_validation.exceptions import CatalogDoesNotExist, ValidationErrors +from apps_validation.validation.validate_catalog import validate_catalog + + +def validate(catalog_path): + + try: + validate_catalog(catalog_path) + except CatalogDoesNotExist: + print(f'[\033[91mFAILED\x1B[0m]\tSpecified {catalog_path!r} path does not exist') + exit(1) + except ValidationErrors as verrors: + print('[\033[91mFAILED\x1B[0m]\tFollowing validation failures were found:') + for index, verror in enumerate(verrors.errors): + print(f'[\033[91m{index}\x1B[0m]\t{verror}') + exit(1) + else: + print('[\033[92mOK\x1B[0m]\tPASSED VALIDATION CHECKS') + + +def main(): + parser = argparse.ArgumentParser() + subparsers = parser.add_subparsers(help='sub-command help', dest='action') + + parser_setup = subparsers.add_parser('validate', help='Validate TrueNAS catalog') + parser_setup.add_argument('--path', help='Specify path of TrueNAS catalog') + + args = parser.parse_args() + if args.action == 'validate': + validate(args.path) + else: + parser.print_help() + + +if __name__ == '__main__': + main() diff --git a/setup.py b/setup.py index 4119e3b..b429456 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,8 @@ platforms='any', entry_points={ 'console_scripts': [ - 'dev_charts_validate = apps_validation.scripts.dev_apps_validate:main', + 'apps_catalog_validate = catalog_validation.scripts.catalog_validate:main', + 'apps_dev_charts_validate = apps_validation.scripts.dev_apps_validate:main', # TODO: Remove apps_prefix ], }, )