-
-
Save atomictom/5216cb72cc18b2799014 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/usr/bin/python | |
| import os | |
| import re | |
| df_lines = list(os.popen("/bin/df -h")) | |
| def report(place, line): | |
| # Grab the fields from each line in the df command | |
| fs, size, used, avail, percentage, mount = re.match("(\S+)\s+" * 6, line).groups() | |
| # Turn the percentage into an actual float | |
| ratio = float(re.match("\d+", percentage).group(0)) / 100 | |
| # Create some filled and unfilled characters corresponding to the ratio of available space | |
| filled = "#" * int(round(ratio * 50)) | |
| unfilled = "_" * int(round((1 - ratio) * 50)) | |
| print "{} --> [{}{}]".format(place, filled, unfilled) | |
| print "\tAvailable: {}".format(avail) | |
| print "\tPercentage: {}".format(percentage) | |
| # Grab info for my Data partition | |
| for line in df_lines: | |
| if "Data" in line: | |
| report("Data", line) | |
| # Grab info for my home partition | |
| for line in df_lines: | |
| if "home" in line: | |
| report("Home", line) | |
| # Grab info for the root partition | |
| for line in df_lines: | |
| if line.strip()[-1] == "/": | |
| report("Root", line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment