Satisfy pylint

This commit is contained in:
I-Al-Istannen 2020-06-26 15:37:35 +02:00
parent 402ae81335
commit e4b1fac045
2 changed files with 50 additions and 25 deletions

View File

@ -1,54 +1,79 @@
from typing import List """
Provides a summary that keeps track of new modified or deleted files.
"""
import logging import logging
from pathlib import Path from pathlib import Path
from typing import List
from .logging import PrettyLogger from .logging import PrettyLogger
class DownloadSummary: class DownloadSummary:
"""
Keeps track of all new, modified or deleted files and provides a summary.
"""
def __init__(self) -> None: def __init__(self) -> None:
self._new_files: List[Path] = [] self._new_files: List[Path] = []
self._changed_files: List[Path] = [] self._modified_files: List[Path] = []
self._deleted_files: List[Path] = [] self._deleted_files: List[Path] = []
def merge(self, summary: 'DownloadSummary') -> None: def merge(self, summary: 'DownloadSummary') -> None:
"""
Merges ourselves with the passed summary. Modifies this object, but not the passed one.
"""
# This is our own class!
# pylint: disable=protected-access
self._new_files += summary._new_files self._new_files += summary._new_files
self._changed_files += summary._changed_files self._modified_files += summary._modified_files
self._deleted_files += summary._deleted_files self._deleted_files += summary._deleted_files
def add_deleted_file(self, path: Path) -> None: def add_deleted_file(self, path: Path) -> None:
"""
Registers a file as deleted.
"""
self._deleted_files.append(path) self._deleted_files.append(path)
def add_changed_file(self, path: Path) -> None: def add_modified_file(self, path: Path) -> None:
self._changed_files.append(path) """
Registers a file as changed.
"""
self._modified_files.append(path)
def add_new_file(self, path: Path) -> None: def add_new_file(self, path: Path) -> None:
"""
Registers a file as new.
"""
self._new_files.append(path) self._new_files.append(path)
def _has_no_updates(self) -> bool: def _has_updates(self) -> bool:
return len(self._new_files) == 0 and len(self._changed_files) == 0 and len(self._deleted_files) == 0 return bool(self._new_files or self._modified_files or self._deleted_files)
def print(self, logger: logging.Logger, pretty: PrettyLogger) -> None: def print(self, logger: logging.Logger, pretty: PrettyLogger) -> None:
"""
Prints this summary.
"""
logger.info("") logger.info("")
logger.info("Summary: ") logger.info("Summary: ")
if self._has_no_updates(): if not self._has_updates():
logger.info("nothing changed") logger.info("Nothing changed!")
else: return
if len(self._new_files) > 0:
if self._new_files:
logger.info("New Files:") logger.info("New Files:")
for file in self._new_files: for file in self._new_files:
pretty.new_file(file) pretty.new_file(file)
logger.info("") logger.info("")
if len(self._changed_files) > 0: if self._modified_files:
logger.info("Modified Files:") logger.info("Modified Files:")
for file in self._changed_files: for file in self._modified_files:
pretty.modified_file(file) pretty.modified_file(file)
logger.info("") logger.info("")
if len(self._deleted_files) > 0: if self._deleted_files:
logger.info("Deleted Files:") logger.info("Deleted Files:")
for file in self._deleted_files: for file in self._deleted_files:
pretty.deleted_file(file) pretty.deleted_file(file)

View File

@ -72,7 +72,7 @@ class Organizer(Location):
dst_absolute.touch() dst_absolute.touch()
return return
self.download_summary.add_changed_file(dst_absolute) self.download_summary.add_modified_file(dst_absolute)
PRETTY.modified_file(dst_absolute) PRETTY.modified_file(dst_absolute)
else: else:
self.download_summary.add_new_file(dst_absolute) self.download_summary.add_new_file(dst_absolute)