Files
conjurer/conjurer_musician/scan_shares.py
T
gitea 2aeb3d286f Tag: 1.26
Intermediate commits (oldest → newest):
- Generated scripts
- new function
- more work needed
- Search client
- serverside
- added server side search
- M
- fix
- fix deploy
- zmiana nazwy
- Params of radio
- Watcher
2025-10-30 16:59:21 +01:00

45 lines
1.2 KiB
Python
Executable File

#!/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()