Created
September 1, 2012 07:26
-
-
Save nychng/3566434 to your computer and use it in GitHub Desktop.
Django Project Code Counter!
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
from django.core.management.base import BaseCommand | |
from django.conf import settings | |
import os | |
class Command(BaseCommand): | |
""" | |
This counts the code for each app in the project and displays the | |
lines of code of unit test written. | |
""" | |
help = 'Display Project Code Count and Unit Test Code count' | |
def handle(self, *args, **options): | |
file_types = ['views.py', 'forms.py', 'models.py', 'utils.py', 'tests.py'] | |
counter = 0 | |
unit_test_counter = 0 | |
for app in settings.APPS: | |
for file_type in file_types: | |
file_name = app + '/' + file_type | |
if os.path.exists(file_name): | |
with open(file_name) as f: | |
for row in f: | |
counter += 1 | |
if file_type == 'tests.py': | |
unit_test_counter += 1 | |
print 'Total lines of code in bbox only apps: %s' % counter | |
print 'Total lines of code in bbox excluding tests: %s' % (counter - unit_test_counter) | |
print 'Total lines of code in bbox tests: %s' % unit_test_counter | |
print 'For every 1 line of code written, %s lines of test code is written' \ | |
% (float(counter-unit_test_counter) / float(unit_test_counter)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wait, how do you call this?