1
0

loc.py 716 B

123456789101112131415161718192021222324252627
  1. import os
  2. def get_loc(path):
  3. loc = 0
  4. with open(path, "rt", encoding='utf-8') as f:
  5. loc += len(f.readlines())
  6. path = path.replace('\\', '/')
  7. print(f'{path}: {loc}')
  8. return loc
  9. def get_loc_for_dir(path):
  10. loc = 0
  11. loc_ex = 0
  12. for root, dirs, files in os.walk(path):
  13. for file in files:
  14. if file.endswith('.h') or file.endswith('.c') or file.endswith('.h'):
  15. _i = get_loc(os.path.join(root, file))
  16. if file.startswith('_'):
  17. loc_ex += _i
  18. else:
  19. loc += _i
  20. return f'{path}: {loc} (+{loc_ex})'
  21. print(get_loc_for_dir('include/pocketpy'))
  22. print()
  23. print(get_loc_for_dir('src'))