pferd/PFERD/download_summary.py

49 lines
1.4 KiB
Python
Raw Normal View History

2020-06-26 15:37:35 +02:00
"""
Provides a summary that keeps track of new modified or deleted files.
"""
2020-06-26 15:17:44 +02:00
from pathlib import Path
2020-06-26 15:37:35 +02:00
from typing import List
2020-06-26 13:02:37 +02:00
class DownloadSummary:
2020-06-26 15:37:35 +02:00
"""
Keeps track of all new, modified or deleted files and provides a summary.
"""
2020-06-26 15:17:44 +02:00
def __init__(self) -> None:
2020-06-26 15:52:07 +02:00
self.new_files: List[Path] = []
self.modified_files: List[Path] = []
self.deleted_files: List[Path] = []
def merge(self, summary: 'DownloadSummary') -> None:
2020-06-26 15:37:35 +02:00
"""
Merges ourselves with the passed summary. Modifies this object, but not the passed one.
"""
2020-06-26 15:52:07 +02:00
self.new_files += summary.new_files
self.modified_files += summary.modified_files
self.deleted_files += summary.deleted_files
2020-06-26 15:17:44 +02:00
def add_deleted_file(self, path: Path) -> None:
2020-06-26 15:37:35 +02:00
"""
Registers a file as deleted.
"""
2020-06-26 15:52:07 +02:00
self.deleted_files.append(path)
2020-06-26 15:37:35 +02:00
def add_modified_file(self, path: Path) -> None:
"""
Registers a file as changed.
"""
2020-06-26 15:52:07 +02:00
self.modified_files.append(path)
2020-06-26 15:17:44 +02:00
def add_new_file(self, path: Path) -> None:
2020-06-26 15:37:35 +02:00
"""
Registers a file as new.
"""
2020-06-26 15:52:07 +02:00
self.new_files.append(path)
2020-06-26 15:52:07 +02:00
def has_updates(self) -> bool:
2020-06-26 15:37:35 +02:00
"""
2020-06-26 15:52:07 +02:00
Returns whether this summary has any updates.
2020-06-26 15:37:35 +02:00
"""
2020-06-26 15:52:07 +02:00
return bool(self.new_files or self.modified_files or self.deleted_files)