Created
May 27, 2012 17:36
-
-
Save wagnerluis1982/2815212 to your computer and use it in GitHub Desktop.
Source code lines and statements counter (Contador de linhas e estruturas de código fonte)
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
import sys, os, re | |
info = {"folder": sys.argv[1], "extensions": sys.argv[2].split(","), "statements": dict.fromkeys(["if", "for", "while", "do", "switch", "case"], 0), "lines": 0} | |
for dirpath, dirnames, filenames in os.walk(info["folder"]): | |
for filelines in [open(os.path.join(dirpath, fname)).readlines() for fname in filenames if fname.split(".")[-1] in info["extensions"]]: | |
for line in filelines: | |
info["lines"] += 1 | |
found = re.search(r"^\s*(%s)\b" % "|".join(info["statements"].keys()), line) | |
if found != None: info["statements"][found.group(1)] += 1 | |
print "O seu codigo possui:\n %d linhas\n" % info["lines"] + "\n".join(" %s: %d" % (k, v) for k, v in info["statements"].iteritems()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment