Add deleted files to summary

This commit is contained in:
Daniel Augustin 2020-06-25 21:30:03 +02:00
parent f6fbd5e4bb
commit 6c034209b6
No known key found for this signature in database
GPG Key ID: E05C0457D89D41F5
3 changed files with 22 additions and 3 deletions

View File

@ -111,6 +111,15 @@ class PrettyLogger:
f"[bold green]Created {self._format_path(path)}.[/bold green]" f"[bold green]Created {self._format_path(path)}.[/bold green]"
) )
def deleted_file(self, path: PathLike) -> None:
"""
A file has been deleted.
"""
self.logger.info(
f"[bold red]Deleted {self._format_path(path)}.[/bold red]"
)
def ignored_file(self, path: PathLike, reason: str) -> None: def ignored_file(self, path: PathLike, reason: str) -> None:
""" """
File was not downloaded or modified. File was not downloaded or modified.

View File

@ -26,6 +26,7 @@ class Organizer(Location):
new_files = [] new_files = []
modified_files = [] modified_files = []
deleted_files = []
def __init__(self, path: Path): def __init__(self, path: Path):
"""Create a new organizer for a given path.""" """Create a new organizer for a given path."""
@ -122,9 +123,9 @@ class Organizer(Location):
if start_dir.resolve() not in self._known_files and dir_empty: if start_dir.resolve() not in self._known_files and dir_empty:
start_dir.rmdir() start_dir.rmdir()
@staticmethod def _delete_file_if_confirmed(self, path: Path) -> None:
def _delete_file_if_confirmed(path: Path) -> None:
prompt = f"Do you want to delete {path}" prompt = f"Do you want to delete {path}"
if prompt_yes_no(prompt, False): if prompt_yes_no(prompt, False):
self.deleted_files.append(path)
path.unlink() path.unlink()

View File

@ -36,6 +36,7 @@ class Pferd(Location):
new_files = [] new_files = []
modified_files = [] modified_files = []
deleted_files = []
def __init__( def __init__(
self, self,
@ -157,13 +158,14 @@ class Pferd(Location):
self.new_files += organizer.new_files self.new_files += organizer.new_files
self.modified_files += organizer.modified_files self.modified_files += organizer.modified_files
self.deleted_files += organizer.deleted_files
return organizer return organizer
def print_summary(self): def print_summary(self):
LOGGER.info("") LOGGER.info("")
LOGGER.info("Summary: ") LOGGER.info("Summary: ")
if len(self.new_files) == 0 and len(self.modified_files) == 0: if len(self.new_files) == 0 and len(self.modified_files) == 0 and len(self.deleted_files) == 0:
LOGGER.info("Nothing changed") LOGGER.info("Nothing changed")
if len(self.new_files) > 0: if len(self.new_files) > 0:
@ -180,6 +182,13 @@ class Pferd(Location):
LOGGER.info("") LOGGER.info("")
if len(self.deleted_files) > 0:
LOGGER.info("Deleted Files:")
for file in self.deleted_files:
PRETTY.deleted_file(file)
LOGGER.info("")
@swallow_and_print_errors @swallow_and_print_errors
def ilias_kit_personal_desktop( def ilias_kit_personal_desktop(
self, self,