2018-04-14 20:57:37 +00:00
|
|
|
|
# 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:
|
2018-05-24 14:19:04 +00:00
|
|
|
|
def __init__(self, monitor_type, directories):
|
2018-04-14 20:57:37 +00:00
|
|
|
|
self._monitor_type = monitor_type
|
|
|
|
|
self._monitor = None
|
2018-05-24 14:19:04 +00:00
|
|
|
|
self._monitored_directories = directories
|
2018-04-14 20:57:37 +00:00
|
|
|
|
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...')
|
2018-05-24 14:19:04 +00:00
|
|
|
|
self._monitor = self._monitor_type(self._monitored_directories)
|
2018-04-14 20:57:37 +00:00
|
|
|
|
self._monitor.watch() # This runs on a separate thread
|