-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCodeMetrix.py
39 lines (32 loc) · 1.1 KB
/
CodeMetrix.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
import os
from os.path import join, getsize, splitext
root= os.getcwd()
fileExtensionCounts= {}
byteSum= 0
fileExts= ['.cs', '.xaml', '.png', '.bmp', '.txt', '.spritefont', '.wmv', '.fbx', '.x', '.dds', '.nsi', '.iss', '.jpg', '.py']
ignoredFolders= ['.git', 'packages', 'bin', 'obj']
for root, dirs, files in os.walk(root):
byteSum+= sum(getsize(join(root, file)) for file in files)
for ext in filter(lambda x: x in fileExts, map(lambda y: splitext(y)[1].lower(), files)):
try:
fileExtensionCounts[ext]+= 1
except KeyError:
fileExtensionCounts[ext]= 1
for folder in ignoredFolders:
if folder in dirs:
dirs.remove(folder)
for key in sorted(fileExtensionCounts.keys()):
print key + " = " + str(fileExtensionCounts[key])
print "Total # of files: " + str(sum(fileExtensionCounts.values()))
print
print "Total relevant file size:"
abbreviations= ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'Insane Bytes!']
displayedSize= float(byteSum)
for abbrev in abbreviations:
if displayedSize / 1000 < 1:
print str(displayedSize) + " " + abbrev
break
else:
displayedSize/= 1000
else:
print "This is just way too big."