From e0c85eafc56cf5a10e872ad0cc7bf3ce8cb654ea Mon Sep 17 00:00:00 2001 From: Kaurin <2141359+Kaurin@users.noreply.github.com> Date: Sat, 11 Nov 2023 13:43:04 +0000 Subject: [PATCH] Hinting and proper logging --- rs_Assets.py | 14 ++++++-------- rs_util_archive.py | 8 +++++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/rs_Assets.py b/rs_Assets.py index f587725..d2acee7 100644 --- a/rs_Assets.py +++ b/rs_Assets.py @@ -95,7 +95,7 @@ def __iter__(self) -> Dict[str, Any]: else: yield "_children", self._children - def add_child_from_config_item(self, config_item, parent) -> "LiveryAsset": + def add_child_from_config_item(self, config_item: Dict[str, Any], parent: "LiveryAsset") -> "LiveryAsset": config_item_copy = config_item.copy() # When adding a child, we want to ensure we pass down the # "must_contain_strings" and "must_not_contain_strings" attributes. @@ -140,7 +140,7 @@ def _download_asset(self) -> "LiveryAsset": def _update_size(self) -> None: self._size_in_bytes = single_dir_size(self._dl_dir) - def _update_asset_items(self): + def _update_asset_items(self) -> None: asset_items = set() entrypoint = self._dl_dir if self.asset_type == "roughmets": @@ -182,7 +182,7 @@ def _compress_and_checksum(self) -> Future: return future @classmethod - def from_config_item(cls, config_item: Dict[str, str]) -> "LiveryAsset": + def from_config_item(cls, config_item: Dict[str, Any]) -> "LiveryAsset": try: basename = config_item["basename"] except KeyError: @@ -249,7 +249,6 @@ def from_config_item(cls, config_item: Dict[str, str]) -> "LiveryAsset": "If 'asset_type' is not set, you must provide 'category_name'" f"\nYou provided: {config_item}" ) - new_instance = cls( basename=basename, gdrive_id=gdrive_id, @@ -269,9 +268,8 @@ def from_config_item(cls, config_item: Dict[str, str]) -> "LiveryAsset": return new_instance - @staticmethod - def _remove_all_readme_files(directory) -> None: - for root, dirs, files in os_walk(directory): + def _remove_all_readme_files(self) -> None: + for root, dirs, files in os_walk(self._dl_dir): for name in files: if fnmatch(name.lower(), "readme*.txt"): # Remove readmes LOGGER.info(f"Removing {os_join(root, name)}") @@ -379,7 +377,7 @@ def _from_config_file(self, asset_config_file: str) -> List["LiveryAsset"]: if asset._dl_future is not None: for nested_future in asset._dl_future.result(): nested_future.result() - asset._remove_all_readme_files(asset._dl_dir) + asset._remove_all_readme_files() asset._update_asset_items() asset._update_size() compress_and_checksum_futures.append(asset._compress_and_checksum()) diff --git a/rs_util_archive.py b/rs_util_archive.py index 9375e33..a810c25 100644 --- a/rs_util_archive.py +++ b/rs_util_archive.py @@ -48,11 +48,13 @@ def calculate_and_write_checksum(destination_dir: str, input_7z_file: str) -> No check=True, text=False, ) + if z_subprocess.stderr: + LOGGER.error(f"7z error: {z_subprocess.stderr}") chksum = sha256(z_subprocess.stdout).hexdigest() dest_chksumfile = os_join( destination_dir, PurePath(input_7z_file).stem + ".sha256sum" ) - LOGGER(f"Checksum: '{chksum}' -> '{dest_chksumfile}'") + LOGGER.info(f"Checksum: '{chksum}' -> '{dest_chksumfile}'") Path(Path(dest_chksumfile).resolve().parents[0]).mkdir(parents=True, exist_ok=True) with open(dest_chksumfile, "w", encoding=getpreferredencoding()) as file_final: file_final.write(chksum) @@ -72,7 +74,7 @@ def sevenz_and_checksum_archive( appended_files_and_or_dirs = [] for file in files_and_or_dirs: appended_files_and_or_dirs.append(os_join(entrypoint, file)) - LOGGER(f"Compressing: {destination_file}") + LOGGER.info(f"Compressing: {destination_file}") sp_run( sevenz_exec + [destination_file] + appended_files_and_or_dirs, capture_output=False, @@ -81,7 +83,7 @@ def sevenz_and_checksum_archive( if DELETE_AFTER_COMPRESS: for target in appended_files_and_or_dirs: - LOGGER(f"Removing: {target}") + LOGGER.info(f"Removing: {target}") my_file = Path(target) if my_file.is_dir(): rmtree(target)