如何监视python中的连接、usb海量存储设备连接?我找到了一些选择,但在这两种选择中,我都遇到了阻碍。
发布于 2014-03-12 02:24:21
看看gudev
有一个简单的例子
http://ubuntuforums.org/archive/index.php/t-1695571.html
基本上,它看起来是:
#!/usr/bin/env python
import glib
import gudev
import pynotify
import sys
def callback(client, action, device, user_data):
device_vendor = device.get_property("ID_VENDOR_ENC")
device_model = device.get_property("ID_MODEL_ENC")
if action == "add":
n = pynotify.Notification("USB Device Added", "%s %s is now connected to your system" % (device_vendor,device_model))
n.show()
elif action == "remove":
n = pynotify.Notification("USB Device Removed", "%s %s has been disconnected from your system" %
(device_vendor, device_model))
n.show()
if not pynotify.init("USB Device Notifier"):
sys.exit("Couldn't connect to the notification daemon!")
client = gudev.Client(["usb/usb_device"])
client.connect("uevent", callback, None)
loop = glib.MainLoop()
loop.run()https://stackoverflow.com/questions/22340538
复制相似问题