Created
July 10, 2019 15:01
-
-
Save RyanFleck/21cbda198d1b8af9e078ebc48735dec7 to your computer and use it in GitHub Desktop.
Count lines of code for a given extension type in a repository.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# Takes file extension as first argument, counts lines of code. | |
import os | |
import sys | |
import re | |
def countLinesOfCode(extension): | |
print(r'(.*\.{}$)'.format(extension)) | |
loc = 0 | |
fileregex = re.compile(r'(.*\.{}$)'.format(extension)) | |
for dirname, subdirs, filenames in os.walk(os.getcwd()): | |
for filename in filenames: | |
if fileregex.match(filename): | |
lines = sum(1 for line in open(dirname+'/'+filename)) | |
print('> '+str(filename)+' => '+str(lines)+' lines.') | |
loc = loc + lines | |
print('\n>> '+str(loc)+' lines of '+str(extension)) | |
try: | |
countLinesOfCode(str(str(sys.argv[1]).strip().split()[0])) | |
except IndexError: | |
print('Please provide an extension to count LoC for.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment