pyudev

Notify QML for 'usb device inserted' events using PyQt5 and pyudev

有些话、适合烂在心里 提交于 2021-02-10 22:24:32
问题 I have a GUI application (made with PyQt5 and QML) and would like to get notify when a usb device is plugged or unplugged from the computer. After some investigation, I have found that pyudev could be the library to use. But I have trouble using it with PyQt5 and QML. I have succeed to use the pyudev example for MonitorObservor, and there are other example provided in the documentation, here with PySide and here with Glib. I have also found an example using PyQt5 and widgets application here.

Retrieve USB information using pyudev with device name

北慕城南 提交于 2019-12-30 05:22:05
问题 I retrieve the first device information from the block subsystem. For example that a USB stick was assigned to /dev/sdb. This is all the infos I can retrieve via the block subsystem: [(u'DEVLINKS', u'/dev/disk/by-id/usb-Generic_Flash_Disk_63F2B6EC-0:0 /dev/disk/by-label/Fedora-Live-Desktop-x86_64-20-1 /dev/disk/by-path/pci-0000:00:1d.0-usb-0:1.2:1.0-scsi-0:0:0:0 /dev/disk/by-uu id/2013-12-12-00-56-55-00'), (u'DEVNAME', u'/dev/sdb'), (u'DEVPATH', u'/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1

Using pyudev.pyqt5 within PyQt5's event loop

一曲冷凌霜 提交于 2019-12-23 21:49:40
问题 I wanted to write a small application that will display usb device's name in a small text browser, when it has been inserted. I am using pyudev to do that. Instead of using pyudev's own event loop, i found out that we can integrate pyudev into qt's event loop, by using MonitorObserver. I have been trying to do that, but the results are unfruitful. Here is the code that i have tried so far. Please tell me if i am making a mistake. Imports from PyQt5.QtCore import pyqtSignal,pyqtSlot,QObject

Obtain device path from pyudev with python

℡╲_俬逩灬. 提交于 2019-12-17 17:12:04
问题 Using pydev with python-2.7 , I wish obtain the device path of connected devices. Now I use this code: from pyudev.glib import GUDevMonitorObserver as MonitorObserver def device_event(observer, action, device): print 'event {0} on device {1}'.format(action, device) but device return a string like this: (u'/sys/devices/pci0000:00/pci0000:00:01.0/0000.000/usb1/1-2') How can I obtain a path like /dev/ttyUSB1 ? 回答1: Device(u'/sys/devices/pci0000:00/pci0000:00:01.0/0000.000/usb1/1-2') is a USB

How to monitor usb devices insertion?

浪子不回头ぞ 提交于 2019-12-11 07:30:03
问题 I am trying to monitor for USB devices when they get plugged in. A couple of test scripts fail that I am pretty sure should of worked. import pyudev context = pyudev.Context() monitor = pyudev.Monitor.from_netlink(context) monitor.filter_by(subsystem='usb') for device in iter(monitor.poll, None): if device.action == 'add': print('{} connected'.format(device)) ^^Does nothing. No error, no output. I try import dbus bus = dbus.SystemBus() obj = bus.get_object('org.freedesktop.NetworkManager', '

How to detect a new usb device is connected on python

左心房为你撑大大i 提交于 2019-12-02 18:24:26
问题 I wanna make something which will run on the background and only after the computer detect new device is connected the rest of the code will run , is there any elegant way to do such a thing? 回答1: this is operating system dependent in linux you can use pyudev for this : Almost the complete libudev functionality is exposed. You can: Enumerate devices, filtered by specific criteria (pyudev.Context) Query device information, properties and attributes, Monitor devices , both synchronously and

Finding only disk drives using pyudev

微笑、不失礼 提交于 2019-12-02 01:32:04
问题 I'm looking to enumerate all hard disks on a computer using udev and specifically pyudev to enumerate everything: import pyudev context = pyudev.Context() for device in context.list_devices(subsystem='block', DEVTYPE='disk'): print "{}, ({})".format(device.device_node, device.device_type) This prints out the following: /dev/sdb (disk) /dev/sdc (disk) /dev/sda (disk) /dev/sr0 (disk) /dev/loop0 (disk) /dev/loop1 (disk) /dev/loop2 (disk) /dev/loop3 (disk) /dev/loop4 (disk) /dev/loop5 (disk) /dev

Retrieve USB information using pyudev with device name

半城伤御伤魂 提交于 2019-11-30 16:21:03
I retrieve the first device information from the block subsystem. For example that a USB stick was assigned to /dev/sdb. This is all the infos I can retrieve via the block subsystem: [(u'DEVLINKS', u'/dev/disk/by-id/usb-Generic_Flash_Disk_63F2B6EC-0:0 /dev/disk/by-label/Fedora-Live-Desktop-x86_64-20-1 /dev/disk/by-path/pci-0000:00:1d.0-usb-0:1.2:1.0-scsi-0:0:0:0 /dev/disk/by-uu id/2013-12-12-00-56-55-00'), (u'DEVNAME', u'/dev/sdb'), (u'DEVPATH', u'/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.2/2-1.2:1.0/host74/target74:0:0/74:0:0:0/block/sdb'), (u'DEVTYPE', u'disk'), (u'ID_BUS', u'usb'), (u

Pyudev - calls function twice

最后都变了- 提交于 2019-11-28 14:41:10
I have a problem with pyudev library usage. I want to have a program which detects USB plug in and prints something to console. Here's the code i have: import glib import os import sys from pyudev import Context, Monitor from pyudev.glib import GUDevMonitorObserver as MonitorObserver def device_event(observer, device): print 'yep' context = Context() monitor = Monitor.from_netlink(context) monitor.filter_by(subsystem='usb') observer = MonitorObserver(monitor) observer.connect('device-added', device_event) monitor.start() glib.MainLoop().run() The problem is when i run the script it seems that

Pyudev - calls function twice

泪湿孤枕 提交于 2019-11-27 08:44:38
问题 I have a problem with pyudev library usage. I want to have a program which detects USB plug in and prints something to console. Here's the code i have: import glib import os import sys from pyudev import Context, Monitor from pyudev.glib import GUDevMonitorObserver as MonitorObserver def device_event(observer, device): print 'yep' context = Context() monitor = Monitor.from_netlink(context) monitor.filter_by(subsystem='usb') observer = MonitorObserver(monitor) observer.connect('device-added',