Skip to content

Instantly share code, notes, and snippets.

@magnunleno
Last active December 12, 2015 05:08
Show Gist options
  • Select an option

  • Save magnunleno/4719112 to your computer and use it in GitHub Desktop.

Select an option

Save magnunleno/4719112 to your computer and use it in GitHub Desktop.
#!/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