mirror of
				https://github.com/avatao-content/baseimage-tutorial-framework
				synced 2025-11-04 05:42:54 +00:00 
			
		
		
		
	Refactor DirectoryMonitor managing code to a mixin
This commit is contained in:
		@@ -4,3 +4,4 @@
 | 
			
		||||
from .supervisor_mixin import SupervisorMixin
 | 
			
		||||
from .callback_mixin import CallbackMixin
 | 
			
		||||
from .observer_mixin import ObserverMixin
 | 
			
		||||
from .monitor_manager_mixin import MonitorManagerMixin
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										27
									
								
								lib/tfw/mixins/monitor_manager_mixin.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								lib/tfw/mixins/monitor_manager_mixin.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,27 @@
 | 
			
		||||
# Copyright (C) 2018 Avatao.com Innovative Learning Kft.
 | 
			
		||||
# All Rights Reserved. See LICENSE file for details.
 | 
			
		||||
 | 
			
		||||
from tfw.config.logs import logging
 | 
			
		||||
 | 
			
		||||
LOG = logging.getLogger(__name__)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class MonitorManagerMixin:
 | 
			
		||||
    def __init__(self, monitor_type, directory):
 | 
			
		||||
        self._monitor_type = monitor_type
 | 
			
		||||
        self._monitor = None
 | 
			
		||||
        self._monitored_directory = directory
 | 
			
		||||
        self.reload_monitor()
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def monitor(self):
 | 
			
		||||
        return self._monitor
 | 
			
		||||
 | 
			
		||||
    def reload_monitor(self):
 | 
			
		||||
        if self._monitor:
 | 
			
		||||
            try:
 | 
			
		||||
                self._monitor.stop()
 | 
			
		||||
            except KeyError:
 | 
			
		||||
                LOG.debug('Working directory was removed – ignoring...')
 | 
			
		||||
        self._monitor = self._monitor_type(self._monitored_directory)
 | 
			
		||||
        self._monitor.watch()   # This runs on a separate thread
 | 
			
		||||
		Reference in New Issue
	
	Block a user