47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Generate environment status report as JSON."""
|
|
import json
|
|
import os
|
|
import shutil
|
|
import sys
|
|
from datetime import datetime, timezone
|
|
|
|
def get_env_status():
|
|
"""Return environment status as dict."""
|
|
cwd = os.getcwd()
|
|
user = os.environ.get('USER', 'unknown')
|
|
|
|
# Get disk usage for root filesystem
|
|
total, used, free = shutil.disk_usage('/')
|
|
|
|
# Count files in scratch directory for hermes
|
|
scratch = os.environ.get('TMPDIR', '/tmp')
|
|
file_count = 0
|
|
for root, dirs, files in os.walk(scratch):
|
|
file_count += len(files)
|
|
if file_count > 100: # Limit for speed
|
|
break
|
|
|
|
status = {
|
|
'timestamp': datetime.now(timezone.utc).isoformat(),
|
|
'working_directory': cwd,
|
|
'user': user,
|
|
'disk_usage': {
|
|
'total_gb': round(total / (1024**3), 2),
|
|
'used_gb': round(used / (1024**3), 2),
|
|
'free_gb': round(free / (1024**3), 2),
|
|
'percent_used': round((used / total) * 100, 1)
|
|
},
|
|
'scratch_files': file_count,
|
|
'python_version': sys.version.split()[0],
|
|
'platform': os.uname().sysname if hasattr(os, 'uname') else 'unknown'
|
|
}
|
|
return status
|
|
|
|
if __name__ == '__main__':
|
|
status = get_env_status()
|
|
output_path = '/root/.hermes/wizard-outputs/spark/env_status.json'
|
|
with open(output_path, 'w') as f:
|
|
json.dump(status, f, indent=2)
|
|
print(f"Status written to {output_path}")
|
|
print(json.dumps(status, indent=2)) |