Created
May 31, 2013 01:59
-
-
Save pranavraja/5682538 to your computer and use it in GitHub Desktop.
Count length of methods in iOS codebases
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 | |
from collections import defaultdict | |
def name_of_method(signature): | |
start_method_name = signature.find(')') + 1 | |
end_method_name = signature.rfind('{') | |
return signature[start_method_name:end_method_name] | |
if __name__ == '__main__': | |
if len(sys.argv) <= 1: | |
print 'Usage: python {} filename [filename2] ...'.format(__file__) | |
sys.exit(0) | |
filenames = sys.argv[1:] | |
for filename in filenames: | |
with open(filename) as f: | |
methods = defaultdict(int) | |
current_method = None | |
for line in f: | |
if line.startswith('-') or line.startswith('+'): | |
# method declaration | |
current_method = line | |
if not current_method: | |
continue # Ignore lines not inside a method | |
if not line.strip(): | |
continue # Ignore blank lines | |
methods[current_method] += 1 | |
if line.startswith('}'): | |
current_method = None | |
for method, lines in methods.items(): | |
print '{}: {}\t{}'.format(filename, name_of_method(method), lines) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment