Make DownloadSummary private, provide property accessors

This commit is contained in:
I-Al-Istannen 2020-06-26 17:30:45 +02:00
parent d9ea688145
commit c26c9352f1

View File

@ -11,38 +11,59 @@ class DownloadSummary:
"""
def __init__(self) -> None:
self.new_files: List[Path] = []
self.modified_files: List[Path] = []
self.deleted_files: List[Path] = []
self._new_files: List[Path] = []
self._modified_files: List[Path] = []
self._deleted_files: List[Path] = []
@property
def new_files(self) -> List[Path]:
"""
Returns all new files.
"""
return self._new_files.copy()
@property
def modified_files(self) -> List[Path]:
"""
Returns all modified files.
"""
return self._modified_files.copy()
@property
def deleted_files(self) -> List[Path]:
"""
Returns all deleted files.
"""
return self._deleted_files.copy()
def merge(self, summary: 'DownloadSummary') -> None:
"""
Merges ourselves with the passed summary. Modifies this object, but not the passed one.
"""
self.new_files += summary.new_files
self.modified_files += summary.modified_files
self.deleted_files += summary.deleted_files
self._new_files += summary.new_files
self._modified_files += summary.modified_files
self._deleted_files += summary.deleted_files
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_modified_file(self, path: Path) -> None:
"""
Registers a file as changed.
"""
self.modified_files.append(path)
self._modified_files.append(path)
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_updates(self) -> bool:
"""
Returns whether this summary has any updates.
"""
return bool(self.new_files or self.modified_files or self.deleted_files)
return bool(self._new_files or self._modified_files or self._deleted_files)