Skip to content

Commit a344404

Browse files
committed
improve comments, control flow
Signed-off-by: Zen <[email protected]>
1 parent f7a510f commit a344404

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

src/ugrd/initramfs_generator.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,8 @@ def __getattr__(self, item):
7070
return super().__getattr__(item)
7171

7272
def build(self) -> None:
73-
""" Builds the initramfs. """
74-
self.logger.info("Building initramfs")
75-
for hook in self.build_tasks:
76-
self.logger.debug("Running build hook: %s" % hook)
77-
self.run_hook(hook, force_exclude=True)
73+
""" Builds the initramfs image. """
74+
self.run_build()
7875
self.config_dict.validate()
7976

8077
self.generate_init()
@@ -83,7 +80,11 @@ def build(self) -> None:
8380
self.run_tests()
8481

8582
def run_func(self, function, force_include=False, force_exclude=False) -> list[str]:
86-
""" Runs a function, If force_include is set, forces the function to be included in the bash source file. """
83+
"""
84+
Runs an imported function.
85+
If force_include is set, forces the function to be included in the bash source file.
86+
if force_exclude is set, does not include the output of the function in the bash source file.
87+
"""
8788
self.logger.log(self['_build_log_level'], "Running function: %s" % function.__name__)
8889

8990
if function_output := function(self):
@@ -124,16 +125,6 @@ def run_hook(self, hook: str, *args, **kwargs) -> list[str]:
124125
out.append(function_output)
125126
return out
126127

127-
def run_init_hook(self, level: str) -> list[str]:
128-
""" Runs the specified init hook, returning the output. """
129-
if runlevel := self.run_hook(level):
130-
out = ['\n# Begin %s' % level]
131-
out += runlevel
132-
return out
133-
else:
134-
self.logger.debug("No output for init level: %s" % level)
135-
return []
136-
137128
def generate_profile(self) -> list[str]:
138129
""" Generates the bash profile file based on self.included_functions. """
139130
from importlib.metadata import version
@@ -208,13 +199,29 @@ def generate_init(self) -> None:
208199
self._write('init', init, 0o755)
209200
self.logger.debug("Final config:\n%s" % self)
210201

202+
def run_build(self) -> None:
203+
""" Runs all build tasks. """
204+
for task in self.build_tasks:
205+
self.logger.debug("Running build task: %s" % task)
206+
self.run_hook(task, force_exclude=True)
207+
211208
def pack_build(self) -> None:
212209
""" Packs the initramfs based on self['imports']['pack']."""
213210
if self['imports'].get('pack'):
214211
self.run_hook('pack')
215212
else:
216213
self.logger.warning("No pack functions specified, the final build is present in: %s" % self.build_dir)
217214

215+
def run_init_hook(self, level: str) -> list[str]:
216+
""" Runs the specified init hook, returning the output. """
217+
if runlevel := self.run_hook(level):
218+
out = ['\n# Begin %s' % level]
219+
out += runlevel
220+
return out
221+
else:
222+
self.logger.debug("No output for init level: %s" % level)
223+
return []
224+
218225
def run_checks(self) -> None:
219226
""" Runs checks if defined in self['imports']['checks']. """
220227
if check_output := self.run_hook('checks'):

0 commit comments

Comments
 (0)