Add download summary

This commit is contained in:
Daniel Augustin 2020-06-25 15:41:58 +02:00
parent 7024db1f13
commit f6fbd5e4bb
No known key found for this signature in database
GPG Key ID: E05C0457D89D41F5
4 changed files with 39 additions and 1 deletions

3
.gitignore vendored
View File

@ -1,5 +1,8 @@
__pycache__/
.venv/
venv/
.idea/
build/
.mypy_cache/
.tmp/
.env

View File

@ -24,6 +24,9 @@ class FileAcceptException(Exception):
class Organizer(Location):
"""A helper for managing downloaded files."""
new_files = []
modified_files = []
def __init__(self, path: Path):
"""Create a new organizer for a given path."""
super().__init__(path)
@ -69,8 +72,10 @@ class Organizer(Location):
dst_absolute.touch()
return
self.modified_files.append(dst_absolute)
PRETTY.modified_file(dst_absolute)
else:
self.new_files.append(dst_absolute)
PRETTY.new_file(dst_absolute)
# Create parent dir if needed

View File

@ -34,6 +34,9 @@ class Pferd(Location):
useful shortcuts for running synchronizers in a single interface.
"""
new_files = []
modified_files = []
def __init__(
self,
base_dir: Path,
@ -139,7 +142,8 @@ class Pferd(Location):
# This authenticator only works with the KIT ilias instance.
authenticator = KitShibbolethAuthenticator(username=username, password=password)
PRETTY.starting_synchronizer(target, "ILIAS", course_id)
return self._ilias(
organizer = self._ilias(
target=target,
base_url="https://ilias.studium.kit.edu/",
crawl_function=lambda crawler: crawler.crawl_course(course_id),
@ -151,6 +155,31 @@ class Pferd(Location):
clean=clean,
)
self.new_files += organizer.new_files
self.modified_files += organizer.modified_files
return organizer
def print_summary(self):
LOGGER.info("")
LOGGER.info("Summary: ")
if len(self.new_files) == 0 and len(self.modified_files) == 0:
LOGGER.info("Nothing changed")
if len(self.new_files) > 0:
LOGGER.info("New Files:")
for file in self.new_files:
PRETTY.new_file(file)
LOGGER.info("")
if len(self.modified_files) > 0:
LOGGER.info("Modified Files:")
for file in self.modified_files:
PRETTY.modified_file(file)
LOGGER.info("")
@swallow_and_print_errors
def ilias_kit_personal_desktop(
self,

View File

@ -124,6 +124,7 @@ def main() -> None:
cookies="ilias_cookies.txt",
)
pferd.print_summary()
if __name__ == "__main__":
main()