1

I need a way to determine if a specific USB thumb drive has been inserted. For instance:

if "flash drive named "Records" is present": copy data to drive

else: "do something else"

I have all the copytree functions working just fine, I just need a way to check for the specific drive before the operation.

Thank you in advance!

Scott Sutton
  • 41
  • 1
  • 1
  • 2

3 Answers3

0

By name, assuming you are looking for label, you could have a few ways. You could call blkid to get the labels of the system. But the tool itself might be limited to superusers. The target users might need to run your script as a superuser.

Other alternative I found with a little Google search is to use DBUS in Python. You might want to look up https://askubuntu.com/questions/437031/finding-volume-label-of-a-usb-mass-storage-device-using-python page.

In short, install python-dbus package and just a few lines of Python code could list you the drive labels.

Community
  • 1
  • 1
Vasu
  • 62
  • 1
  • 7
  • Thanks for all the answers, having studied each I determined that my best approach was to use PyUSB module to iterate over my USB devices and look for the particular device that I needed before my operation. – Scott Sutton Jan 24 '15 at 17:14
0

How about the usbid package? It has the ability to find USB device IDs, so might be just what you need.

NB: I haven't used this myself; I just found this with a quick Google search and thought it might help solve your problem!

Mike P
  • 742
  • 11
  • 26
0

Your distro probably has the lsusb util installed. If so, you can have a look at this answer that demonstrated how to read and parse the output of lsusb from a python script.

Community
  • 1
  • 1
Dave
  • 1,784
  • 2
  • 23
  • 35