diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2016-02-04 09:10:36 +0100 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2016-02-04 09:10:36 +0100 |
commit | a1ca4ade2f72a30bc94820b99097957f60a09773 (patch) | |
tree | d2750a72c7c19267563210c9f8a3c24bfbcd720e | |
parent | f156559077eb55bed9efb32e29729ee71393680a (diff) | |
download | psutil-a1ca4ade2f72a30bc94820b99097957f60a09773.tar.gz |
little refactoring
-rw-r--r-- | psutil/_pslinux.py | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py index a5b79633..2dab99b0 100644 --- a/psutil/_pslinux.py +++ b/psutil/_pslinux.py @@ -732,24 +732,27 @@ def disk_io_counters(): SECTOR_SIZE = 512 # determine partitions we want to look for - partitions = [] - with open_text("%s/partitions" % get_procfs_path()) as f: - lines = f.readlines()[2:] - for line in reversed(lines): - _, _, _, name = line.split() - if name[-1].isdigit(): - # we're dealing with a partition (e.g. 'sda1'); 'sda' will - # also be around but we want to omit it - partitions.append(name) - else: - if not partitions or not partitions[-1].startswith(name): - # we're dealing with a disk entity for which no - # partitions have been defined (e.g. 'sda' but - # 'sda1' was not around), see: - # https://github.com/giampaolo/psutil/issues/338 + def get_partitions(): + partitions = [] + with open_text("%s/partitions" % get_procfs_path()) as f: + lines = f.readlines()[2:] + for line in reversed(lines): + _, _, _, name = line.split() + if name[-1].isdigit(): + # we're dealing with a partition (e.g. 'sda1'); 'sda' will + # also be around but we want to omit it partitions.append(name) - # + else: + if not partitions or not partitions[-1].startswith(name): + # we're dealing with a disk entity for which no + # partitions have been defined (e.g. 'sda' but + # 'sda1' was not around), see: + # https://github.com/giampaolo/psutil/issues/338 + partitions.append(name) + return partitions + retdict = {} + partitions = get_partitions() with open_text("%s/diskstats" % get_procfs_path()) as f: lines = f.readlines() for line in lines: |