-
Notifications
You must be signed in to change notification settings - Fork 0
/
usb_server.py
27 lines (21 loc) · 1012 Bytes
/
usb_server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import dbus, gobject
from dbus.mainloop.glib import DBusGMainLoop
from pprint import pprint
DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
def device_added_callback(device):
print('Added:')
dev_obj = bus.get_object('org.freedesktop.UDisks', device)
dev_props = dbus.Interface(dev_obj, dbus.PROPERTIES_IFACE)
pprint (dev_props.Get('org.freedesktop.UDisks.Device', 'DeviceMountPaths'))
def device_changed_callback(device):
print('Changed:')
dev_obj = bus.get_object('org.freedesktop.UDisks', device)
dev_props = dbus.Interface(dev_obj, dbus.PROPERTIES_IFACE)
pprint (dev_props.Get('org.freedesktop.UDisks.Device', 'DeviceMountPaths'))
proxy = bus.get_object('org.freedesktop.UDisks', '/org/freedesktop/UDisks')
iface = dbus.Interface(proxy, 'org.freedesktop.UDisks')
iface.connect_to_signal('DeviceAdded', device_added_callback)
iface.connect_to_signal('DeviceChanged', device_changed_callback)
mainloop = gobject.MainLoop()
mainloop.run()