forked from aosabook/500lines
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcountlines.py
More file actions
38 lines (32 loc) · 936 Bytes
/
countlines.py
File metadata and controls
38 lines (32 loc) · 936 Bytes
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
import os
import difflib
currdir = os.path.dirname(os.path.abspath(__file__))
dirs = [p for p in os.listdir(currdir) if os.path.isdir(p) and "0" in p]
dirs.sort()
total = 0
print dirs[0]
prev = {}
for fn in sorted(os.listdir(dirs[0])):
fulln = os.path.join(dirs[0], fn)
if not fn.endswith(".py") or not os.path.isfile(fulln):
continue
with file(fulln) as f:
lines = f.readlines()
print len(lines), fn
total += len(lines)
prev[fn] = lines
print
for d in dirs[1:]:
print d
for fn, prevlines in sorted(prev.items()):
fulln = os.path.join(d, fn)
with file(fulln) as f:
lines = f.readlines()
diffsize = len(list(difflib.unified_diff(prevlines, lines, n=1)))
print diffsize, fn
#print "".join(difflib.unified_diff(prevlines, lines))
prev[fn] = lines
total += diffsize
print
print "------------"
print total, "total"