本文整理汇总了Python中pyudev.Monitor.from_netlink方法的典型用法代码示例。如果您正苦于以下问题:Python Monitor.from_netlink方法的具体用法?Python Monitor.from_netlink怎么用?Python Monitor.from_netlink使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyudev.Monitor
的用法示例。
在下文中一共展示了Monitor.from_netlink方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_from_netlink_source_udev
# 需要导入模块: from pyudev import Monitor [as 别名]
# 或者: from pyudev.Monitor import from_netlink [as 别名]
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
# 需要导入模块: from pyudev import Monitor [as 别名]
# 或者: from pyudev.Monitor import from_netlink [as 别名]
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_netlink_source_udev_mock
# 需要导入模块: from pyudev import Monitor [as 别名]
# 或者: from pyudev.Monitor import from_netlink [as 别名]
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')
示例4: disk_src
# 需要导入模块: from pyudev import Monitor [as 别名]
# 或者: from pyudev.Monitor import from_netlink [as 别名]
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()
示例5: __init__
# 需要导入模块: from pyudev import Monitor [as 别名]
# 或者: from pyudev.Monitor import from_netlink [as 别名]
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
示例6: main2
# 需要导入模块: from pyudev import Monitor [as 别名]
# 或者: from pyudev.Monitor import from_netlink [as 别名]
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()
示例7: __init__
# 需要导入模块: from pyudev import Monitor [as 别名]
# 或者: from pyudev.Monitor import from_netlink [as 别名]
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)
示例8: initialize
# 需要导入模块: from pyudev import Monitor [as 别名]
# 或者: from pyudev.Monitor import from_netlink [as 别名]
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()
示例9: monitor_background
# 需要导入模块: from pyudev import Monitor [as 别名]
# 或者: from pyudev.Monitor import from_netlink [as 别名]
def monitor_background():
c = Context()
monitor = Monitor.from_netlink(c)
monitor.filter_by("block", "disk")
obs = MonitorObserver(monitor, device_event)
obs.start()
示例10: start_udev_monitoring
# 需要导入模块: from pyudev import Monitor [as 别名]
# 或者: from pyudev.Monitor import from_netlink [as 别名]
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()
示例11: watch
# 需要导入模块: from pyudev import Monitor [as 别名]
# 或者: from pyudev.Monitor import from_netlink [as 别名]
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()
示例12: set_monitor_func
# 需要导入模块: from pyudev import Monitor [as 别名]
# 或者: from pyudev.Monitor import from_netlink [as 别名]
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()
示例13: monitor
# 需要导入模块: from pyudev import Monitor [as 别名]
# 或者: from pyudev.Monitor import from_netlink [as 别名]
def monitor():
context = Context()
monitor = Monitor.from_netlink(context)
monitor.filter_by(subsystem='usb')
observer = MonitorObserver(monitor)
observer.connect('device-removed', remove_event)
observer.connect('device-added', add_event)
monitor.start()
glib.MainLoop().run()
示例14: _assert_from_netlink_called
# 需要导入模块: from pyudev import Monitor [as 别名]
# 或者: from pyudev.Monitor import from_netlink [as 别名]
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: _listenOnUsb
# 需要导入模块: from pyudev import Monitor [as 别名]
# 或者: from pyudev.Monitor import from_netlink [as 别名]
def _listenOnUsb(self):
context = Context()
monitor = Monitor.from_netlink(context)
monitor.filter_by(subsystem="usb")
observer = MonitorObserver(monitor)
observer.connect("device-event", self._deviceEvent)
monitor.start()
glib.MainLoop().run()