patching: emit warnings when files in dt folder overwrite pre-existing files (DTs that landed upstream)

- it's more and more common that the (bare) DT files in our `dt` folders have landed upstream
- this adds warnings and marks the patching table red when some bare-dt file overwrites what's already in git
- without this it's very easy to forget them there during bumps
This commit is contained in:
Ricardo Pardini
2024-09-17 12:51:25 +02:00
committed by Igor
parent 1ac3f7ca2b
commit 5396ffb602

View File

@@ -42,12 +42,18 @@ class AutomaticPatchDescription:
self.name = "Not initted name" self.name = "Not initted name"
self.description = "Not initted desc" self.description = "Not initted desc"
self.files = [] self.files = []
self.overwrites = []
def rich_name_status(self): def rich_name_status(self):
if len(self.overwrites) > 0:
return f"[bold][red]{self.name}"
return f"[bold][blue]{self.name}" return f"[bold][blue]{self.name}"
def rich_diffstats(self): def rich_diffstats(self):
files_bare = [] files_bare = []
# Always list all overwrites.
for one_file in self.overwrites:
files_bare.append(f"[OVERWRITTEN]{os.path.basename(one_file)}")
max_files_to_show = 15 # show max 15 max_files_to_show = 15 # show max 15
for one_file in self.files[:max_files_to_show]: for one_file in self.files[:max_files_to_show]:
files_bare.append(os.path.basename(one_file)) files_bare.append(os.path.basename(one_file))
@@ -231,9 +237,14 @@ def copy_bare_files(autopatcher_params: AutoPatcherParams, type: str) -> list[Au
all_files_to_copy_dict[base_filename] = one_file all_files_to_copy_dict[base_filename] = one_file
# do the actual copy # do the actual copy
all_copied_files = [] all_copied_files = []
overwritten_files = []
for one_file in all_files_to_copy_dict: for one_file in all_files_to_copy_dict:
log.debug(f"Copy '{one_file}' (from {all_files_to_copy_dict[one_file]}) to '{full_path_target_dir}'...") log.debug(f"Copy '{one_file}' (from {all_files_to_copy_dict[one_file]}) to '{full_path_target_dir}'...")
full_path_target_file = os.path.join(full_path_target_dir, one_file) full_path_target_file = os.path.join(full_path_target_dir, one_file)
# If the target already exists, emit a warning; DTs land upstream all the time and we might forget to remove them from our 'dt' directory
if os.path.exists(full_path_target_file):
overwritten_files.append(full_path_target_file)
log.warning(f"Target file '{one_file}' already exists; will overwrite it; consider if it should be removed.")
shutil.copyfile(all_files_to_copy_dict[one_file], full_path_target_file) shutil.copyfile(all_files_to_copy_dict[one_file], full_path_target_file)
all_copied_files.append(full_path_target_file) all_copied_files.append(full_path_target_file)
if type == "dt": if type == "dt":
@@ -246,7 +257,12 @@ def copy_bare_files(autopatcher_params: AutoPatcherParams, type: str) -> list[Au
desc = AutomaticPatchDescription() desc = AutomaticPatchDescription()
desc.name = f"Armbian Bare {type.upper()} auto-patch" desc.name = f"Armbian Bare {type.upper()} auto-patch"
desc.description = f"Armbian Bare {type.upper()} files for {target_dir}" desc.description = f"Armbian Bare {type.upper()} files for {target_dir}"
# if overwritten files, add to description and name
if len(overwritten_files) > 0:
desc.description += f" (overwriting {len(overwritten_files)} files)"
desc.name += f" (overwriting {len(overwritten_files)} files)"
desc.files = all_copied_files desc.files = all_copied_files
desc.overwrites = overwritten_files
ret_desc_list.append(desc) ret_desc_list.append(desc)
if autopatcher_params.apply_patches_to_git and len(all_copied_files) > 0: if autopatcher_params.apply_patches_to_git and len(all_copied_files) > 0: