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


Python pyudev.Monitor类代码示例

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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