mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
23 lines
613 B
Python
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)
|