#!/usr/bin/python3 # -*- coding: utf-8 -*- from curses import color_pair as get_pair mountpoints = ( '/', ) # C'est pour importer des modules du repertoire parent from os.path import dirname from sys import path as pythonpath pythonpath.insert (0, dirname (dirname (__file__))) from utils import bytes_human def diskfree (path): from os import statvfs fs = statvfs (path) def total (): return (int (fs.f_blocks*fs.f_bsize)) def percent (): return (int ((fs.f_blocks - fs.f_bfree)/(fs.f_blocks*0.01))) def used (): return (int ((fs.f_blocks - fs.f_bfree)*fs.f_bsize)) def free (): return (int (fs.f_bavail * fs.f_frsize)) return [path, total (), used (), free (), percent ()] def main (line, screen): screen.addstr (line, 0, '-->', get_pair (5)) screen.addstr (line, 3, 'Espace disque :', get_pair (1)) line += 1 data = [] for i in mountpoints: data.append (diskfree (i)) table=[] for i in data: table.append ((i[0], bytes_human (i [1]), bytes_human (i[2]), bytes_human (i[3]), i [4])) max_lengths = [0, 0, 0, 0, 0] for i in table: length = len (i [0]) if length > max_lengths [0]: max_lengths [0] = length length = len (i [1]) if length > max_lengths [1]: max_lengths [1] = length length = len (i [2]) if length > max_lengths [2]: max_lengths [2] = length length = len (i [3]) if length > max_lengths [3]: max_lengths [3] = length length = len (str (i [4]) + '%') if length > max_lengths [4]: max_lengths [4] = length for i in table: x = 0 f = '%-' + str (max_lengths [0]) + 's:' screen.addstr (line, x, f%(i [0]), get_pair (2)) x += max_lengths [0] + 2 f = '%' + str (max_lengths [1]) + 's' screen.addstr (line, x, f%((i[1])), get_pair (3)) x += max_lengths [1] + 3 f = '%' + str (max_lengths [2]) + 's' screen.addstr (line, x, f%((i[2])), get_pair (3)) x += max_lengths [2] + 3 f = '%' + str (max_lengths [3]) + 's' screen.addstr (line, x, f%((i[3])), get_pair (3)) x += max_lengths [3] + 3 f = '%' + str (max_lengths [4]) + 's' if i[4] < 90: screen.addstr (line, x, f%((i[4])), get_pair (3)) else: screen.addstr (line, x, f%((i[4])), get_pair (4)) screen.addstr (line, x + max_lengths [4] + 1, '%', get_pair (1)) x += max_lengths [4] + 5 line += 1 return (line)