armbian-next: patching: less horrible patching log, pt 37

- don't show stats for patches that are bind applied blind (failed to parse/autogen)
- don't show Author, it's too long
- don't dump Python exceptions in log
- extra: expand Python imports
This commit is contained in:
Ricardo Pardini
2023-01-19 00:26:34 +01:00
parent 8cedc82ec2
commit 861b07305e
2 changed files with 19 additions and 14 deletions

View File

@@ -290,8 +290,10 @@ class PatchInPatchFile:
return downgrade_to_ascii(remove_quotes(m.group("name"))), remove_quotes(m.group("email"))
def one_line_patch_stats(self) -> str:
files_desc = ", ".join(self.patched_file_stats_dict)
return f"{self.text_diffstats()} {{{files_desc}}}"
if (not self.failed_to_parse) and (not self.parent.patch_dir.is_autogen_dir):
files_desc = ", ".join(self.patched_file_stats_dict)
return f"{self.text_diffstats()} {{{files_desc}}}"
return ""
def text_diffstats(self) -> str:
operations: list[str] = []
@@ -315,8 +317,7 @@ class PatchInPatchFile:
except Exception as e:
self.problems.append("invalid_diff")
self.failed_to_parse = True
log.error(
f"Failed to parse unidiff for file {self.parent.full_file_path()}(:{self.counter}): {str(e).strip()}")
log.warning(f"Failed to parse unidiff for file {self.parent.full_file_path()}(:{self.counter}): '{str(e).strip()}'")
return # no point in continuing; the patch is invalid; might be recovered during apply
self.total_additions = 0
@@ -359,11 +360,12 @@ class PatchInPatchFile:
return self.str_oneline_around("->", "<-")
def str_oneline_around(self, prefix, suffix):
extra_email = f"{self.from_email}" if self.from_email is not None else ""
extra_subject = f":'{self.subject}'" if self.subject is not None else ""
# extra_email = f"{self.from_email}" if self.from_email is not None else ""
# extra_subject = f":'{self.subject}'" if self.subject is not None else ""
# extra_author = f":{extra_email}{extra_subject}"
desc: str = \
f"{prefix}{self.parent.relative_dirs_and_base_file_name}(:{self.counter}):" + \
f"{self.one_line_patch_stats()}:{extra_email}{extra_subject}{suffix}"
f"{prefix}{self.parent.relative_dirs_and_base_file_name}(:{self.counter}) " + \
f"{self.one_line_patch_stats()}{suffix}"
return desc
def apply_patch(self, working_dir: str, options: dict[str, bool]):
@@ -438,8 +440,7 @@ class PatchInPatchFile:
stdout_output = "\n".join([f"STDOUT: {line}" for line in stdout_output.splitlines()])
stdout_output = "\n" + stdout_output if stdout_output != "" else stdout_output
self.problems.append("failed_apply")
raise Exception(
f"Failed to apply patch {self.parent.full_file_path()}:{stderr_output}{stdout_output}")
raise Exception(f"Failed to apply patch {self.parent.full_file_path()}:{stderr_output}{stdout_output}")
def commit_changes_to_git(self, repo: git.Repo, add_rebase_tags: bool, split_patches: bool):
log.info(f"Committing changes to git: {self.parent.relative_dirs_and_base_file_name}")

View File

@@ -3,11 +3,15 @@ import logging
import os
# Let's use GitPython to query and manipulate the git repo
from git import Repo, GitCmdObjectDB, InvalidGitRepositoryError, Actor
from git import Actor
from git import GitCmdObjectDB
from git import InvalidGitRepositoryError
from git import Repo
import common.armbian_utils as armbian_utils
import common.patching_utils as patching_utils
from common.md_asset_log import SummarizedMarkdownWriter, get_gh_pages_workflow_script
from common.md_asset_log import SummarizedMarkdownWriter
from common.md_asset_log import get_gh_pages_workflow_script
# Prepare logging
armbian_utils.setup_logging()
@@ -154,7 +158,7 @@ for patch_file_in_dir in ALL_PATCH_FILES_SORTED:
log.critical(
f"Failed to read patch file {patch_file_in_dir.file_name}: {e}\n"
f"Can't continue; please fix the patch file {patch_file_in_dir.full_file_path()} manually. Sorry."
, exc_info=True)
)
if has_critical_split_errors:
raise Exception("Critical errors found while splitting patches. Please fix the patch files manually.")
@@ -241,7 +245,7 @@ if apply_patches:
one_patch.apply_patch(GIT_WORK_DIR, apply_options)
one_patch.applied_ok = True
except Exception as e:
log.error(f"Problem with {one_patch}: {e}", exc_info=True)
log.error(f"Problem with {one_patch}: {e}")
if one_patch.applied_ok and apply_patches_to_git:
committed = one_patch.commit_changes_to_git(git_repo, (not rewrite_patches_in_place), split_patches)