Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter detected device type #498

Closed
giampaolo opened this issue May 23, 2014 · 7 comments
Closed

Filter detected device type #498

giampaolo opened this issue May 23, 2014 · 7 comments

Comments

@giampaolo
Copy link
Owner

From [email protected] on April 23, 2014 04:07:06

This is a feature request.
Is it possible to detect only connected usb disk drives (like pendrive) with psutils?

Original issue: http://code.google.com/p/psutil/issues/detail?id=498

@giampaolo
Copy link
Owner Author

From g.rodola on April 22, 2014 19:13:02

I think you should see what psutil.disk_partitions() ( 
https://pythonhosted.org/psutil/#psutil.disk_partitions ) returns when you have 
an USB disk connected then simply filter for "fstype".

@giampaolo
Copy link
Owner Author

From [email protected] on April 22, 2014 19:16:25

Read it. The way it is written, it seems to work under windows only.

Anyway, Will test and report back. If working, you may want to update the
doc.

@giampaolo
Copy link
Owner Author

From g.rodola on April 22, 2014 19:19:50

What do you mean? What is returned if an USB disk is connected and how should I 
update the doc?

@giampaolo
Copy link
Owner Author

From [email protected] on April 23, 2014 06:14:46

Sorry for the delay. 
Here is the simple sample code:-

import psutil
for device in psutil.disk_partitions(all=False):
  print device[0]

It producess an output like this:-
/dev/sda5
/dev/sda8
/dev/sda7
/dev/sda6
/dev/sdb1

Now, how do I detemine if "/dev/sdb1" is a USB device?

@giampaolo
Copy link
Owner Author

From g.rodola on April 23, 2014 13:07:33

Try to paste the whole namedtuple as in:

import psutil
for device in psutil.disk_partitions(all=False):
  print device

@giampaolo
Copy link
Owner Author

From [email protected] on April 23, 2014 20:24:19

Here is the nametuple you asked for:-

sdiskpart(device='/dev/sda5', mountpoint='/', fstype='ext4', 
opts='rw,relatime,data=ordered')
sdiskpart(device='/dev/sda6', mountpoint='/media/DEBIAN', fstype='ext4', 
opts='rw,relatime,data=ordered')
sdiskpart(device='/dev/sda8', mountpoint='/media/FUN', fstype='vfat', 
opts='rw,nosuid,nodev,noexec,relatime,gid=100,fmask=0002,dmask=0002,allow_utime=0020,codepage=437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro')

sdiskpart(device='/dev/sda7', mountpoint='/media/DATA', fstype='vfat', 
opts='rw,nosuid,nodev,noexec,relatime,gid=100,fmask=0002,dmask=0002,allow_utime=0020,codepage=437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro')

sdiskpart(device='/dev/sdb1', mountpoint='/run/media/sundar/SUNDAR', 
fstype='vfat', 
opts='rw,nosuid,nodev,relatime,uid=1000,gid=100,fmask=0022,dmask=0077,codepage=437,iocharset=iso8859-1,shortname=mixed,showexec,utf8,flush,errors=remount-ro')

@giampaolo
Copy link
Owner Author

AFAICT USB devices are supposed to be seen by psutil. Closing this out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant