this should work

This commit is contained in:
brent s 2017-10-09 09:42:26 -04:00
parent 3776f89d9c
commit 6423c36f24

View File

@ -5,28 +5,26 @@
# Should probably only cron it once a week or so. # Should probably only cron it once a week or so.


import os import os
import pycryptsetup # requires cryptsetup to be configured with '--enable-python --with-python_version=3.6' (or whatever your python version is)
import lvm # requires lvm2 to be configured with '-enable-python3_bindings'
import subprocess import subprocess


def getDisks(): def getDisks():
disks = [] disks = []
for d in psutil.disk_partitions(all = False): with open(os.devnull, 'w') as _DEVNULL:
if d.device not in disks: # Avoid dupes _rawlist = subprocess.run(['parted',
_devpath = os.path.split(d.device) '--list',
if _devpath[1] == 'mapper': # It's actually an LVM, LUKS, etc. '--machine',
# Is it an LVM device? '--script'],
if lvm.scan(): stdout = subprocess.PIPE,
continue stderr = _DEVNULL).stdout.decode('utf-8')
# Is it a LUKS device? for l in _rawlist.splitlines():
_crypt = pycryptsetup.CryptSetup(d.device) if l in ('', 'BYT;'):
if _crypt.isLuks() == 0: continue # Skip empty lines and markers for new devices
# We can (and should) get the actual physical device elif l.startswith('/'):
_dev = _crypt.info()['device'] # It's a device path.
if _dev not in disks: _l = l.split(':')
disks.append(_dev) if _l[2] not in ('md', 'dm'): # Skip non-block devices like MDADM arrays, LVM volumes
else: if _l[0] not in disks:
disks.append(d.device) disks.append(_l[0])
return(disks) return(disks)


def chkDisk(disk): def chkDisk(disk):