# Created by Liang Sun <i@liangsun.org> in 2012# This code is for Python 2.ximportos,sysexts=['.py','.ini','.c','.h']count_empty_line=Truehere=os.path.abspath(os.path.dirname(sys.argv[0]))defread_line_count(fname):count=0forlineinopen(fname).readlines():ifcount_empty_lineorlen(line.strip())>0:count+=1returncountif__name__=='__main__':line_count=0file_count=0forbase,dirs,filesinos.walk(here):forfileinfiles:# Check the sub directorys iffile.find('.')<0:continueext=(file[file.rindex('.'):]).lower()try:ifexts.index(ext)>=0:file_count+=1path=(base+'/'+file)c=read_line_count(path)print".%s : %d"%(path[len(here):],c)line_count+=cexcept:passprint'File count : %d'%file_countprint'Line count : %d'%line_count
Copy and save the script as analytics.py and modify the exts list to include all the file extensions in your project, and put this script in your source code folder, then run: