source: fact/tools/pyscripts/simulation/count_lines.py@ 17254

Last change on this file since 17254 was 14805, checked in by neise, 12 years ago
initial commit
  • Property svn:executable set to *
File size: 881 bytes
Line 
1#!/usr/bin/python -tt
2import sys
3
4def count_loc(lines):
5 nb_lines = 0
6 docstring = False
7 for line in lines:
8 line = line.strip()
9
10 if line == "" \
11 or line.startswith("#") \
12 or docstring and not (line.startswith('"""') or line.startswith("'''"))\
13 or (line.startswith("'''") and line.endswith("'''") and len(line) >3) \
14 or (line.startswith('"""') and line.endswith('"""') and len(line) >3) :
15 continue
16
17 # this is either a starting or ending docstring
18 elif line.startswith('"""') or line.startswith("'''"):
19 docstring = not docstring
20 continue
21
22 else:
23 nb_lines += 1
24
25 return nb_lines
26
27if __name__ == '__main__':
28
29 for file in sys.argv[1:]:
30 f = open(file)
31 print file, count_loc(f)
32 f.close()
33
34
Note: See TracBrowser for help on using the repository browser.