-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproject_files.py
66 lines (49 loc) · 1.54 KB
/
project_files.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python
"""
This script check missing project links and remove them.
"""
import sys, os
input_dir = sys.argv[1]
#using code ripped from:
#http://www.5dollarwhitebox.org/drupal/node/84
#to convert to human readable format
def convert_bytes(bytes):
bytes = float(bytes)
if bytes >= 1099511627776:
terabytes = bytes / 1099511627776
size = '%.2fT' % terabytes
elif bytes >= 1073741824:
gigabytes = bytes / 1073741824
size = '%.2fG' % gigabytes
elif bytes >= 1048576:
megabytes = bytes / 1048576
size = '%.2fM' % megabytes
elif bytes >= 1024:
kilobytes = bytes / 1024
size = '%.2fK' % kilobytes
else:
size = '%.2fb' % bytes
return size
typesizeH = {}
typesize = {}
typecount = {}
try:
for root, dirs, filenames in os.walk(input_dir):
for fn in filenames:
prefix, extension = os.path.splitext(fn)
ext = extension.lower()
if ext not in typesize:
typecount[ext] = typesize[ext] = 0
file = os.path.join(root, fn)
if os.path.isfile(file):
typesize[ext] += os.stat(file).st_size
typecount[ext] += 1
except KeyboardInterrupt:
pass
types = typesize.keys()
types.sort(cmp=lambda a,b: cmp(typesize[a], typesize[b]), reverse=True)
headers = ["Filetype", "Size", "Count"]
row_format = u"{:<10}{:<15}{:<20}"
print(row_format.format(*headers))
for ext in types:
print(row_format.format(ext, convert_bytes(typesize[ext]), typecount[ext]))