Merge pull request #434 from facetoe/revert_disk_changes
Revert breaking changes to disk.py
This commit is contained in:
commit
fd8b6ecbf5
@ -1,23 +1,15 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from i3pystatus import IntervalModule
|
from i3pystatus import IntervalModule
|
||||||
|
|
||||||
from .core.util import round_dict
|
from .core.util import round_dict
|
||||||
|
|
||||||
|
|
||||||
class Disk(IntervalModule):
|
class Disk(IntervalModule):
|
||||||
"""
|
"""
|
||||||
Obtains usage statistics from the given mounted filesystem.
|
Gets ``{used}``, ``{free}``, ``{avail}`` and ``{total}`` amount of bytes on the given mounted filesystem.
|
||||||
|
|
||||||
.. rubric:: Available formatters
|
These values can also be expressed as percentages with the ``{percentage_used}``, ``{percentage_free}``
|
||||||
|
and ``{percentage_avail}`` formats.
|
||||||
* `{used}` — used space (unit determined by divisor)
|
|
||||||
* `{free}` — free space (unit determined by divisor)
|
|
||||||
* `{avail}` — avail space (unit determined by divisor)
|
|
||||||
* `{total}` — total space (unit determined by divisor)
|
|
||||||
* `{percentage_used}` — percentage used
|
|
||||||
* `{percentage_free}` — percentage free
|
|
||||||
* `{percentage_avail}` — percentage avail
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
settings = (
|
settings = (
|
||||||
@ -27,9 +19,6 @@ class Disk(IntervalModule):
|
|||||||
("display_limit", "if more space is available than this limit the module is hidden"),
|
("display_limit", "if more space is available than this limit the module is hidden"),
|
||||||
("critical_limit", "critical space limit (see critical_color)"),
|
("critical_limit", "critical space limit (see critical_color)"),
|
||||||
("critical_color", "the critical color"),
|
("critical_color", "the critical color"),
|
||||||
("critical_metric",
|
|
||||||
"the metric used for calculating the critical limit. Available metrics are "
|
|
||||||
"used, free, avail, percentage_free, percentage_avail and percentage_used."),
|
|
||||||
("color", "the common color"),
|
("color", "the common color"),
|
||||||
("round_size", "precision, None for INT"),
|
("round_size", "precision, None for INT"),
|
||||||
("mounted_only", "display only if path is a valid mountpoint"),
|
("mounted_only", "display only if path is a valid mountpoint"),
|
||||||
@ -40,7 +29,6 @@ class Disk(IntervalModule):
|
|||||||
color = "#FFFFFF"
|
color = "#FFFFFF"
|
||||||
color_not_mounted = "#FFFFFF"
|
color_not_mounted = "#FFFFFF"
|
||||||
critical_color = "#FF0000"
|
critical_color = "#FF0000"
|
||||||
critical_metric = 'avail'
|
|
||||||
format = "{free}/{avail}"
|
format = "{free}/{avail}"
|
||||||
format_not_mounted = None
|
format_not_mounted = None
|
||||||
divisor = 1024 ** 3
|
divisor = 1024 ** 3
|
||||||
@ -76,6 +64,8 @@ class Disk(IntervalModule):
|
|||||||
self.output = {}
|
self.output = {}
|
||||||
return
|
return
|
||||||
|
|
||||||
|
critical = available < self.critical_limit
|
||||||
|
|
||||||
cdict = {
|
cdict = {
|
||||||
"total": (stat.f_bsize * stat.f_blocks) / self.divisor,
|
"total": (stat.f_bsize * stat.f_blocks) / self.divisor,
|
||||||
"free": (stat.f_bsize * stat.f_bfree) / self.divisor,
|
"free": (stat.f_bsize * stat.f_bfree) / self.divisor,
|
||||||
@ -85,12 +75,6 @@ class Disk(IntervalModule):
|
|||||||
"percentage_avail": stat.f_bavail / stat.f_blocks * 100,
|
"percentage_avail": stat.f_bavail / stat.f_blocks * 100,
|
||||||
"percentage_used": (stat.f_blocks - stat.f_bfree) / stat.f_blocks * 100,
|
"percentage_used": (stat.f_blocks - stat.f_bfree) / stat.f_blocks * 100,
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.critical_metric not in cdict:
|
|
||||||
raise Exception("{} is not a valid critical_metric. Available metrics: {}"
|
|
||||||
.format(self.critical_metric, list(cdict.keys())))
|
|
||||||
critical = (cdict[self.critical_metric] > self.critical_limit) and self.critical_limit > 0
|
|
||||||
|
|
||||||
round_dict(cdict, self.round_size)
|
round_dict(cdict, self.round_size)
|
||||||
|
|
||||||
self.data = cdict
|
self.data = cdict
|
||||||
|
Loading…
Reference in New Issue
Block a user