Skip to content

Commit

Permalink
Merge pull request #213 from desultory/dev
Browse files Browse the repository at this point in the history
improve build logging
  • Loading branch information
desultory authored Feb 9, 2025
2 parents b079b97 + 000a0f5 commit 0a829eb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/ugrd/base/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,12 +427,15 @@ def _process_gz_dependencies_multi(self, dependency: Union[Path, str]) -> None:
def _process_build_logging(self, log_build: bool) -> None:
"""Sets the build log flag."""
build_log_level = self.get("_build_log_level", 10)
if log_build == self["build_logging"]:
# Don't re-run the setup procedure as it will bump the log level again when args are re-processed
return self.logger.debug("Build logging is already set to: %s" % log_build)
if log_build:
self["_build_log_level"] = max(build_log_level + 10, 20)
else:
if self["_build_log_level"] > 10:
self.logger.warning("Resetting _build_log_level to 10, as build logging is disabled.")
self["_build_log_level"] = 10
self["_build_log_level"] = 10
self.data["build_logging"] = log_build


Expand Down
12 changes: 8 additions & 4 deletions src/ugrd/generator_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from zenlib.util import colorize, pretty_print

__version__ = "1.6.2"
__version__ = "1.6.3"
__author__ = "desultory"


Expand Down Expand Up @@ -71,7 +71,7 @@ def _mkdir(self, path: Path, resolve_build=True) -> None:

if not path_dir.is_dir():
path_dir.mkdir()
self.logger.log(self["_build_log_level"], "Created directory: %s" % path)
self.logger.log(self["_build_log_level"], "Created directory: %s" % colorize(path, "green"))
else:
self.logger.debug("Directory already exists: %s" % path_dir)

Expand Down Expand Up @@ -156,7 +156,9 @@ def _copy(self, source: Union[Path, str], dest=None) -> None:
except ValueError as e:
raise RuntimeError("Destination path is not within the build directory: %s" % dest_path) from e

self.logger.log(self["_build_log_level"], "Copying '%s' to '%s'" % (source, dest_path))
self.logger.log(
self["_build_log_level"], "Copying '%s' to '%s'" % (colorize(source, "blue"), colorize(dest_path, "green"))
)
copy2(source, dest_path)

def _symlink(self, source: Union[Path, str], target: Union[Path, str]) -> None:
Expand Down Expand Up @@ -200,7 +202,9 @@ def _symlink(self, source: Union[Path, str], target: Union[Path, str]) -> None:
if target.relative_to(self._get_build_path("/")) == source:
return self.logger.debug("Cannot symlink to self: %s -> %s" % (target, source))

self.logger.debug("Creating symlink: %s -> %s" % (target, source))
self.logger.log(
self["_build_log_level"], "Creating symlink: %s -> %s" % (colorize(target, "green"), colorize(source, "blue"))
)
target.symlink_to(source)

def _run(self, args: list[str], timeout=None, fail_silent=False, fail_hard=True) -> CompletedProcess:
Expand Down
4 changes: 3 additions & 1 deletion src/ugrd/initramfs_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ def run_func(self, function, force_include=False, force_exclude=False) -> list[s
If force_include is set, forces the function to be included in the shell profile.
if force_exclude is set, does not include the output of the function in the shell profile.
"""
self.logger.log(self["_build_log_level"], "Running function: %s" % function.__name__)
self.logger.log(
self["_build_log_level"], "Running function: %s" % colorize(function.__name__, "blue", bold=True)
)

if function_output := function(self):
if isinstance(function_output, list) and len(function_output) == 1:
Expand Down

0 comments on commit 0a829eb

Please sign in to comment.