Last active
October 31, 2016 12:30
-
-
Save kapilt/d0485d6fac3be6caaed2 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
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