Created
March 11, 2019 17:54
-
-
Save Quenty/354636b2b7f3163b4087d2f4ab50beea to your computer and use it in GitHub Desktop.
Analytics script to count lines of Lua code
This file contains hidden or 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
""" | |
Utility script to count lines of Lua code | |
Author: Quenty | |
""" | |
import glob, os | |
def file_len(fname): | |
""" | |
Counts lines of a file given the name | |
:param fname: Path to the file | |
""" | |
with open(fname, encoding="utf8") as f: | |
for i, l in enumerate(f): | |
pass | |
return i + 1 | |
total_line_length = 0 | |
files = [] | |
def count_lines(path, recursive=True): | |
global total_line_length | |
global files | |
""" | |
Counts the lines in the folder | |
:param path: The path to use. In glob format. | |
:param recursive: Whether to recursively search. | |
""" | |
for file in glob.glob(path, recursive=recursive): | |
length = file_len(file) | |
total_line_length += length | |
files.append((file, length)) | |
# Add libraries and main source code | |
count_lines("..\\**\\*.lua") | |
count_lines("..\\..\\..\\libraries\\Nevermore\\Modules\\**\\*.lua") | |
count_lines("..\\..\\..\\libraries\\Nevermore\\App\\**\\*.lua") | |
# Output | |
print("Done") | |
print('\n'.join(map(str, sorted(files, key=lambda x: x[1], reverse=False)))) | |
print(f'Found {len(files)} files') | |
print(f'Lines: {total_line_length}') | |
print(f'Average length: {total_line_length/len(files)}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment