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

add linux disk rotational info #2035

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion psutil/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class BatteryTime(enum.IntEnum):
'read_time', 'write_time'])
# psutil.disk_partitions()
sdiskpart = namedtuple('sdiskpart', ['device', 'mountpoint', 'fstype', 'opts',
'maxfile', 'maxpath'])
'maxfile', 'maxpath', 'rotational'])
# psutil.net_io_counters()
snetio = namedtuple('snetio', ['bytes_sent', 'bytes_recv',
'packets_sent', 'packets_recv',
Expand Down
6 changes: 5 additions & 1 deletion psutil/_psaix.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,12 @@ def disk_partitions(all=False):
if not disk_usage(mountpoint).total:
continue
maxfile = maxpath = None # set later

# Not yet implemented
rotational = None

ntuple = _common.sdiskpart(device, mountpoint, fstype, opts,
maxfile, maxpath)
maxfile, maxpath, rotational)
retlist.append(ntuple)
return retlist

Expand Down
6 changes: 5 additions & 1 deletion psutil/_psbsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,12 @@ def disk_partitions(all=False):
for partition in partitions:
device, mountpoint, fstype, opts = partition
maxfile = maxpath = None # set later

# Not yet implemented
rotational = None

ntuple = _common.sdiskpart(device, mountpoint, fstype, opts,
maxfile, maxpath)
maxfile, maxpath, rotational)
retlist.append(ntuple)
return retlist

Expand Down
9 changes: 8 additions & 1 deletion psutil/_pslinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -1299,8 +1299,15 @@ def disk_partitions(all=False):
if device == '' or fstype not in fstypes:
continue
maxfile = maxpath = None # set later

rotational = None
try:
rotational = int(open(f'/sys/class/block/{device[device.rfind("/")+1:]}/queue/rotational').read())
except (FileNotFoundError, PermissionError):
pass

ntuple = _common.sdiskpart(device, mountpoint, fstype, opts,
maxfile, maxpath)
maxfile, maxpath, rotational)
retlist.append(ntuple)

return retlist
Expand Down
6 changes: 5 additions & 1 deletion psutil/_psosx.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,12 @@ def disk_partitions(all=False):
if not os.path.isabs(device) or not os.path.exists(device):
continue
maxfile = maxpath = None # set later

# Not yet implemented
rotational = None

ntuple = _common.sdiskpart(device, mountpoint, fstype, opts,
maxfile, maxpath)
maxfile, maxpath, rotational)
retlist.append(ntuple)
return retlist

Expand Down
6 changes: 5 additions & 1 deletion psutil/_pssunos.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,12 @@ def disk_partitions(all=False):
debug("skipping %r: %s" % (mountpoint, err))
continue
maxfile = maxpath = None # set later

# Not yet implemented
rotational = None

ntuple = _common.sdiskpart(device, mountpoint, fstype, opts,
maxfile, maxpath)
maxfile, maxpath, rotational)
retlist.append(ntuple)
return retlist

Expand Down
6 changes: 5 additions & 1 deletion psutil/_pswindows.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,11 @@ def disk_usage(path):
def disk_partitions(all):
"""Return disk partitions."""
rawlist = cext.disk_partitions(all)
return [_common.sdiskpart(*x) for x in rawlist]

# Not yet implemented
rotational = None

return [_common.sdiskpart(*x, rotational) for x in rawlist]


# =====================================================================
Expand Down