mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-14 21:38:38 +00:00
Generated scripts
This commit is contained in:
Executable
+44
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
import json
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
# Configuration
|
||||
SCAN_PATH = '/mnt/shares'
|
||||
OUTPUT_FILE = '/var/log/share_scan.json'
|
||||
|
||||
def scan_directory(root):
|
||||
"""Recursively walk `root` and collect metadata."""
|
||||
entries = []
|
||||
for dirpath, dirs, files in os.walk(root):
|
||||
for name in dirs + files:
|
||||
full = os.path.join(dirpath, name)
|
||||
try:
|
||||
stat = os.stat(full)
|
||||
entries.append({
|
||||
'path': full,
|
||||
'is_dir': os.path.isdir(full),
|
||||
'size_bytes': stat.st_size,
|
||||
'mtime': time.strftime('%Y-%m-%dT%H:%M:%S%z',
|
||||
time.localtime(stat.st_mtime)),
|
||||
})
|
||||
except Exception as e:
|
||||
# skip items we can't stat
|
||||
continue
|
||||
return entries
|
||||
|
||||
def main():
|
||||
data = {
|
||||
'scanned_at': time.strftime('%Y-%m-%dT%H:%M:%S%z', time.localtime()),
|
||||
'root': SCAN_PATH,
|
||||
'entries': scan_directory(SCAN_PATH),
|
||||
}
|
||||
# Write atomically
|
||||
temp = OUTPUT_FILE + '.tmp'
|
||||
with open(temp, 'w') as f:
|
||||
json.dump(data, f, indent=2)
|
||||
os.replace(temp, OUTPUT_FILE)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user