spark: add prime checker utility script
This commit is contained in:
1 parent
dfd06b3c27
commit
034e19b62d
6 files changed
+173
No files matched your search
Binary file not shown.
@@ -0,0 +1,65 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Check the Hermes agent environment and spark profile status."""
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def check_hermes_spark():
|
||||
"""Verify Hermes spark profile exists and has correct structure."""
|
||||
errors = []
|
||||
|
||||
# Check profile directory
|
||||
profile_dir = Path("/root/.hermes/profiles/spark")
|
||||
if not profile_dir.exists():
|
||||
errors.append("Profile directory missing")
|
||||
else:
|
||||
# Check cache/scratch exists
|
||||
scratch_dir = profile_dir / "cache" / "scratch"
|
||||
if not scratch_dir.exists():
|
||||
errors.append("Scratch directory missing")
|
||||
|
||||
# Check key files
|
||||
config_file = profile_dir / "config.yaml"
|
||||
if not config_file.exists():
|
||||
errors.append("config.yaml missing")
|
||||
|
||||
return errors
|
||||
|
||||
|
||||
def check_wizard_outputs():
|
||||
"""Verify wizard-outputs/spark directory structure."""
|
||||
errors = []
|
||||
|
||||
output_dir = Path("/root/.hermes/wizard-outputs/spark")
|
||||
if not output_dir.exists():
|
||||
errors.append("wizard-outputs/spark directory missing")
|
||||
return errors
|
||||
|
||||
# Check for key output files
|
||||
required_files = ["results.txt", "env-check.sh"]
|
||||
for fname in required_files:
|
||||
if not (output_dir / fname).exists():
|
||||
errors.append(f"Missing {fname}")
|
||||
|
||||
return errors
|
||||
|
||||
|
||||
def main():
|
||||
all_errors = []
|
||||
|
||||
all_errors.extend(check_hermes_spark())
|
||||
all_errors.extend(check_wizard_outputs())
|
||||
|
||||
if all_errors:
|
||||
print("Verification FAILED:")
|
||||
for err in all_errors:
|
||||
print(f" - {err}")
|
||||
sys.exit(1)
|
||||
else:
|
||||
print("All checks PASSED")
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,74 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Checksum verification tool - verifies SHA256 checksums of files.
|
||||
|
||||
Usage:
|
||||
python3 checksum_verify.py <checksum_file>
|
||||
|
||||
Format of checksum_file:
|
||||
<sha256_hash> <filename>
|
||||
(same as sha256sum output format)
|
||||
"""
|
||||
|
||||
import hashlib
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def compute_sha256(filepath: str) -> str:
|
||||
"""Compute SHA256 hash of a file."""
|
||||
sha256_hash = hashlib.sha256()
|
||||
with open(filepath, "rb") as f:
|
||||
for chunk in iter(lambda: f.read(8192), b""):
|
||||
sha256_hash.update(chunk)
|
||||
return sha256_hash.hexdigest()
|
||||
|
||||
|
||||
def verify_checksums(checksum_file: str) -> bool:
|
||||
"""Verify all checksums in the file. Returns True if all pass."""
|
||||
all_passed = True
|
||||
with open(checksum_file, "r") as f:
|
||||
for line_num, line in enumerate(f, 1):
|
||||
line = line.strip()
|
||||
if not line:
|
||||
continue
|
||||
parts = line.split()
|
||||
if len(parts) < 2:
|
||||
print(f"Line {line_num}: Invalid format - skipping")
|
||||
all_passed = False
|
||||
continue
|
||||
expected_hash = parts[0]
|
||||
filepath = " ".join(parts[1:])
|
||||
|
||||
if not Path(filepath).exists():
|
||||
print(f"FAIL: {filepath} - file not found")
|
||||
all_passed = False
|
||||
continue
|
||||
|
||||
actual_hash = compute_sha256(filepath)
|
||||
if actual_hash == expected_hash:
|
||||
print(f"OK: {filepath}")
|
||||
else:
|
||||
print(f"FAIL: {filepath}")
|
||||
print(f" Expected: {expected_hash}")
|
||||
print(f" Actual: {actual_hash}")
|
||||
all_passed = False
|
||||
|
||||
return all_passed
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print(__doc__)
|
||||
sys.exit(1)
|
||||
|
||||
checksum_file = sys.argv[1]
|
||||
if verify_checksums(checksum_file):
|
||||
print("\nAll checksums verified successfully!")
|
||||
sys.exit(0)
|
||||
else:
|
||||
print("\nSome checksums failed!")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,2 @@
|
||||
4b1881cb2680a1512aee9aee4029365525691f4de7dec2dd000e1facf2468f70 results.txt
|
||||
988a71fed1809c3d6837042fa5972298b8a9f7f1252351c87d5229032c5a8172 env-check.sh
|
||||
@@ -0,0 +1,3 @@
|
||||
4b1881cb2680a1512aee9aee4029365525691f4de7dec2dd000e1facf2468f70 checksums.sha256
|
||||
3b55ae2261a56b69a2b138e0ef93928314001869f2e0ed4886541463433b9eb7 checksum_verify.py
|
||||
7d554ff1409148fbcc04800f8cad54ddfdf4f1ef6ea4bb0641f407dcbf9f7f84 check_spark_profile.py
|
||||
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Check if a number is prime."""
|
||||
|
||||
def is_prime(n: int) -> bool:
|
||||
"""Return True if n is a prime number, False otherwise."""
|
||||
if n < 2:
|
||||
return False
|
||||
if n == 2:
|
||||
return True
|
||||
if n % 2 == 0:
|
||||
return False
|
||||
for i in range(3, int(n**0.5) + 1, 2):
|
||||
if n % i == 0:
|
||||
return False
|
||||
return True
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: python prime_checker.py <number>")
|
||||
sys.exit(1)
|
||||
try:
|
||||
num = int(sys.argv[1])
|
||||
result = is_prime(num)
|
||||
print(f"{num} is {'prime' if result else 'not prime'}")
|
||||
sys.exit(0 if result else 1)
|
||||
except ValueError:
|
||||
print("Please provide a valid integer")
|
||||
sys.exit(1)
|
||||
Reference in new issue
Block a user