Advertisement
johnmahugu

python - count sloc (lines of code)

Jun 14th, 2015
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. # prints recursive count of lines of python source code from current directory
  2. # includes an ignore_list. also prints total sloc
  3.  
  4. import os
  5. cur_path = os.getcwd()
  6. ignore_set = set(["__init__.py", "count_sourcelines.py"])
  7.  
  8. loclist = []
  9.  
  10. for pydir, _, pyfiles in os.walk(cur_path):
  11.     for pyfile in pyfiles:
  12.         if pyfile.endswith(".py") and pyfile not in ignore_set:
  13.             totalpath = os.path.join(pydir, pyfile)
  14.             loclist.append( ( len(open(totalpath, "r").read().splitlines()),
  15.                                totalpath.split(cur_path)[1]) )
  16.  
  17. for linenumbercount, filename in loclist:
  18.     print "%05d lines in %s" % (linenumbercount, filename)
  19.  
  20. print "\nTotal: %s lines (%s)" %(sum([x[0] for x in loclist]), cur_path)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement