summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--meson.build12
-rwxr-xr-xsrc/ukify/ukify.py39
2 files changed, 24 insertions, 27 deletions
diff --git a/meson.build b/meson.build
index 965b237d23..d37f47d48b 100644
--- a/meson.build
+++ b/meson.build
@@ -1976,13 +1976,13 @@ if run_command(python, '-c', 'import jinja2', check : false).returncode() != 0
error('python3 jinja2 missing')
endif
-python_310 = run_command(python, '-c',
- 'import sys; sys.exit(0 if sys.version_info >= (3,10) else 1)',
- check : false).returncode() == 0
+python_39 = run_command(python, '-c',
+ 'import sys; sys.exit(0 if sys.version_info >= (3,9) else 1)',
+ check : false).returncode() == 0
if get_option('ukify') == 'auto'
- want_ukify = python_310 and conf.get('HAVE_GNU_EFI') == 1
-elif get_option('ukify') == 'true' and (not python310 or conf.get('HAVE_GNU_EFI') != 1)
- error('ukify requires Python >= 3.10 and GNU EFI')
+ want_ukify = python_39 and conf.get('HAVE_GNU_EFI') == 1
+elif get_option('ukify') == 'true' and (not python_39 or conf.get('HAVE_GNU_EFI') != 1)
+ error('ukify requires Python >= 3.9 and GNU EFI')
else
want_ukify = get_option('ukify') == 'true'
endif
diff --git a/src/ukify/ukify.py b/src/ukify/ukify.py
index 6f177bc5b7..b00b9fd900 100755
--- a/src/ukify/ukify.py
+++ b/src/ukify/ukify.py
@@ -65,7 +65,7 @@ def shell_join(cmd):
return ' '.join(shlex.quote(str(x)) for x in cmd)
-def path_is_readable(s: str | None) -> pathlib.Path | None:
+def path_is_readable(s: typing.Optional[str]) -> typing.Optional[pathlib.Path]:
"""Convert a filename string to a Path and verify access."""
if s is None:
return None
@@ -215,14 +215,14 @@ class Uname:
class Section:
name: str
content: pathlib.Path
- tmpfile: typing.IO | None = None
+ tmpfile: typing.Optional[typing.IO] = None
flags: list[str] = dataclasses.field(default_factory=lambda: ['data', 'readonly'])
- offset: int | None = None
+ offset: typing.Optional[int] = None
measure: bool = False
@classmethod
def create(cls, name, contents, **kwargs):
- if isinstance(contents, str | bytes):
+ if isinstance(contents, (str, bytes)):
mode = 'wt' if isinstance(contents, str) else 'wb'
tmp = tempfile.NamedTemporaryFile(mode=mode, prefix=f'tmp{name}')
tmp.write(contents)
@@ -261,9 +261,9 @@ class Section:
@dataclasses.dataclass
class UKI:
- executable: list[pathlib.Path|str]
+ executable: list[typing.Union[pathlib.Path, str]]
sections: list[Section] = dataclasses.field(default_factory=list, init=False)
- offset: int | None = dataclasses.field(default=None, init=False)
+ offset: typing.Optional[int] = dataclasses.field(default=None, init=False)
def __post_init__(self):
self.offset = round_up(pe_next_section_offset(self.executable))
@@ -426,21 +426,18 @@ def call_systemd_measure(uki, linux, opts):
def join_initrds(initrds):
- match initrds:
- case []:
- return None
- case [initrd]:
- return initrd
- case multiple:
- seq = []
- for file in multiple:
- initrd = file.read_bytes()
- padding = b'\0' * round_up(len(initrd), 4) # pad to 32 bit alignment
- seq += [initrd, padding]
-
- return b''.join(seq)
-
- assert False
+ if len(initrds) == 0:
+ return None
+ elif len(initrds) == 1:
+ return initrds[0]
+
+ seq = []
+ for file in initrds:
+ initrd = file.read_bytes()
+ padding = b'\0' * round_up(len(initrd), 4) # pad to 32 bit alignment
+ seq += [initrd, padding]
+
+ return b''.join(seq)
def pe_validate(filename):