cleaned up, etc.

This commit is contained in:
brent s
2019-10-30 03:46:33 -04:00
parent f0d93658d0
commit c4386d55d1
10 changed files with 33 additions and 396 deletions

View File

@@ -18,7 +18,7 @@ import blkinfo
import parted # https://www.gnu.org/software/parted/api/index.html
import psutil
##
from aif.utils import xmlBool
from aif.utils import xmlBool, size
PARTED_FSTYPES = sorted(list(dict(vars(parted.filesystem))['fileSystemType'].keys()))
@@ -26,23 +26,11 @@ PARTED_FLAGS = sorted(list(parted.partition.partitionFlag.values()))
IDX_FLAG = dict(parted.partition.partitionFlag)
FLAG_IDX = {v: k for k, v in IDX_FLAG.items()}
# parted lib can do SI or IEC (see table to right at https://en.wikipedia.org/wiki/Binary_prefix)
# We bit-shift to do conversions:
# https://stackoverflow.com/a/12912296/733214
# https://stackoverflow.com/a/52684562/733214
_units = {'B': 0,
'kB': 7,
'MB': 17,
'GB': 27,
'TB': 37,
'KiB': 10,
'MiB': 20,
'GiB': 30,
'TiB': 40}
# parted lib can do SI or IEC. So can we.
_pos_re = re.compile((r'^(?P<pos_or_neg>-|\+)?\s*'
r'(?P<size>[0-9]+)\s*'
# empty means size in sectors
r'(?P<pct_unit_or_sct>%|{0}|)\s*$'.format('|'.join(list(_units.keys())))
r'(?P<pct_unit_or_sct>%|{0}|)\s*$'.format('|'.join(size.valid_storage))
))
@@ -57,11 +45,11 @@ def convertSizeUnit(pos):
from_beginning = False
else:
from_beginning = pos_or_neg
size = int(pos.group('size'))
_size = int(pos.group('size'))
amt_type = pos.group('pct_unit_or_sct').strip()
else:
raise ValueError('Invalid size specified: {0}'.format(orig_pos))
return((from_beginning, size, amt_type))
return((from_beginning, _size, amt_type))
class Partition(object):
@@ -105,8 +93,8 @@ class Partition(object):
sectors = x['size']
if x['type'] == '%':
sectors = int(self.device.getLength() / x['size'])
elif x['type'] in _units.keys():
sectors = int(x['size'] << _units[x['type']] / self.device.sectorSize)
else:
sectors = int(size.convertStorage(x['size'], x['type'], target = 'B') / self.device.sectorSize)
sizes[s] = (sectors, x['from_bgn'])
if sizes['start'][1] is not None:
if sizes['start'][1]:

View File

@@ -36,8 +36,9 @@ for i in os.listdir(_mod_dir):
if fs_name:
# The kernel *probably* has autoloading enabled, but in case it doesn't...
# TODO: logging!
subprocess.run(['modprobe', fs_name])
FS_FSTYPES.append(fs_name)
if os.getuid() == 0:
subprocess.run(['modprobe', fs_name])
FS_FSTYPES.append(fs_name)
class FS(object):

View File

@@ -11,7 +11,7 @@ from aif.disk.block import Disk
from aif.disk.block import Partition
SUPPORTED_LEVELS = (0, 1, 4, 5, 6)
SUPPORTED_LEVELS = (0, 1, 4, 5, 6, 10)
SUPPORTED_METADATA = ('0', '0.90', '1', '1.0', '1.1', '1.2', 'default', 'ddf', 'imsm')
SUPPORTED_LAYOUTS = {5: (re.compile(r'^((left|right)-a?symmetric|[lr][as]|'
r'parity-(fir|la)st|'