Skip to content

Commit d87879a

Browse files
committed
don't include build function output in profile, improve dm autodetection
Signed-off-by: Zen <[email protected]>
1 parent 93bc374 commit d87879a

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

src/ugrd/fs/mounts.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__author__ = 'desultory'
2-
__version__ = '4.16.2'
2+
__version__ = '4.16.3'
33

44
from pathlib import Path
55
from zenlib.util import contains, pretty_print
@@ -205,7 +205,7 @@ def get_mounts_info(self) -> None:
205205

206206

207207
@contains('hostonly', "Skipping blkid autodetection, hostonly mode is enabled.", log_level=30)
208-
def get_blkid_info(self, device=None) -> str:
208+
def get_blkid_info(self, device=None) -> dict:
209209
"""
210210
Gets the blkid info for all devices if no device is passed.
211211
Gets the blkid info for the passed device if a device is passed.
@@ -233,6 +233,7 @@ def get_blkid_info(self, device=None) -> str:
233233
raise ValueError("[%s] Failed to parse blkid info: %s" % (device, info))
234234

235235
self.logger.debug("Blkid info: %s" % pretty_print(self['_blkid_info']))
236+
return self['_blkid_info'][device] if device else self['_blkid_info']
236237

237238

238239
@contains('init_target', 'init_target must be set', raise_exception=True)
@@ -327,11 +328,17 @@ def _autodetect_dm(self, mountpoint, device=None) -> None:
327328
self.logger.debug("Mount is not a device mapper mount: %s" % source_device)
328329
return
329330

331+
device_name = source_device.split('/')[-1]
330332
if source_device not in self['_blkid_info']:
331-
device_name = source_device.split('/')[-1]
332-
mapped_device = f'/dev/mapper/{device_name}'
333-
if mapped_device not in self['_blkid_info']:
334-
raise FileNotFoundError("[%s] No blkid info for virtual device: %s" % (mountpoint, device_name))
333+
if device_name in self['_dm_info']:
334+
if f'/dev/{device_name}' in self['_blkid_info']:
335+
source_device = f'/dev/{device_name}'
336+
elif f'/dev/mapper/{device_name}' in self['_blkid_info']:
337+
source_device = f'/dev/mapper/{device_name}'
338+
elif not get_blkid_info(self, source_device):
339+
raise FileNotFoundError("[%s] No blkid info for virtual device: %s" % (mountpoint, source_device))
340+
else:
341+
raise ValueError("[%s] No blkid info for virtual device: %s" % (mountpoint, source_device))
335342

336343
self.logger.info("[%s] Detected virtual block device: %s" % (mountpoint, source_device))
337344
source_device = Path(source_device)

src/ugrd/initramfs_generator.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ def build(self) -> None:
7575
self.logger.info("Building initramfs")
7676
for hook in self.build_tasks:
7777
self.logger.debug("Running build hook: %s" % hook)
78-
self.run_hook(hook)
78+
self.run_hook(hook, force_exclude=True)
7979
self.generate_init()
8080
self.run_hook('build_final')
8181
self.pack_build()
8282
self.run_checks()
8383
self.run_tests()
8484

85-
def run_func(self, function, force_include=False) -> list[str]:
85+
def run_func(self, function, force_include=False, force_exclude=False) -> list[str]:
8686
""" Runs a function, If force_include is set, forces the function to be included in the bash source file. """
8787
self.logger.log(self['_build_log_level'], "Running function: %s" % function.__name__)
8888

@@ -102,9 +102,12 @@ def run_func(self, function, force_include=False) -> list[str]:
102102
self.logger.debug("[%s] Function returned string: %s" % (function.__name__, function_output))
103103
return function_output
104104

105-
self.logger.debug("[%s] Function returned output: %s" % (function.__name__, pretty_print(function_output)))
106-
self.included_functions[function.__name__] = function_output
107-
self.logger.debug("Created function alias: %s" % function.__name__)
105+
if not force_exclude:
106+
self.logger.debug("[%s] Function returned output: %s" % (function.__name__, pretty_print(function_output)))
107+
self.included_functions[function.__name__] = function_output
108+
self.logger.debug("Created function alias: %s" % function.__name__)
109+
elif function_output:
110+
self.logger.debug("[%s] Function output was not included: %s" % (function.__name__, function_output))
108111
return function.__name__
109112
else:
110113
self.logger.debug("[%s] Function returned no output" % function.__name__)
@@ -151,7 +154,7 @@ def generate_profile(self) -> None:
151154
for line in func_content:
152155
out.append(f" {line}")
153156
else:
154-
raise TypeError("Function content is not a string or list: %s" % func_content)
157+
raise TypeError("[%s] Function content is not a string or list: %s" % (func_name, func_content))
155158
out.append("}")
156159

157160
return out

0 commit comments

Comments
 (0)