cleaned up, etc.
This commit is contained in:
@@ -1,3 +1,12 @@
|
||||
import os
|
||||
import re
|
||||
|
||||
version = '0.2.0'
|
||||
external_deps = ['blkinfo',
|
||||
'gpg',
|
||||
'lxml',
|
||||
'mdstat',
|
||||
'passlib',
|
||||
'psutil',
|
||||
'pyparted',
|
||||
'pyroute2',
|
||||
'pytz',
|
||||
'requests',
|
||||
'validators']
|
||||
@@ -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]:
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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|'
|
||||
|
||||
@@ -11,10 +11,8 @@ import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import venv
|
||||
|
||||
# TODO: a more consistent way of managing deps?
|
||||
depmods = ['blkinfo', 'gpg', 'lxml', 'mdstat', 'passlib', 'psutil',
|
||||
'pyparted', 'pyroute2', 'pytz', 'requests', 'validators']
|
||||
##
|
||||
import aif.constants
|
||||
|
||||
class EnvBuilder(object):
|
||||
def __init__(self):
|
||||
@@ -37,7 +35,7 @@ class EnvBuilder(object):
|
||||
# This is SO. DUMB. WHY DO I HAVE TO CALL PIP FROM A SHELL. IT'S WRITTEN IN PYTHON.
|
||||
# https://pip.pypa.io/en/stable/user_guide/#using-pip-from-your-program
|
||||
# TODO: logging
|
||||
for m in depmods:
|
||||
for m in aif.constants.external_deps:
|
||||
pip_cmd = [os.path.join(self.vdir,
|
||||
'bin',
|
||||
'python3'),
|
||||
|
||||
@@ -38,6 +38,8 @@ def collapseValues(d, vallist = None):
|
||||
class _Sizer(object):
|
||||
def __init__(self):
|
||||
# We use different methods for converting between storage and BW, and different multipliers for each subtype.
|
||||
# https://stackoverflow.com/a/12912296/733214
|
||||
# https://stackoverflow.com/a/52684562/733214
|
||||
# https://stackoverflow.com/questions/5194057/better-way-to-convert-file-sizes-in-python
|
||||
# https://en.wikipedia.org/wiki/Orders_of_magnitude_(data)
|
||||
# https://en.wikipedia.org/wiki/Binary_prefix
|
||||
@@ -92,13 +94,13 @@ class _Sizer(object):
|
||||
for unit_type, convpair in self.storageUnits.items():
|
||||
for f, l in convpair.items():
|
||||
for suffix in l:
|
||||
if suffix not in self.valid_storage:
|
||||
if suffix not in self.valid_storage and suffix:
|
||||
self.valid_storage.append(suffix)
|
||||
self.valid_bw = []
|
||||
for unit_type, convpair in self.bwUnits.items():
|
||||
for f, l in convpair.items():
|
||||
for suffix in l:
|
||||
if suffix not in self.valid_bw:
|
||||
if suffix not in self.valid_bw and suffix:
|
||||
self.valid_bw.append(suffix)
|
||||
|
||||
def convert(self, n, suffix):
|
||||
|
||||
Reference in New Issue
Block a user