mirror of
				https://github.com/zoriya/Kyoo.git
				synced 2025-11-04 03:27:14 -05:00 
			
		
		
		
	
		
			
				
	
	
		
			23 lines
		
	
	
		
			615 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			23 lines
		
	
	
		
			615 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)
 |