def test___init__(self):
     monitor = Monitor('/tmp', ['create'], lambda x: 1, debug=1)
     assert isinstance(monitor, Monitor)
 def test_process_IN_MODIFY(self):
     f = open('/tmp/test', 'w')
     monitor = Monitor('/tmp/test', ['modify'], lambda x: 1, debug=1)
     f.write('kjl')
     f.close()
 def test_set_action(self):
     action = lambda x: 1
     monitor = Monitor('/tmp/test', ['modify'], action, debug=1)
     assert monitor.handler.action == action
 def test_process_IN_CREATE(self):
     monitor = Monitor('/tmp', ['create'], lambda x: 1, debug=1)
     f = open('/tmp/test', 'w')
     f.close()
 def test_process_IN_DELETE(self):
     f = open('/tmp/test', 'w')
     f.close()
     monitor = Monitor('/tmp/test', ['delete'], lambda x: 1, debug=1)
     os.unlink('/tmp/test')
 def test_process_IN_CLOSE_WRITE(self):
     f = open('/tmp/test', 'w')
     monitor = Monitor('/tmp/test', ['close_write'], lambda x: 1, debug=1)
     f.write('kjl')
     f.close()
 def test_process_IN_CLOSE_NOWRITE(self):
     f = open('/tmp/test', 'r')
     monitor = Monitor('/tmp/test', ['close_nowrite'], lambda x: 1, debug=1)
     f.close()
 def test_process_IN_ACCESS(self):
     f = open('/tmp/test', 'w')
     monitor = Monitor('/tmp/test', ['access'], lambda x: 1, debug=1)
     f.write('kjl')
     f.close()
 def test__get_mask(self):
     monitor = Monitor('/tmp', ['create'], lambda x: 1, debug=1)
     assert monitor.mask == pyinotify.IN_CREATE
     monitor = Monitor('/tmp', ['create', 'delete'], lambda x: 1, debug=1)
     assert monitor.mask == pyinotify.IN_CREATE | pyinotify.IN_DELETE
Пример #10
0
from __future__ import print_function

# ===============================================================================
# Examples for the filemonitor module
# ===============================================================================

import numpy as np
from liveplots.filemonitor import Monitor
from liveplots.xmlrpcserver import PlotServer
import six.moves.xmlrpc_client
import time


pserver = PlotServer()


def action(fpath):
    print("action triggered", fpath)
    np.load(fpath)
    pserver.lines(data.tolist(), [], ["data"], "")


monitor = Monitor("/tmp", ["close_write"], action, debug=1)


data = np.random.normal(0, 1, 1000)
np.save("/tmp/data.npy", data)
# Wait a little bit to allow for the event to be processed
time.sleep(1)
monitor.stop()