当前位置: 首页>>代码示例>>Python>>正文


Python Monitor.from_netlink方法代码示例

本文整理汇总了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
开发者ID:dwlehman,项目名称:pyudev,代码行数:9,代码来源:test_monitor.py

示例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
开发者ID:csleex,项目名称:pyudev,代码行数:13,代码来源:test_monitor.py

示例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')
开发者ID:dwlehman,项目名称:pyudev,代码行数:17,代码来源:test_monitor.py

示例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()
开发者ID:ellak-monades-aristeias,项目名称:dlimen,代码行数:29,代码来源:storagepool.py

示例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
开发者ID:matthewelse,项目名称:lmtools,代码行数:9,代码来源:notify.py

示例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()
开发者ID:scipioa,项目名称:umenprosthesis,代码行数:9,代码来源:EventManager.py

示例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)
开发者ID:SpotlightKid,项目名称:jack-select,代码行数:9,代码来源:devmonitor.py

示例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()
开发者ID:SymbIoT-Systems,项目名称:RPi_Edgerouter,代码行数:9,代码来源:USBAutoDetect.py

示例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()
开发者ID:timothyb89,项目名称:offline_proxy,代码行数:10,代码来源:usb_wrapper.py

示例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()
开发者ID:KpaBap,项目名称:strava-uploader,代码行数:10,代码来源:linux-usb-uploader.py

示例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()
开发者ID:rrobe53,项目名称:CameraSync,代码行数:10,代码来源:camera.py

示例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()
开发者ID:AlexeiBuzuma,项目名称:IPD,代码行数:10,代码来源:usb.py

示例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()
开发者ID:cryptax,项目名称:fittools,代码行数:11,代码来源:donglelock.py

示例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
开发者ID:lanstat,项目名称:pyudev,代码行数:11,代码来源:test_monitor.py

示例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()
开发者ID:claudemuller,项目名称:pydle,代码行数:12,代码来源:pydle.py


注:本文中的pyudev.Monitor.from_netlink方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。