Advertisement
Guest User

Untitled

a guest
May 25th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. import os
  2.  
  3.  
  4. def count_lines(start, lines=0, header=True, begin_start=None, exclude=None):
  5. if header:
  6. print('{:>10} |{:>10} | {:<20}'.format('ADDED', 'TOTAL', 'FILE'))
  7. print('{:->11}|{:->11}|{:->20}'.format('', '', ''))
  8.  
  9. for thing in os.listdir(start):
  10. thing = os.path.join(start, thing)
  11. if os.path.isfile(thing):
  12. if thing.endswith('.py'):
  13. with open(thing, 'r') as f:
  14. newlines = f.readlines()
  15. newlines = len(newlines)
  16. lines += newlines
  17.  
  18. if begin_start is not None:
  19. reldir_of_thing = '.' + thing.replace(begin_start, '')
  20. else:
  21. reldir_of_thing = '.' + thing.replace(start, '')
  22.  
  23. print('{:>10} |{:>10} | {:<20}'.format(
  24. newlines, lines, reldir_of_thing))
  25.  
  26.  
  27. for thing in os.listdir(start):
  28. if exclude is not None and thing in exclude:
  29. continue
  30. thing = os.path.join(start, thing)
  31. if os.path.isdir(thing):
  32. lines = count_lines(
  33. thing,
  34. lines, header=False,
  35. begin_start=start if begin_start is None else begin_start,
  36. exclude=exclude)
  37.  
  38. return lines
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement