Kyoo/scanner/scanner/monitor.py
2024-01-31 02:41:21 +01:00

23 lines
613 B
Python

import logging
from watchfiles import awatch, Change
from .utils import ProviderError
from .scanner import Scanner
async def monitor(path: str, scanner: Scanner):
async for changes in awatch(path):
for event, file in changes:
try:
if event == Change.added:
await scanner.identify(file)
elif event == Change.deleted:
await scanner.delete(file)
elif event == Change.modified:
pass
else:
print(f"Change {event} occured for file {file}")
except ProviderError as e:
logging.error(str(e))
except Exception as e:
logging.exception("Unhandled error", exc_info=e)