Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib/models/bootloader.py
blob: e21cda33ed2763f913bf5e04f7692498b66f0157 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from __future__ import annotations

import sys
from enum import Enum
from typing import List

from ..hardware import SysInfo
from ..output import warn


class Bootloader(Enum):
	Systemd = 'Systemd-boot'
	Grub = 'Grub'
	Efistub = 'Efistub'

	def json(self):
		return self.value

	@classmethod
	def values(cls) -> List[str]:
		return [e.value for e in cls]

	@classmethod
	def get_default(cls) -> Bootloader:
		if SysInfo.has_uefi():
			return Bootloader.Systemd
		else:
			return Bootloader.Grub

	@classmethod
	def from_arg(cls, bootloader: str) -> Bootloader:
		# to support old configuration files
		bootloader = bootloader.capitalize()

		if bootloader not in cls.values():
			values = ', '.join(cls.values())
			warn(f'Invalid bootloader value "{bootloader}". Allowed values: {values}')
			sys.exit(1)
		return Bootloader(bootloader)