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