summaryrefslogtreecommitdiff
path: root/psutil/_pslinux.py
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2020-02-11 18:07:55 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2020-02-11 18:07:55 +0100
commit00a339886a63887e1abb225d62827ff2d961a75f (patch)
tree8a8c1ece064d060576cd0451c78301305e35df05 /psutil/_pslinux.py
parent76104dbc77623cca46c18c5ef1534399d10f563d (diff)
downloadpsutil-00a339886a63887e1abb225d62827ff2d961a75f.tar.gz
fix #1681 / linux / disk_partitions: show swap
Diffstat (limited to 'psutil/_pslinux.py')
-rw-r--r--psutil/_pslinux.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py
index ba65aea9..60941589 100644
--- a/psutil/_pslinux.py
+++ b/psutil/_pslinux.py
@@ -1177,6 +1177,33 @@ def disk_partitions(all=False):
continue
ntuple = _common.sdiskpart(device, mountpoint, fstype, opts)
retlist.append(ntuple)
+
+ # swap
+ if all:
+ try:
+ f = open_text("%s/swaps" % procfs_path)
+ except FileNotFoundError:
+ pass
+ else:
+ with f:
+ lines = f.readlines()
+ lines.pop(0) # header
+ for line in lines:
+ fields = line.split('\t')
+ device = fields[0].split()[0]
+ mountp = None
+ fstype = 'swap'
+ # The priority column is useful when multiple swap
+ # files are in use. The lower the priority, the
+ # more likely the swap file is to be used.
+ prio = fields[-1].strip()
+ if re.match(r'(-)?\d+', prio):
+ opts = "priority=" + prio
+ else:
+ opts = ''
+ ntuple = _common.sdiskpart(device, mountp, fstype, opts)
+ retlist.append(ntuple)
+
return retlist