options for selecting excludes

This commit is contained in:
Ville Rantanen
2020-09-29 11:06:06 +03:00
parent 2f4cfd196f
commit cc7397e78b

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import sys,os,glob
from datetime import datetime
@@ -7,7 +7,7 @@ import re,signal,time
import subprocess
#,threading
VERSION=2
VERSION=3
W= '30'
R= '31'
@@ -43,18 +43,21 @@ Shows the output of df in colour.
help="Refresh delay")
parser.add_argument("-1",action="store_true",dest="once",default=False,
help="Run once and exit")
parser.add_argument("-x",'--exclude',type=str,dest="exclude",default="tmpfs,devtmpfs,squashfs",
help="Comma separated list of excluded filesystem types. Defaults: %(default)s")
parser.add_argument("--version",action='version', version=VERSION)
options=parser.parse_args()
return options
def c(attribs):
''' ANSI colorizer '''
if not options.colors:
return ""
return '\033['+';'.join(attribs)+'m'
def pos(y,x):
''' ANSI absolute position set '''
return "\033["+str(y)+";"+str(x)+"H"
@@ -104,6 +107,7 @@ def count_running(string, stats):
stats['totals']=[totalfree, total]
return stats
class EndProgram( Exception ):
''' Nice way of exiting the program '''
pass
@@ -117,6 +121,7 @@ def is_number(s):
except:
return False
def str_short(s,stats):
''' shorten text to fit screen '''
maxL=stats['size'][1] - 16
@@ -161,6 +166,7 @@ def print_stats(stats):
sys.stdout.write(DOWN+CLRBLN+CLRLN)
#sys.stdout.write(LOAD)
def print_stats_once(stats):
''' Prints logged errors, once '''
e=0
@@ -210,11 +216,13 @@ def mean_speed(history):
speed=sum(history)/len(history)
return int(speed)
def human_time(dt=False):
if not dt:
dt=datetime.now()
return dt.strftime("%H:%M:%S")
def human_size(size,precision=1):
if size==None:
return 'nan'
@@ -231,6 +239,7 @@ def human_size(size,precision=1):
defPrecision=precision
return "%s%.*f%s"%(sign,defPrecision,size,suffixes[suffixIndex])
def readinput(lf):
try:
line = lf.stdout.readline()
@@ -239,6 +248,7 @@ def readinput(lf):
except:
return "CleanerTimeout"
def termsize():
try:
rows, columns = os.popen('stty size', 'r').read().split()
@@ -265,11 +275,15 @@ stats={'time':datetime.now(),
if not options.once:
sys.stdout.write(CLR+pos(0,0)+"Launching...")
omit_opts = []
for omit in options.exclude.split(","):
omit_opts.append("-x")
omit_opts.append(omit.strip())
while 1:
try:
proc = subprocess.Popen(['df','-x','tmpfs','-x','devtmpfs','-T'],stdout=subprocess.PIPE)
proc = subprocess.Popen(['df','-T'] + omit_opts,stdout=subprocess.PIPE)
# set a 5 second timeout for the line read.
#~ signal.signal(signal.SIGALRM, transfers.readline)
#~ signal.alarm(5)
@@ -277,7 +291,7 @@ while 1:
if not stdout:
raise EndProgram
for line in stdout.split('\n')[1:]:
for line in stdout.decode('utf-8').split('\n')[1:]:
stats=count_running(line,stats)
if options.once:
@@ -287,7 +301,7 @@ while 1:
sys.stdout.flush()
time.sleep(options.delay)
except EndProgram,KeyboardInterrupt:
except (EndProgram, KeyboardInterrupt):
sys.stdout.write(DOWN+'\n')
sys.stdout.flush()