add option to omit filesystems
This commit is contained in:
parent
4e6d48b7af
commit
897a93b62e
|
@ -1 +1 @@
|
||||||
__version__ = "0.1.1"
|
__version__ = "0.1.2"
|
||||||
|
|
|
@ -2,12 +2,13 @@ from os import statvfs
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
|
||||||
def diskspace(filesystems=[], discover=True):
|
def diskspace(filesystems=[], discover=True, omit=[]):
|
||||||
"""
|
"""
|
||||||
Emit disk space usage statistics for the passed filesystems.
|
Emit disk space usage statistics for the passed filesystems.
|
||||||
:param filesystems: list of mountpoints to gather stats for
|
:param filesystems: list of mountpoints to gather stats for
|
||||||
:param discover: automatically find non-temporary filesystems to gather statistics for. Duplicates from the
|
:param discover: automatically find non-temporary filesystems to gather statistics for. Duplicates from the
|
||||||
filesystems param will be ignored.
|
filesystems param will be ignored.
|
||||||
|
:param omit: list of paths that, if prefix a discovered mountpoint, to not report on
|
||||||
"""
|
"""
|
||||||
filesystems = [f.rstrip("/") for f in filesystems]
|
filesystems = [f.rstrip("/") for f in filesystems]
|
||||||
if discover:
|
if discover:
|
||||||
|
@ -20,6 +21,8 @@ def diskspace(filesystems=[], discover=True):
|
||||||
filesystems.append(mountpoint)
|
filesystems.append(mountpoint)
|
||||||
|
|
||||||
for fs in set(filesystems):
|
for fs in set(filesystems):
|
||||||
|
if any([fs.startswith(i) for i in omit or []]):
|
||||||
|
continue
|
||||||
try:
|
try:
|
||||||
stats = statvfs(fs)
|
stats = statvfs(fs)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
|
@ -92,7 +95,6 @@ mapping = {
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import sys
|
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
for item in diskspace(filesystems=sys.argv[1:]):
|
for item in diskspace(filesystems=[], discover=True, omit=None):
|
||||||
pprint(item)
|
pprint(item)
|
||||||
|
|
Loading…
Reference in New Issue