-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathPy_Files_Sort.py
More file actions
35 lines (32 loc) · 1.11 KB
/
Copy pathPy_Files_Sort.py
File metadata and controls
35 lines (32 loc) · 1.11 KB
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
import os, sys, pprint
trace = 0 #1-dirs 2-files
visited = { }
allsizes = []
for srcdir in sys.path :
for (thisdir, subdir, files) in os.walk(srcdir):
if trace > 0: print(thisdir)
thisdir = os.path.normpath(thisdir)
fixcase = os.path.normcase(thisdir)
if fixcase in visited:
continue
else:
visited[fixcase] = True
for filename in files:
if filename.endswith('.py'):
if trace > 1: print('...', filename)
pypath = os.path.join(thisdir, filename)
try:
pysize = os.path.getsize(filename)
except os.error:
print('skipping', pypath, sys.exc_info()[0])
else:
pylines = len(open(pypath, 'rb').readlines())
allsizes.append((pysize, pylines, pypath))
print('By size...')
allsizes.sort()
pprint.pprint(allsizes[:3])
pprint.pprint(allsizes[-3:])
print('By lines...')
allsizes.sort(key=lambda x: x[1])
pprint.pprint(allsizes[:3])
pprint.pprint(allsizes[-3:])