Created
August 3, 2015 04:33
-
-
Save philipmat/342738d7fd3ec43cd67a to your computer and use it in GitHub Desktop.
Brew Cleanup Calculator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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