Skip to content

Instantly share code, notes, and snippets.

@AngelicosPhosphoros
Created November 29, 2018 21:20
Show Gist options
  • Save AngelicosPhosphoros/12a8dc9b3475894db06223afd44f47a6 to your computer and use it in GitHub Desktop.
Save AngelicosPhosphoros/12a8dc9b3475894db06223afd44f47a6 to your computer and use it in GitHub Desktop.
starts = ['binaries', 'Source', 'Config', 'Content']
import os
import os.path as path
def get_file_data(filepath):
if path.isfile(filepath):
sz = path.getsize(filepath)
#print("For %s is %d"%(filepath, sz))
return filepath, sz
print ("ERROR")
return 0, 0
def get_dir_data(d):
r = []
if path.isdir(d):
for p in os.listdir(d):
pp = d + '/' + p
if path.isdir(pp):
r += get_dir_data(pp)
elif path.isfile(pp):
r.append(get_file_data(pp))
else:
continue
return r
print ("ERROR")
return r
r = []
for s in starts:
print("Started %s"%s)
t = get_dir_data(s)
r += t
def mean(x): return len(x) and sum(x)/len(x)
fs = [len, sum, max, min, mean]
szs = [x[1] for x in r]
for f in fs:
print(f, f(szs))
print ("max file is %s", max(r, key=lambda x:x[1])[0])
mxs = sorted(r, key=lambda x:x[1], reverse=True)
print("Maxes")
for x in mxs[:20]:
print ('%s\t\t\tis\t%f Mb'%(x[0], x[1]/1024/1024))
sm = sum(map(lambda x: x[1], mxs[:20]))/1024/1024
print("SUM is %f"%sm)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment