diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-03-01 13:11:06 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-03-01 13:11:06 +0100 |
commit | 3360309b71a2e97ebcc4a1f425bc98b59ae9fdc9 (patch) | |
tree | e0cf37a290c9bc5de155550eeb14a4110ccb1f6f /src | |
parent | add uptime and idle time in seconds format (diff) | |
download | xpybar-3360309b71a2e97ebcc4a1f425bc98b59ae9fdc9.tar.gz xpybar-3360309b71a2e97ebcc4a1f425bc98b59ae9fdc9.tar.bz2 xpybar-3360309b71a2e97ebcc4a1f425bc98b59ae9fdc9.tar.xz |
add df
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/df.py | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/src/plugins/df.py b/src/plugins/df.py new file mode 100644 index 0000000..81ad5a2 --- /dev/null +++ b/src/plugins/df.py @@ -0,0 +1,116 @@ +# -*- python -*- +''' +xpybar – xmobar replacement written in python +Copyright © 2014 Mattias Andrée (maandree@member.fsf.org) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +''' + +from util import * + + +class Discs: + ''' + Retrieve information about mounted discs + + @variable filesystems:dict<str, Disc> Map from filesystem to disc + @variable mountpoints:dict<str, Disc> Map from mountpoint to disc + ''' + + + def __init__(self): + ''' + Constructor + ''' + self.filesystems = {} + self.mountpoints = {} + listed = {} + + df = spawn_read('df', '-B1', '-T').split('\n')[1:] + dfi = spawn_read('df', '-i').split('\n')[1:] + + # Disc usage information + for line in df: + line = line + buf = '' + cells = [] + for c in line: + if (c == ' ') and (len(cells) < 6): + if not buf == '': + cells.append(buf) + buf = '' + else: + buf += c + cells.append(buf) + (fs, fstype, blocks, used, avail, _use, mount) = cells + listed[fs] = mount + disc = Disc() + self.filesystems[fs] = disc + self.mountpoints[mount] = disc + disc.filesystem = fs + disc.mountpoint = mount + disc.fstype = fstype + disc.blocks = int(blocks) + disc.used = int(used) + disc.available = int(avail) + + # Inode usage information + for line in dfi: + line = line + buf = '' + cells = [] + for c in line: + if (c == ' ') and (len(cells) < 5): + if not buf == '': + cells.append(buf) + buf = '' + else: + buf += c + cells.append(buf) + (fs, inodes, iused, ifree, _use, _mount) = cells + if fs in self.filesystems: + del listed[fs] + disc = self.filesystems[fs] + disc.inodes = int(inodes) + disc.iused = int(iused) + disc.ifree = int(ifree) + + # Perhaps an umount appeared between `df -B1 -T` and `df -i` + for fs in listed.keys(): + del self.filesystems[fs] + del self.mountpoints[listed[fs]] + + +class Disc: + ''' + Information about a single disc + + @variable filesystem:str The filesystem, a device or API filesystem name + @variable mountpoint:str The filesystem mountpoint, the one with shortest name if there are multiple + @variable fstype:str The filesystem type + @variable blocks:int The total number of 1 byte blocks, the value is close or equal to `used + available` + @variable used:int The number of used bytes + @variable available:int The number of unused bytes + @variable inodes:int The total number of index nodes + @variable iused:int The number of used index nodes + @variable ifree:int The number of available index nodes + ''' + + + def __init__(self): + ''' + Constructor + ''' + pass + |