Debian Codegraph @

planetary_system_stacker/Test_programs/count_lines_of_code.py

raw symbols SCIP
1 # -*- coding: utf-8; -*-
2
3 import os
4
5 def countlines(start, lines=0, header=True, begin_start=None):
6 if header:
7 print('{:>10} |{:>10} | {:<20}'.format('ADDED', 'TOTAL', 'FILE'))
8 print('{:->11}|{:->11}|{:->20}'.format('', '', ''))
9
10 for thing in os.listdir(start):
11 thing = os.path.join(start, thing)
12
13 # With the following line only non-GUI code is counted.
14 if os.path.isfile(thing) and not os.path.isfile(thing[:-3] + '.ui'):
15 # As an alternative count all files.
16 # if os.path.isfile(thing):
17 if thing.endswith('.py'):
18 with open(thing, 'r') as f:
19 newlines = f.readlines()
20 newlines = len(newlines)
21 lines += newlines
22
23 if begin_start is not None:
24 reldir_of_thing = '.' + thing.replace(begin_start, '')
25 else:
26 reldir_of_thing = '.' + thing.replace(start, '')
27
28 print('{:>10} |{:>10} | {:<20}'.format(
29 newlines, lines, reldir_of_thing))
30
31
32 for thing in os.listdir(start):
33 thing = os.path.join(start, thing)
34 if os.path.isdir(thing):
35 lines = countlines(thing, lines, header=False, begin_start=start)
36
37 return lines
38
39 directory = r'D:\SW-Development\Python\PlanetarySystemStacker\planetary_system_stacker'
40 lines = countlines(directory)