google-code-export / psutil

Automatically exported from code.google.com/p/psutil
Other
0 stars 0 forks source link

Filter detected device type #498

Open GoogleCodeExporter opened 9 years ago

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

Original issue reported on code.google.com by feedback...@gmail.com on 23 Apr 2014 at 2:07

GoogleCodeExporter commented 9 years ago
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".

Original comment by g.rodola on 23 Apr 2014 at 2:13

GoogleCodeExporter commented 9 years ago
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.

Original comment by feedback...@gmail.com on 23 Apr 2014 at 2:16

GoogleCodeExporter commented 9 years ago
What do you mean? What is returned if an USB disk is connected and how should I 
update the doc?

Original comment by g.rodola on 23 Apr 2014 at 2:19

GoogleCodeExporter commented 9 years ago
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?

Original comment by feedback...@gmail.com on 23 Apr 2014 at 1:14

GoogleCodeExporter commented 9 years ago
Try to paste the whole namedtuple as in:

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

Original comment by g.rodola on 23 Apr 2014 at 8:07

GoogleCodeExporter commented 9 years ago
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=4
37,iocharset=iso8859-1,shortname=mixed,showexec,utf8,flush,errors=remount-ro')

Original comment by feedback...@gmail.com on 24 Apr 2014 at 3:24

GoogleCodeExporter commented 9 years ago
psutil has been migrated from Google Code to Github (see: 
http://grodola.blogspot.com/2014/05/goodbye-google-code-im-moving-to-github.html
).
Please do NOT reply here but use this instead:
https://github.com/giampaolo/psutil/issues/498

Original comment by g.rodola on 26 May 2014 at 3:05