forked from photofroggy/wsc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstat
executable file
·52 lines (40 loc) · 1.24 KB
/
stat
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
#!/usr/bin/python
import re
import os
import sys
import os.path
import argparse
def linecount(file):
base = os.path.basename(file)
dir = os.path.dirname(file)
file = open(os.path.abspath(os.path.join(dir, base)), 'r')
lc = len(file.read().split('\n'));
nlc = lc
try:
file.close()
file = open(os.path.abspath(os.path.join(dir, 'nom.' + base)), 'r')
nlc = len(file.read().split('\n'))
except Exception:
pass
return [lc, nlc]
def countup(files):
info = {
'names': [],
'count': 0,
'ncount': 0
}
for file in files:
info['names'].append(os.path.basename(file))
lc = linecount(file)
info['count']+= lc[0]
info['ncount']+= lc[1]
return info
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Display line counts for a source file.')
parser.add_argument('file', nargs='+', help='source file to get line count for')
args = parser.parse_args()
data = countup(args.file)
dispb = '+'.join(data['names'])
sys.stdout.write('>> ' + dispb.ljust(20) + ' | ')
sys.stdout.write(str(data['count']).ljust(6) + ' | '+str(data['ncount']).ljust(6)+'\n')
sys.stdout.flush()