Update classmethods to use cls (#4110)
This commit is contained in:
parent
01bee60cd1
commit
cb4b7e3db0
|
|
@ -132,7 +132,7 @@ class ArchConfig:
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_config(cls, args_config: dict[str, Any], args: Arguments) -> 'ArchConfig':
|
def from_config(cls, args_config: dict[str, Any], args: Arguments) -> 'ArchConfig':
|
||||||
arch_config = ArchConfig()
|
arch_config = cls()
|
||||||
|
|
||||||
arch_config.locale_config = LocaleConfiguration.parse_arg(args_config)
|
arch_config.locale_config = LocaleConfiguration.parse_arg(args_config)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,25 +37,25 @@ class Bootloader(Enum):
|
||||||
from ..args import arch_config_handler
|
from ..args import arch_config_handler
|
||||||
|
|
||||||
if arch_config_handler.args.skip_boot:
|
if arch_config_handler.args.skip_boot:
|
||||||
return Bootloader.NO_BOOTLOADER
|
return cls.NO_BOOTLOADER
|
||||||
elif SysInfo.has_uefi():
|
elif SysInfo.has_uefi():
|
||||||
return Bootloader.Systemd
|
return cls.Systemd
|
||||||
else:
|
else:
|
||||||
return Bootloader.Grub
|
return cls.Grub
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_arg(cls, bootloader: str, skip_boot: bool) -> Bootloader:
|
def from_arg(cls, bootloader: str, skip_boot: bool) -> Bootloader:
|
||||||
# to support old configuration files
|
# to support old configuration files
|
||||||
bootloader = bootloader.capitalize()
|
bootloader = bootloader.capitalize()
|
||||||
|
|
||||||
bootloader_options = [e.value for e in Bootloader if e != Bootloader.NO_BOOTLOADER or skip_boot is True]
|
bootloader_options = [e.value for e in cls if e != cls.NO_BOOTLOADER or skip_boot is True]
|
||||||
|
|
||||||
if bootloader not in bootloader_options:
|
if bootloader not in bootloader_options:
|
||||||
values = ', '.join(bootloader_options)
|
values = ', '.join(bootloader_options)
|
||||||
warn(f'Invalid bootloader value "{bootloader}". Allowed values: {values}')
|
warn(f'Invalid bootloader value "{bootloader}". Allowed values: {values}')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
return Bootloader(bootloader)
|
return cls(bootloader)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ class DiskLayoutConfiguration:
|
||||||
if not config_type:
|
if not config_type:
|
||||||
raise ValueError('Missing disk layout configuration: config_type')
|
raise ValueError('Missing disk layout configuration: config_type')
|
||||||
|
|
||||||
config = DiskLayoutConfiguration(
|
config = cls(
|
||||||
config_type=DiskLayoutType(config_type),
|
config_type=DiskLayoutType(config_type),
|
||||||
device_modifications=device_modifications,
|
device_modifications=device_modifications,
|
||||||
)
|
)
|
||||||
|
|
@ -294,7 +294,7 @@ class SectorSize:
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse_args(cls, arg: _SectorSizeSerialization) -> SectorSize:
|
def parse_args(cls, arg: _SectorSizeSerialization) -> SectorSize:
|
||||||
return SectorSize(
|
return cls(
|
||||||
arg['value'],
|
arg['value'],
|
||||||
Unit[arg['unit']],
|
Unit[arg['unit']],
|
||||||
)
|
)
|
||||||
|
|
@ -333,7 +333,7 @@ class Size:
|
||||||
def parse_args(cls, size_arg: _SizeSerialization) -> Size:
|
def parse_args(cls, size_arg: _SizeSerialization) -> Size:
|
||||||
sector_size = size_arg['sector_size']
|
sector_size = size_arg['sector_size']
|
||||||
|
|
||||||
return Size(
|
return cls(
|
||||||
size_arg['value'],
|
size_arg['value'],
|
||||||
Unit[size_arg['unit']],
|
Unit[size_arg['unit']],
|
||||||
SectorSize.parse_args(sector_size),
|
SectorSize.parse_args(sector_size),
|
||||||
|
|
@ -553,7 +553,7 @@ class _PartitionInfo:
|
||||||
SectorSize(partition.disk.device.sectorSize, Unit.B),
|
SectorSize(partition.disk.device.sectorSize, Unit.B),
|
||||||
)
|
)
|
||||||
|
|
||||||
return _PartitionInfo(
|
return cls(
|
||||||
partition=partition,
|
partition=partition,
|
||||||
name=partition.get_name(),
|
name=partition.get_name(),
|
||||||
type=partition_type,
|
type=partition_type,
|
||||||
|
|
@ -608,7 +608,7 @@ class _DeviceInfo:
|
||||||
sector_size = SectorSize(device.sectorSize, Unit.B)
|
sector_size = SectorSize(device.sectorSize, Unit.B)
|
||||||
free_space = [DeviceGeometry(g, sector_size) for g in disk.getFreeSpaceRegions()]
|
free_space = [DeviceGeometry(g, sector_size) for g in disk.getFreeSpaceRegions()]
|
||||||
|
|
||||||
return _DeviceInfo(
|
return cls(
|
||||||
model=device.model.strip(),
|
model=device.model.strip(),
|
||||||
path=Path(device.path),
|
path=Path(device.path),
|
||||||
type=device_type,
|
type=device_type,
|
||||||
|
|
@ -632,7 +632,7 @@ class SubvolumeModification:
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_existing_subvol_info(cls, info: _BtrfsSubvolumeInfo) -> SubvolumeModification:
|
def from_existing_subvol_info(cls, info: _BtrfsSubvolumeInfo) -> SubvolumeModification:
|
||||||
return SubvolumeModification(info.name, mountpoint=info.mountpoint)
|
return cls(info.name, mountpoint=info.mountpoint)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse_args(cls, subvol_args: list[_SubvolumeModificationSerialization]) -> list[SubvolumeModification]:
|
def parse_args(cls, subvol_args: list[_SubvolumeModificationSerialization]) -> list[SubvolumeModification]:
|
||||||
|
|
@ -644,7 +644,7 @@ class SubvolumeModification:
|
||||||
|
|
||||||
mountpoint = Path(entry['mountpoint']) if entry['mountpoint'] else None
|
mountpoint = Path(entry['mountpoint']) if entry['mountpoint'] else None
|
||||||
|
|
||||||
mods.append(SubvolumeModification(entry['name'], mountpoint))
|
mods.append(cls(entry['name'], mountpoint))
|
||||||
|
|
||||||
return mods
|
return mods
|
||||||
|
|
||||||
|
|
@ -723,10 +723,10 @@ class PartitionType(Enum):
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_type_from_code(cls, code: int) -> PartitionType:
|
def get_type_from_code(cls, code: int) -> PartitionType:
|
||||||
if code == parted.PARTITION_NORMAL:
|
if code == parted.PARTITION_NORMAL:
|
||||||
return PartitionType.Primary
|
return cls.Primary
|
||||||
else:
|
else:
|
||||||
debug(f'Partition code not supported: {code}')
|
debug(f'Partition code not supported: {code}')
|
||||||
return PartitionType._Unknown
|
return cls._Unknown
|
||||||
|
|
||||||
def get_partition_code(self) -> int | None:
|
def get_partition_code(self) -> int | None:
|
||||||
if self == PartitionType.Primary:
|
if self == PartitionType.Primary:
|
||||||
|
|
@ -923,7 +923,7 @@ class PartitionModification:
|
||||||
mountpoint = partition_info.mountpoints[0] if partition_info.mountpoints else None
|
mountpoint = partition_info.mountpoints[0] if partition_info.mountpoints else None
|
||||||
subvol_mods = []
|
subvol_mods = []
|
||||||
|
|
||||||
return PartitionModification(
|
return cls(
|
||||||
status=ModificationStatus.Exist,
|
status=ModificationStatus.Exist,
|
||||||
type=partition_info.type,
|
type=partition_info.type,
|
||||||
start=partition_info.start,
|
start=partition_info.start,
|
||||||
|
|
@ -1433,10 +1433,10 @@ class EncryptionType(Enum):
|
||||||
@classmethod
|
@classmethod
|
||||||
def _encryption_type_mapper(cls) -> dict[str, 'EncryptionType']:
|
def _encryption_type_mapper(cls) -> dict[str, 'EncryptionType']:
|
||||||
return {
|
return {
|
||||||
tr('No Encryption'): EncryptionType.NoEncryption,
|
tr('No Encryption'): cls.NoEncryption,
|
||||||
tr('LUKS'): EncryptionType.Luks,
|
tr('LUKS'): cls.Luks,
|
||||||
tr('LVM on LUKS'): EncryptionType.LvmOnLuks,
|
tr('LVM on LUKS'): cls.LvmOnLuks,
|
||||||
tr('LUKS on LVM'): EncryptionType.LuksOnLvm,
|
tr('LUKS on LVM'): cls.LuksOnLvm,
|
||||||
}
|
}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
@ -1539,7 +1539,7 @@ class DiskEncryption:
|
||||||
if vol.obj_id in disk_encryption.get('lvm_volumes', []):
|
if vol.obj_id in disk_encryption.get('lvm_volumes', []):
|
||||||
volumes.append(vol)
|
volumes.append(vol)
|
||||||
|
|
||||||
enc = DiskEncryption(
|
enc = cls(
|
||||||
EncryptionType(disk_encryption['encryption_type']),
|
EncryptionType(disk_encryption['encryption_type']),
|
||||||
password,
|
password,
|
||||||
enc_partitions,
|
enc_partitions,
|
||||||
|
|
@ -1583,7 +1583,7 @@ class Fido2Device:
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse_arg(cls, arg: _Fido2DeviceSerialization) -> 'Fido2Device':
|
def parse_arg(cls, arg: _Fido2DeviceSerialization) -> 'Fido2Device':
|
||||||
return Fido2Device(
|
return cls(
|
||||||
Path(arg['path']),
|
Path(arg['path']),
|
||||||
arg['manufacturer'],
|
arg['manufacturer'],
|
||||||
arg['product'],
|
arg['product'],
|
||||||
|
|
|
||||||
|
|
@ -195,7 +195,7 @@ class CustomRepository:
|
||||||
configs = []
|
configs = []
|
||||||
for arg in args:
|
for arg in args:
|
||||||
configs.append(
|
configs.append(
|
||||||
CustomRepository(
|
cls(
|
||||||
arg['name'],
|
arg['name'],
|
||||||
arg['url'],
|
arg['url'],
|
||||||
SignCheck(arg['sign_check']),
|
SignCheck(arg['sign_check']),
|
||||||
|
|
@ -221,7 +221,7 @@ class CustomServer:
|
||||||
configs = []
|
configs = []
|
||||||
for arg in args:
|
for arg in args:
|
||||||
configs.append(
|
configs.append(
|
||||||
CustomServer(arg['url']),
|
cls(arg['url']),
|
||||||
)
|
)
|
||||||
|
|
||||||
return configs
|
return configs
|
||||||
|
|
@ -305,7 +305,7 @@ class MirrorConfiguration:
|
||||||
args: dict[str, Any],
|
args: dict[str, Any],
|
||||||
backwards_compatible_repo: list[Repository] = [],
|
backwards_compatible_repo: list[Repository] = [],
|
||||||
) -> 'MirrorConfiguration':
|
) -> 'MirrorConfiguration':
|
||||||
config = MirrorConfiguration()
|
config = cls()
|
||||||
|
|
||||||
mirror_regions = args.get('mirror_regions', [])
|
mirror_regions = args.get('mirror_regions', [])
|
||||||
if mirror_regions:
|
if mirror_regions:
|
||||||
|
|
|
||||||
|
|
@ -254,7 +254,7 @@ class WifiConfiguredNetwork:
|
||||||
flags: list[str] = []
|
flags: list[str] = []
|
||||||
|
|
||||||
networks.append(
|
networks.append(
|
||||||
WifiConfiguredNetwork(
|
cls(
|
||||||
network_id=int(parts[0]),
|
network_id=int(parts[0]),
|
||||||
ssid=parts[1],
|
ssid=parts[1],
|
||||||
bssid=parts[2],
|
bssid=parts[2],
|
||||||
|
|
|
||||||
|
|
@ -166,7 +166,7 @@ class PackageGroup:
|
||||||
if len(group) == 0:
|
if len(group) == 0:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
pkg_groups.setdefault(group, PackageGroup(group))
|
pkg_groups.setdefault(group, cls(group))
|
||||||
pkg_groups[group].packages.append(pkg.name)
|
pkg_groups[group].packages.append(pkg.name)
|
||||||
|
|
||||||
return pkg_groups
|
return pkg_groups
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ class ProfileConfiguration:
|
||||||
greeter = arg.get('greeter', None)
|
greeter = arg.get('greeter', None)
|
||||||
gfx_driver = arg.get('gfx_driver', None)
|
gfx_driver = arg.get('gfx_driver', None)
|
||||||
|
|
||||||
return ProfileConfiguration(
|
return cls(
|
||||||
profile,
|
profile,
|
||||||
GfxDriver(gfx_driver) if gfx_driver else None,
|
GfxDriver(gfx_driver) if gfx_driver else None,
|
||||||
GreeterType(greeter) if greeter else None,
|
GreeterType(greeter) if greeter else None,
|
||||||
|
|
|
||||||
|
|
@ -59,45 +59,45 @@ class PasswordStrength(Enum):
|
||||||
if digit and upper and lower and symbol:
|
if digit and upper and lower and symbol:
|
||||||
match length:
|
match length:
|
||||||
case num if 13 <= num:
|
case num if 13 <= num:
|
||||||
return PasswordStrength.STRONG
|
return cls.STRONG
|
||||||
case num if 11 <= num <= 12:
|
case num if 11 <= num <= 12:
|
||||||
return PasswordStrength.MODERATE
|
return cls.MODERATE
|
||||||
case num if 7 <= num <= 10:
|
case num if 7 <= num <= 10:
|
||||||
return PasswordStrength.WEAK
|
return cls.WEAK
|
||||||
case num if num <= 6:
|
case num if num <= 6:
|
||||||
return PasswordStrength.VERY_WEAK
|
return cls.VERY_WEAK
|
||||||
elif digit and upper and lower:
|
elif digit and upper and lower:
|
||||||
match length:
|
match length:
|
||||||
case num if 14 <= num:
|
case num if 14 <= num:
|
||||||
return PasswordStrength.STRONG
|
return cls.STRONG
|
||||||
case num if 11 <= num <= 13:
|
case num if 11 <= num <= 13:
|
||||||
return PasswordStrength.MODERATE
|
return cls.MODERATE
|
||||||
case num if 7 <= num <= 10:
|
case num if 7 <= num <= 10:
|
||||||
return PasswordStrength.WEAK
|
return cls.WEAK
|
||||||
case num if num <= 6:
|
case num if num <= 6:
|
||||||
return PasswordStrength.VERY_WEAK
|
return cls.VERY_WEAK
|
||||||
elif upper and lower:
|
elif upper and lower:
|
||||||
match length:
|
match length:
|
||||||
case num if 15 <= num:
|
case num if 15 <= num:
|
||||||
return PasswordStrength.STRONG
|
return cls.STRONG
|
||||||
case num if 12 <= num <= 14:
|
case num if 12 <= num <= 14:
|
||||||
return PasswordStrength.MODERATE
|
return cls.MODERATE
|
||||||
case num if 7 <= num <= 11:
|
case num if 7 <= num <= 11:
|
||||||
return PasswordStrength.WEAK
|
return cls.WEAK
|
||||||
case num if num <= 6:
|
case num if num <= 6:
|
||||||
return PasswordStrength.VERY_WEAK
|
return cls.VERY_WEAK
|
||||||
elif lower or upper:
|
elif lower or upper:
|
||||||
match length:
|
match length:
|
||||||
case num if 18 <= num:
|
case num if 18 <= num:
|
||||||
return PasswordStrength.STRONG
|
return cls.STRONG
|
||||||
case num if 14 <= num <= 17:
|
case num if 14 <= num <= 17:
|
||||||
return PasswordStrength.MODERATE
|
return cls.MODERATE
|
||||||
case num if 9 <= num <= 13:
|
case num if 9 <= num <= 13:
|
||||||
return PasswordStrength.WEAK
|
return cls.WEAK
|
||||||
case num if num <= 8:
|
case num if num <= 8:
|
||||||
return PasswordStrength.VERY_WEAK
|
return cls.VERY_WEAK
|
||||||
|
|
||||||
return PasswordStrength.VERY_WEAK
|
return cls.VERY_WEAK
|
||||||
|
|
||||||
|
|
||||||
UserSerialization = TypedDict(
|
UserSerialization = TypedDict(
|
||||||
|
|
@ -204,7 +204,7 @@ class User:
|
||||||
if not username or password is None:
|
if not username or password is None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
user = User(
|
user = cls(
|
||||||
username=username,
|
username=username,
|
||||||
password=password,
|
password=password,
|
||||||
sudo=entry.get('sudo', False) is True,
|
sudo=entry.get('sudo', False) is True,
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ class FrameProperties:
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def max(cls, header: str) -> 'FrameProperties':
|
def max(cls, header: str) -> 'FrameProperties':
|
||||||
return FrameProperties(
|
return cls(
|
||||||
header,
|
header,
|
||||||
FrameStyle.MAX,
|
FrameStyle.MAX,
|
||||||
FrameStyle.MAX,
|
FrameStyle.MAX,
|
||||||
|
|
@ -84,7 +84,7 @@ class FrameProperties:
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def min(cls, header: str) -> 'FrameProperties':
|
def min(cls, header: str) -> 'FrameProperties':
|
||||||
return FrameProperties(
|
return cls(
|
||||||
header,
|
header,
|
||||||
FrameStyle.MIN,
|
FrameStyle.MIN,
|
||||||
FrameStyle.MIN,
|
FrameStyle.MIN,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue