Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # author: s4bba7
- # ver: 1.0
- # Start this script in a console and unplug USB device. It should print one or more device's IDs - pick one.
- # Package pyudev have to be installed.
- import functools
- import os.path
- import pyudev
- import subprocess
- def main():
- BASE_PATH = os.path.abspath(os.path.dirname(__file__))
- path = functools.partial(os.path.join, BASE_PATH)
- call = lambda x, *args: subprocess.call([path(x)] + list(args))
- context = pyudev.Context()
- monitor = pyudev.Monitor.from_netlink(context)
- monitor.filter_by(subsystem='usb')
- monitor.start()
- for device in iter(monitor.poll, None):
- print(device)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment