Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Unobtrusive Project Language Distribution
# Usage:
# python ./ [code-repository-folder]
# example:
# python ./ ~/Development/our_code/
# Will count the number of files as well as the total lines
# of code in your project for different types (cpp, m, h, swift)
# and print out a json blob with the answers.
import os, sys, json
path = None
path = sys.argv[1]
except IndexError:
print "Usage: python ./ [path-to-source-folder]"
class Entry:
name = ""
lines = 0
files = 0
count_lines = True
def __init__(self, name, count_lines = True): = name
counts = {
".swift": Entry("Swift"),
".m": Entry("Objective-C Implementation"),
".h": Entry("Header"),
".c": Entry("C Implementation"),
".cpp": Entry("C++"),
".mm": Entry("Objective-C++"),
".xib": Entry("Interface Builder", count_lines = False),
".storyboard": Entry("Storyboard", count_lines = False),
for root, dirs, files in os.walk(unicode(path)):
path = root.split(os.sep)
for file in files:
(_, ext) = os.path.splitext(file)
ext = ext.lower()
if not counts.has_key(ext): continue
if counts[ext].count_lines == True:
counts[ext].lines += sum(1 for i in open(os.path.join(root, file), 'rb'))
counts[ext].files += 1
print json.dumps(map(lambda x: {"type":, "lines": x.lines, "files": x.files}, counts.values()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment