2018-04-14 20:57:37 +00:00
|
|
|
|
# Copyright (C) 2018 Avatao.com Innovative Learning Kft.
|
|
|
|
|
# All Rights Reserved. See LICENSE file for details.
|
|
|
|
|
|
2019-06-10 13:32:45 +00:00
|
|
|
|
import logging
|
2018-04-14 20:57:37 +00:00
|
|
|
|
|
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MonitorManagerMixin:
|
2018-05-30 11:06:09 +00:00
|
|
|
|
def __init__(self, monitor_type, *monitor_args):
|
2018-04-14 20:57:37 +00:00
|
|
|
|
self._monitor_type = monitor_type
|
|
|
|
|
self._monitor = None
|
2018-05-30 13:19:59 +00:00
|
|
|
|
self.monitor_args = monitor_args
|
2018-04-14 20:57:37 +00:00
|
|
|
|
self.reload_monitor()
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def monitor(self):
|
|
|
|
|
return self._monitor
|
|
|
|
|
|
2018-05-30 13:19:59 +00:00
|
|
|
|
def set_monitor_args(self, *monitor_args):
|
|
|
|
|
self.monitor_args = monitor_args
|
|
|
|
|
|
2018-04-14 20:57:37 +00:00
|
|
|
|
def reload_monitor(self):
|
|
|
|
|
if self._monitor:
|
|
|
|
|
try:
|
|
|
|
|
self._monitor.stop()
|
|
|
|
|
except KeyError:
|
|
|
|
|
LOG.debug('Working directory was removed – ignoring...')
|
2018-05-30 13:19:59 +00:00
|
|
|
|
self._monitor = self._monitor_type(*self.monitor_args)
|
2018-04-14 20:57:37 +00:00
|
|
|
|
self._monitor.watch() # This runs on a separate thread
|