Skip to content

Commit

Permalink
Hinting and proper logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaurin committed Nov 11, 2023
1 parent 2673def commit e0c85ea
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
14 changes: 6 additions & 8 deletions rs_Assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand All @@ -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)}")
Expand Down Expand Up @@ -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())
Expand Down
8 changes: 5 additions & 3 deletions rs_util_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand All @@ -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)
Expand Down

0 comments on commit e0c85ea

Please sign in to comment.