15
16
:returns: boolean: True if path is a block device, False if not.
17
return S_ISBLK(stat(path).st_mode)
18
if not os.path.exists(path):
20
return S_ISBLK(os.stat(path).st_mode)
20
23
def zap_disk(block_device):
29
32
'--clear', block_device])
30
33
dev_end = check_output(['blockdev', '--getsz', block_device])
31
34
gpt_end = int(dev_end.split()[0]) - 100
32
check_call(['dd', 'if=/dev/zero', 'of=%s'%(block_device),
35
check_call(['dd', 'if=/dev/zero', 'of=%s' % (block_device),
33
36
'bs=1M', 'count=1'])
34
check_call(['dd', 'if=/dev/zero', 'of=%s'%(block_device),
35
'bs=512', 'count=100', 'seek=%s'%(gpt_end)])
37
check_call(['dd', 'if=/dev/zero', 'of=%s' % (block_device),
38
'bs=512', 'count=100', 'seek=%s' % (gpt_end)])
41
def is_device_mounted(device):
42
'''Given a device path, return True if that device is mounted, and False
45
:param device: str: Full path of the device to check.
46
:returns: boolean: True if the path represents a mounted device, False if
49
out = check_output(['mount'])
50
return bool(re.search(device + r"[0-9]+\b", out))