Skip to content

Instantly share code, notes, and snippets.

@philipmat
Created August 3, 2015 04:33
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 philipmat/342738d7fd3ec43cd67a to your computer and use it in GitHub Desktop.
Save philipmat/342738d7fd3ec43cd67a to your computer and use it in GitHub Desktop.
Brew Cleanup Calculator
from __future__ import print_function
import re
import sys
# 1. brew cleanup > /tmp/brew_cleanup.txt
# 2. python cleanup_total.py /tmp/brew_cleanup.txt
cleanup_file = '/tmp/brew_cleanup.txt'
if len(sys.argv) > 1:
file = sys.argv[1]
mult = { 'K': 1000, 'M': 1000000 }
total = 0.0
with open(cleanup_file, 'r') as f:
for line in f:
m = re.search(r'(?P<q>\d+|\d+.\d+)(?P<m>K|M)', line)
if m:
q = float(m.group('q'))
m = m.group('m')
total += q * mult[m]
print('Total: {0:,g} MB'.format(total / mult['M']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment