Last active
December 12, 2015 05:08
-
-
Save magnunleno/4719112 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/env python2 | |
| # encoding: utf-8 | |
| import subprocess | |
| def __get_output(command): | |
| process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) | |
| output = process.communicate() | |
| retcode = process.poll() | |
| if retcode == 0: | |
| return [out for out in output[0].split("\n") if out] | |
| else: | |
| return None | |
| class Device(object): | |
| def __init__(self): | |
| self.block_device = None | |
| self.size = None | |
| def list_harddrives_names(): | |
| drives = [] | |
| for line in __get_output("parted -lms | grep '^/dev'"): | |
| line = line.split(':') | |
| if (len(line) != 8) and (line[5] == 'loop') or ('ROM' in line[6]): | |
| continue | |
| drives.append(line[0]) | |
| return drives | |
| print list_harddrives_names() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment