You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
983 B
31 lines
983 B
import asyncio
|
|
from subprocess import PIPE
|
|
import locale
|
|
|
|
from zasd.config import config
|
|
from zasd.asyncio import LineBufferedProtocol
|
|
from zasd.log import log
|
|
|
|
class PathWatcher:
|
|
def __init__(self, name, path, callback):
|
|
self._name = name
|
|
self._path = path
|
|
|
|
# Watch path
|
|
asyncio.get_event_loop().subprocess_exec(
|
|
PathWatcherProtocol(name, callback), config['fswatch_path'], '-o',
|
|
path, stdout=PIPE)
|
|
|
|
class PathWatcherProtocol(LineBufferedProtocol):
|
|
def __init__(self, name, callback):
|
|
LineBufferedProtocol.__init__(self, locale.getpreferredencoding())
|
|
self._name = name
|
|
self._callback = callback
|
|
|
|
def pipe_line_received(self, line):
|
|
# Ignore empty lines and NOOPs
|
|
if len(line) == 0 or int(line) == 0:
|
|
return
|
|
|
|
log.info('Detected change on filesystem %s', self._name)
|
|
self._callback(self._name)
|
|
|