首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用python检测USB海量存储设备连接

使用python检测USB海量存储设备连接
EN

Stack Overflow用户
提问于 2014-03-12 02:02:46
回答 1查看 1.8K关注 0票数 0

如何监视python中的连接、usb海量存储设备连接?我找到了一些选择,但在这两种选择中,我都遇到了阻碍。

  • 首先是udev (pyudev),它有一个很好的系统来监视设备连接。不幸的是,无法获得过滤器,因为我不知道哪个子系统,DEVTYPE等必须指定。

  • 第二,dbus。但HAL似乎不受欢迎。在.service文件和其他方面也遇到了一些问题。Question在这里。我觉得这是因为HAL是不推荐的,但如果它是其他东西,有工作,请告诉我! 已经横扫了万维网,还没有找到解决上述障碍的办法。请帮帮我!
EN

回答 1

Stack Overflow用户

发布于 2014-03-12 02:24:21

看看gudev

有一个简单的例子

http://ubuntuforums.org/archive/index.php/t-1695571.html

基本上,它看起来是:

代码语言:javascript
复制
#!/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()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22340538

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档