Skip to content

Instantly share code, notes, and snippets.

@kapilt
Last active October 31, 2016 12:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kapilt/d0485d6fac3be6caaed2 to your computer and use it in GitHub Desktop.
Save kapilt/d0485d6fac3be6caaed2 to your computer and use it in GitHub Desktop.
import subprocess
import re
regex = re.compile('([A-Z]+)=(?:"(.*?)")')
parts = "NAME,KNAME,MODEL,UUID,SIZE,ROTA,TYPE,MOUNTPOINT,MAJ:MIN"
def blocks():
blocks = []
output = subprocess.check_output([
"sudo", "lsblk", "-P", "-o",
"NAME,KNAME,MODEL,UUID,SIZE,ROTA,FSTYPE,TYPE,MOUNTPOINT,MAJ:MIN"])
for l in output.strip().splitlines():
blocks.append(dict([(k.lower(), v) for k, v in regex.findall(l)]))
return blocks
if __name__ == '__main__':
import pprint
pprint.pprint(blocks())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment