File: test.py

package info (click to toggle)
python-gudev 147.2-1%2Bsqueeze1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 116 kB
  • ctags: 5
  • sloc: sh: 137; makefile: 53; python: 32; ansic: 18
file content (42 lines) | stat: -rw-r--r-- 1,387 bytes parent folder | download | duplicates (2)
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Port of
# http://git.kernel.org/?p=linux/hotplug/udev.git;a=blob;f=extras/gudev/gjs-example.js

import sys
sys.path.insert(0, ".libs")

import gudev
import glib

print "GUDEV VERSION: %s" % gudev.__version__

def print_device(device):
    print "subsystem", device.get_subsystem()
    print "devtype", device.get_devtype()
    print "name", device.get_name()
    print "number", device.get_number()
    print "sysfs_path:", device.get_sysfs_path()
    print "driver:", device.get_driver()
    print "action:", device.get_action()
    print "seqnum:", device.get_seqnum()
    print "device type:", device.get_device_type()
    print "device number:", device.get_device_number()
    print "device file:", device.get_device_file()
    print "device file symlinks:", ", ".join(device.get_device_file_symlinks())
    print "device keys:", ", ".join(device.get_property_keys())
    for device_key in device.get_property_keys():
        print "   device property %s: %s"  % (device_key, device.get_property(device_key))

def on_uevent(client, action, device):
    print "UEVENT"
    print_device(device)
    print "------", device.get_property("ID_MEDIA_PLAYER")

client = gudev.Client(["block","usb"])
client.connect("uevent", on_uevent)

devices = client.query_by_subsystem("usb")
for device in devices:
    print_device(device)

print "\n --- WAITING FOR EVENTS ---"
glib.MainLoop().run()