Skip to content

Instantly share code, notes, and snippets.

@emre
Created March 12, 2010 17:29
Show Gist options
  • Save emre/330550 to your computer and use it in GitHub Desktop.
Save emre/330550 to your computer and use it in GitHub Desktop.
code stats for a simple django project
# mirat'in kodu
# <proje>/scripts/stats.py
import glob
import os
SCAN_FOLDER = "../"
stats = {
"python" : 0,
"html" : 0,
"css" : 0,
}
def process_directory(foo,directory,files):
for file in files:
if os.path.splitext(file)[1] == ".py":
stats["python"] += len(open(os.path.join(directory,file),"r").readlines())
if os.path.splitext(file)[1] == ".html":
stats["html"] += len(open(os.path.join(directory,file),"r").readlines())
if os.path.splitext(file)[1] == ".css":
stats["css"] += len(open(os.path.join(directory,file),"r").readlines())
os.path.walk(SCAN_FOLDER, process_directory, "foo")
total = 0
for stat in stats.keys():
total += stats[stat]
print "%s \t %s lines of code" % (stat, stats[stat])
print "total \t %s lines of code" % total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment