本文整理汇总了Python中pyudev.Monitor类的典型用法代码示例。如果您正苦于以下问题:Python Monitor类的具体用法?Python Monitor怎么用?Python Monitor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Monitor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_from_netlink_source_udev
def test_from_netlink_source_udev(self, context):
monitor = Monitor.from_netlink(context)
assert monitor._as_parameter_
assert not monitor.started
monitor = Monitor.from_netlink(context, source='udev')
assert monitor._as_parameter_
assert not monitor.started
示例2: test_from_netlink_source_udev_mock
def test_from_netlink_source_udev_mock(self, context):
calls = {'udev_monitor_new_from_netlink':
[(context, b'udev'), (context, b'udev')]}
with pytest.calls_to_libudev(calls):
libudev.udev_monitor_new_from_netlink.return_value = sentinel.monitor
monitor = Monitor.from_netlink(context)
assert monitor._as_parameter_ is sentinel.monitor
assert not monitor.started
monitor = Monitor.from_netlink(context, 'udev')
assert monitor._as_parameter_ is sentinel.monitor
assert not monitor.started
示例3: test_from_socket_mock
def test_from_socket_mock(self, context, socket_path):
socket_path = str(socket_path)
new_from_socket = 'udev_monitor_new_from_socket'
with pytest.patch_libudev(new_from_socket) as new_from_socket:
new_from_socket.return_value = mock.sentinel.pointer
monitor = Monitor.from_socket(context, socket_path)
new_from_socket.assert_called_with(
context, socket_path.encode(sys.getfilesystemencoding()))
assert monitor._as_parameter_ is mock.sentinel.pointer
Monitor.from_socket(context, 'foobar')
new_from_socket.assert_called_with(context, b'foobar')
assert isinstance(new_from_socket.call_args[0][1], bytes)
示例4: test_from_netlink_source_udev_mock
def test_from_netlink_source_udev_mock(self, context):
funcname = 'udev_monitor_new_from_netlink'
spec = lambda c, s: None
with mock.patch.object(context._libudev, funcname,
autospec=spec) as func:
func.return_value = mock.sentinel.monitor
monitor = Monitor.from_netlink(context)
assert monitor._as_parameter_ is mock.sentinel.monitor
assert not monitor.started
func.assert_called_once_with(context, b'udev')
func.reset_mock()
monitor = Monitor.from_netlink(context, 'udev')
assert monitor._as_parameter_ is mock.sentinel.monitor
assert not monitor.started
func.assert_called_once_with(context, b'udev')
示例5: disk_src
def disk_src(self):
try:
from pyudev.glib import MonitorObserver
def device_event(observer, device):
print 'event {0} on device {1}'.format(device.action, device)
if device.action == "add":
manager.disk_mnt(context)
elif device.action == "remove":
manager.disk_umnt(device)
except:
from pyudev.glib import GUDevMonitorObserver as MonitorObserver
def device_event(observer, action, device):
print 'event {0} on device {1}'.format(action, device)
if action == "add":
manager.disk_mnt(context)
elif action == "remove":
manager.disk_umnt(device)
context = Context()
manager = Storage(self.cfg, self.log)
monitor = Monitor.from_netlink(context)
monitor.filter_by(subsystem='block', device_type='partition')
observer = MonitorObserver(monitor)
observer.connect('device-event', device_event)
monitor.start()
glib.MainLoop().run()
示例6: __init__
def __init__(self):
self.context = Context()
self.monitor = Monitor.from_netlink(self.context)
self.monitor.filter_by(subsystem='usb')
self.observer = MonitorObserver(
self.monitor, callback=self.event_handler, name="blahblah")
self.observer.daemon = True
示例7: main2
def main2():
context = Context()
monitor = Monitor.from_netlink(context)
monitor.filter_by(subsystem='input')
observer = MonitorObserver(monitor)
observer.connect('device-event', device_event)
monitor.start()
示例8: __init__
def __init__(self, callback):
# set up udev device monitor
context = Context()
self._monitor = Monitor.from_netlink(context)
self._monitor.filter_by(subsystem='sound')
self._observer = MonitorObserver(self._monitor)
self._observer.connect('device-event', callback)
示例9: initialize
def initialize():
context = Context()
monitor = Monitor.from_netlink(context)
monitor.filter_by(subsystem='tty')
observer = MonitorObserver(monitor, callback=print_device_event, name = 'monitor-observer')
observer.daemon
observer.start()
示例10: monitor_background
def monitor_background():
c = Context()
monitor = Monitor.from_netlink(c)
monitor.filter_by("block", "disk")
obs = MonitorObserver(monitor, device_event)
obs.start()
示例11: start_udev_monitoring
def start_udev_monitoring():
#Setting up Linux UDEV monitoring in a separate thread
context = Context()
monitor = Monitor.from_netlink(context)
monitor.filter_by(subsystem='block')
observer = MonitorObserver(monitor, callback=find_garmin, name='monitor-observer')
observer.daemon = True
observer.start()
示例12: watch
def watch(self, filtername, callback):
context = Context()
monitor = Monitor.from_netlink(context)
monitor.filter_by(filtername)
observer = MonitorObserver(monitor, callback=callback, name="monitor-observer")
observer.start()
示例13: set_monitor_func
def set_monitor_func(func):
global HANDLER
HANDLER = func
udev_context = Context()
monitor = Monitor.from_netlink(udev_context)
monitor.filter_by('block')
observer = MonitorObserver(monitor, log_event)
observer.start()
示例14: _assert_from_netlink_called
def _assert_from_netlink_called(context, *args):
new_from_netlink = 'udev_monitor_new_from_netlink'
with pytest.patch_libudev(new_from_netlink) as new_from_netlink:
source = args[0].encode('ascii') if args else b'udev'
new_from_netlink.return_value = mock.sentinel.pointer
monitor = Monitor.from_netlink(context, *args)
new_from_netlink.assert_called_with(context, source)
assert isinstance(new_from_netlink.call_args[0][1], bytes)
assert monitor._as_parameter_ is mock.sentinel.pointer
示例15: test_enable_receiving_bound_socket
def test_enable_receiving_bound_socket(self, context, socket_path):
sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
# cause an error by binding the socket, thus testing error handling in
# this method
sock.bind(str(socket_path))
monitor = Monitor.from_socket(context, str(socket_path))
with pytest.raises(EnvironmentError) as exc_info:
monitor.enable_receiving()
pytest.assert_env_error(exc_info.value, errno.EADDRINUSE, str(socket_path))