Skip to content

Instantly share code, notes, and snippets.

@benfulton
Created March 2, 2014 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benfulton/9311549 to your computer and use it in GitHub Desktop.
Save benfulton/9311549 to your computer and use it in GitHub Desktop.
# This script reads a GIT directory and prints out the contents
# appropriately to be incorporated into a Google Visualization Treemap
# https://code.google.com/apis/ajax/playground/?type=visualization#tree_map
import os
rootdir = "E:\\Git"
result = {}
for path, dirs, files in os.walk(rootdir):
key = os.path.basename(path)
if ".git" in path:
continue
parent = os.path.basename(os.path.dirname(path))
count = len(files)
sm = sum(os.path.getsize(os.path.join(path, f)) for f in files)
if key not in result:
result[key] = (parent, count, sm)
print "['Location', 'Parent', 'File Count', 'File Size'],"
for k,v in result.iteritems():
print "['%s', '%s', %s, %s]," % (k, v[0], v[1], v[2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment