2016-12-10 18:21:01 +01:00
|
|
|
# pylint: disable=C0111,R0903
|
|
|
|
|
|
|
|
"""Shows free diskspace, total diskspace and the percentage of free disk space.
|
2017-03-09 21:08:31 +01:00
|
|
|
|
2016-12-10 18:21:01 +01:00
|
|
|
Parameters:
|
|
|
|
* disk.warning: Warning threshold in % of disk space (defaults to 80%)
|
|
|
|
* disk.critical: Critical threshold in % of disk space (defaults ot 90%)
|
|
|
|
* disk.path: Path to calculate disk usage from (defaults to /)
|
|
|
|
"""
|
|
|
|
|
2017-03-09 20:07:41 +01:00
|
|
|
import os
|
2016-12-10 18:21:01 +01:00
|
|
|
|
|
|
|
import bumblebee.input
|
|
|
|
import bumblebee.output
|
|
|
|
import bumblebee.engine
|
|
|
|
|
|
|
|
class Module(bumblebee.engine.Module):
|
|
|
|
def __init__(self, engine, config):
|
|
|
|
super(Module, self).__init__(engine, config,
|
|
|
|
bumblebee.output.Widget(full_text=self.diskspace)
|
|
|
|
)
|
|
|
|
self._path = self.parameter("path", "/")
|
|
|
|
self._perc = 0
|
2016-12-11 11:37:24 +01:00
|
|
|
self._used = 0
|
|
|
|
self._size = 0
|
2016-12-10 18:21:01 +01:00
|
|
|
|
|
|
|
engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE,
|
|
|
|
cmd="nautilus {}".format(self._path))
|
|
|
|
|
2016-12-11 11:37:24 +01:00
|
|
|
def diskspace(self, widget):
|
2017-03-10 08:17:43 +01:00
|
|
|
return "{} {}/{} ({:05.02f}%)".format(self._path,
|
2016-12-10 18:49:25 +01:00
|
|
|
bumblebee.util.bytefmt(self._used),
|
|
|
|
bumblebee.util.bytefmt(self._size), self._perc
|
2016-12-10 18:21:01 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
def update(self, widgets):
|
2017-03-09 20:07:41 +01:00
|
|
|
st = os.statvfs(self._path)
|
|
|
|
self._size = st.f_blocks * st.f_frsize
|
|
|
|
self._used = (st.f_blocks - st.f_bfree) * st.f_frsize
|
2016-12-10 18:49:25 +01:00
|
|
|
self._perc = 100.0*self._used/self._size
|
2016-12-10 18:21:01 +01:00
|
|
|
|
|
|
|
def state(self, widget):
|
2016-12-11 08:25:54 +01:00
|
|
|
return self.threshold_state(self._perc, 80, 90)
|
2016-12-10 18:21:01 +01:00
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|