Skip to content

Instantly share code, notes, and snippets.

@atomictom
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save atomictom/5216cb72cc18b2799014 to your computer and use it in GitHub Desktop.

Select an option

Save atomictom/5216cb72cc18b2799014 to your computer and use it in GitHub Desktop.
#!/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
print
for line in df_lines:
if "home" in line:
report("Home", line)
# Grab info for the root partition
print
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