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