spark: add path validator utility with validation results

This commit is contained in:
spark committed 2026-10-31 03:33:09 +00:00
1 parent 97feac2176
commit 607c2125d2
2 files changed
+70

No files matched your search

+50
View File
@@ -0,0 +1,50 @@
#!/usr/bin/env python3
"""Path validator - checks if paths exist and reports their properties."""
import sys
import stat
from pathlib import Path
def validate_path(path_str):
"""Validate a path and return its properties."""
path = Path(path_str)
result = {
'path': str(path),
'exists': path.exists(),
'is_absolute': path.is_absolute(),
'type': None,
'permissions': None
}
if result['exists']:
if path.is_file():
result['type'] = 'file'
elif path.is_dir():
result['type'] = 'directory'
elif path.is_symlink():
result['type'] = 'symlink'
else:
result['type'] = 'other'
st = path.stat()
result['permissions'] = stat.filemode(st.st_mode)
return result
def main():
if len(sys.argv) < 2:
print("Usage: path_validator.py <path1> [path2] ...")
sys.exit(1)
for path_str in sys.argv[1:]:
result = validate_path(path_str)
print(f"Path: {result['path']}")
print(f" Exists: {result['exists']}")
print(f" Absolute: {result['is_absolute']}")
print(f" Type: {result['type']}")
if result['permissions']:
print(f" Permissions: {result['permissions']}")
print()
if __name__ == "__main__":
main()
+20
View File
@@ -0,0 +1,20 @@
Path Validation Results
==================================================
Path: /root/.hermes/profiles/spark
Exists: True
Absolute: True
Type: directory
Permissions: drwx------
Path: /root/.hermes/wizard-outputs/spark
Exists: True
Absolute: True
Type: directory
Permissions: drw-------
Path: /nonexistent/path
Exists: False
Absolute: True
Type: None