mirror of
https://github.com/Prowlarr/Indexers.git
synced 2025-12-20 02:58:28 +00:00
script:(validate) add flexible folder structure support
This commit is contained in:
committed by
bakerboy448
parent
9b84483294
commit
891ab5b2a4
@@ -164,18 +164,78 @@ def validate_file_against_schema(yaml_path, schema, all_errors=False):
|
||||
except Exception as e:
|
||||
return False, f"Error validating {yaml_path}: {str(e)}"
|
||||
|
||||
def validate_files_in_directory(directory, schema_path, all_errors=False):
|
||||
"""Validate all YAML files in a directory against a single schema."""
|
||||
success = True
|
||||
error_count = 0
|
||||
total_files = 0
|
||||
|
||||
schema = load_json_schema(schema_path)
|
||||
if schema is None:
|
||||
print(f"Error: Failed to load schema from {schema_path}")
|
||||
return False
|
||||
|
||||
# Find all YAML files in directory
|
||||
yaml_files = []
|
||||
for extension in YAML_EXTENSIONS:
|
||||
yaml_files.extend(glob.glob(os.path.join(directory, extension)))
|
||||
|
||||
if not yaml_files:
|
||||
print(f"No YAML files found in {directory}")
|
||||
return True # Not an error if no files to validate
|
||||
|
||||
for yaml_file in sorted(yaml_files):
|
||||
# Skip schema.json files
|
||||
if os.path.basename(yaml_file) == SCHEMA_FILENAME:
|
||||
continue
|
||||
|
||||
total_files += 1
|
||||
is_valid, error_msg = validate_file_against_schema(yaml_file, schema, all_errors)
|
||||
|
||||
if not is_valid:
|
||||
print(f"FAIL: {error_msg}")
|
||||
success = False
|
||||
error_count += 1
|
||||
else:
|
||||
print(f"PASS: {os.path.basename(yaml_file)}")
|
||||
|
||||
print(f"\nValidation Summary:")
|
||||
print(f"Total files: {total_files}")
|
||||
print(f"Errors: {error_count}")
|
||||
print(f"Success: {total_files - error_count}")
|
||||
|
||||
return success
|
||||
|
||||
def validate_directory(definitions_dir, all_errors=False):
|
||||
"""Validate all YAML files in a definitions directory."""
|
||||
success = True
|
||||
error_count = 0
|
||||
total_files = 0
|
||||
|
||||
# Find all version directories
|
||||
# Check for schema.json in root directory first (Jackett-style)
|
||||
root_schema_path = os.path.join(definitions_dir, SCHEMA_FILENAME)
|
||||
if os.path.exists(root_schema_path):
|
||||
print(f"Found root schema, validating files in {definitions_dir}")
|
||||
return validate_files_in_directory(definitions_dir, root_schema_path, all_errors)
|
||||
|
||||
# Find all version directories (Prowlarr-style)
|
||||
version_dirs = glob.glob(os.path.join(definitions_dir, "v*"))
|
||||
version_dirs.sort()
|
||||
|
||||
if not version_dirs:
|
||||
print(f"No version directories found in {definitions_dir}")
|
||||
print(f"No version directories or root schema found in {definitions_dir}")
|
||||
print(f"Searching for YAML files without schema validation...")
|
||||
yaml_files = []
|
||||
for extension in YAML_EXTENSIONS:
|
||||
yaml_files.extend(glob.glob(os.path.join(definitions_dir, extension)))
|
||||
|
||||
if yaml_files:
|
||||
print(f"Found {len(yaml_files)} YAML files but no schema for validation")
|
||||
for yaml_file in sorted(yaml_files):
|
||||
print(f"SKIP: {os.path.basename(yaml_file)} (no schema)")
|
||||
return False
|
||||
else:
|
||||
print(f"No YAML files found in {definitions_dir}")
|
||||
return False
|
||||
|
||||
for version_dir in version_dirs:
|
||||
|
||||
Reference in New Issue
Block a user