Created
August 27, 2017 14:02
-
-
Save victor-iyi/46cc9707a89a9f9cc774e2a6b08ff220 to your computer and use it in GitHub Desktop.
Estimate how many lines of code is in your project π
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
import os | |
import numpy as np | |
project_dir = '/Users/victor/Documents/Devcrib/DigiSchools/desktop/digischools-desktop' | |
ignored_files = ['node_modules', 'package-lock.json', 'uploads', 'fonts', | |
'bootstrap-grid.min.css', 'bootstrap.css', 'bootstrap.min.css', 'dropzone.css', | |
'owl.carousel.min.js', 'jquery.min.js', 'jquery-1.10.2.js', 'owl.carousel.min.css', | |
'owl.theme.default.min.css', 'owl.video.play.png', 'pretty.min.css', | |
'jquery_upload.min.js', 'datatables.min.js', 'dataTables', 'datatables.min.css', | |
'bootstrap.min.js', 'dropzone.js', 'tether.min.js', 'wow.min.js', 'font-awesome.min.css', | |
'font-awesome.min.js', 'font-awesome.css'] | |
ignored_extensions = ['pdf', 'txt', 'md', 'ini', 'gif', 'jpg', 'png', 'jpeg'] | |
project_files = [] | |
directories = [] | |
files = [] | |
lines_of_code = 0 | |
def extension(file): # [check] | |
return file.split('.')[-1] | |
def list_files(project_dir): | |
listed_files = [d for d in os.listdir(project_dir) if d not in ignored_files and extension(d) not in ignored_extensions and not d[0] == '.'] | |
for file in listed_files: | |
add_file(os.path.join(project_dir, file)) | |
for d in directories: | |
get_files_from_dir(d) | |
def get_files_from_dir(directory): | |
dirs = [d for d in os.listdir(directory) if d not in ignored_files and extension(d) not in ignored_extensions and not d[0] == '.'] | |
for d in dirs: | |
add_file(os.path.join(directory, d)) | |
def add_file(file): # [check] | |
if os.path.isfile(file): | |
if file not in files: | |
files.append(file) | |
else: | |
if file not in directories: | |
directories.append(file) | |
def read_lines(file): # [check] | |
global lines_of_code | |
try: | |
source_code = np.genfromtxt(file, delimiter='\n') | |
lines_of_code += len(source_code) | |
except Exception as e: | |
pass | |
list_files(project_dir) | |
for f in files: | |
read_lines(f) | |
print('files:',len(files), '\tdirectories', len(directories)) | |
print('{:,} lines of codes in this project'.format(lines_of_code)) | |
##for file in files: | |
## print('{}\n'.format(file)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment