|
|
|
@ -214,9 +214,13 @@ class DetailProcess(Analysis):
|
|
|
|
|
ma += [ dict(now, **self.format(row)) for row in matrix]
|
|
|
|
|
|
|
|
|
|
return ma
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
This class evaluates a list of folders and provides detailed informaiton about age/size of each file
|
|
|
|
|
Additionally the the details are summarized in terms of global size, and oldest file.
|
|
|
|
|
"""
|
|
|
|
|
class FileWatch(Analysis):
|
|
|
|
|
def __init__(self,conf):
|
|
|
|
|
def __init__(self,folders):
|
|
|
|
|
self.folders = folders
|
|
|
|
|
pass
|
|
|
|
|
def split(self,row):
|
|
|
|
|
|
|
|
|
@ -228,16 +232,29 @@ class FileWatch(Analysis):
|
|
|
|
|
print x
|
|
|
|
|
size = float(x[0].replace('K','').replace('KB','')) / 1000
|
|
|
|
|
elif 'M' in x[0] :
|
|
|
|
|
size = x[0].replace('MB','')
|
|
|
|
|
size = float(x[0].replace('MB','').replace('M',''))
|
|
|
|
|
elif 'G' in x[0] :
|
|
|
|
|
size = x[0].replace('GB','') * 1000
|
|
|
|
|
size = float(x[0].replace('GB','').replace('G','')) * 1000
|
|
|
|
|
elif 'T' in x[0] :
|
|
|
|
|
pass
|
|
|
|
|
size = float(x[0].replace('TB','').replace('T','')) * 1000000
|
|
|
|
|
else :
|
|
|
|
|
#
|
|
|
|
|
# Size provided in bytes we are converting into MB
|
|
|
|
|
size = float(x[0]) / 1000000
|
|
|
|
|
month = months.index(x[1]) + 1
|
|
|
|
|
day = x[2]
|
|
|
|
|
print [' ** ',x[4]]
|
|
|
|
|
#hour,minute = x[3].split(':')
|
|
|
|
|
year = x[4]
|
|
|
|
|
day = int(x[2])
|
|
|
|
|
age = -1
|
|
|
|
|
hour=minute = 0
|
|
|
|
|
if ':' in x[3] :
|
|
|
|
|
hour,minute = x[3].split(':')
|
|
|
|
|
if re.match('^\d+$',x[4]):
|
|
|
|
|
year = int(x[4])
|
|
|
|
|
else:
|
|
|
|
|
year = datetime.datetime.today().year
|
|
|
|
|
file_date = datetime.datetime(year,month,day,int(hour),int(minute))
|
|
|
|
|
size = round(size,2)
|
|
|
|
|
#file_date = datetime.datetime(year,month,day,hour,minute)
|
|
|
|
|
age = (file_date - datetime.datetime.now()).days
|
|
|
|
|
return {"size":size,"age":age}
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
@ -247,9 +264,17 @@ class FileWatch(Analysis):
|
|
|
|
|
handler = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE)
|
|
|
|
|
ostream = handler.communicate()[0].split('\n')
|
|
|
|
|
|
|
|
|
|
print [self.split(stream) for stream in ostream if stream.strip() != '']
|
|
|
|
|
pass
|
|
|
|
|
return [self.split(stream) for stream in ostream if stream.strip() != '']
|
|
|
|
|
def composite(self):
|
|
|
|
|
d = [] #-- matrix of details (age,size)
|
|
|
|
|
s = {} #-- summary of the
|
|
|
|
|
for folder in self.folders:
|
|
|
|
|
if os.path.exists(folder):
|
|
|
|
|
d += self.evaluate(folder)
|
|
|
|
|
xo = np.array(ML.Extract(['size','age'],d))
|
|
|
|
|
s[folder] = [np.sum(xo[:,0]),np.max(xo[:,1])]
|
|
|
|
|
|
|
|
|
|
return {"summary":s,"details":d}
|
|
|
|
|
class Monitor (Thread):
|
|
|
|
|
def __init__(self,pConfig,pWriter,id='processes') :
|
|
|
|
|
Thread.__init__(self)
|
|
|
|
|