Add preliminary logging to organizer and tmp_dir

This commit is contained in:
I-Al-Istannen 2020-04-20 14:37:44 +02:00
parent 930d821dd7
commit b2fe7cc064
2 changed files with 22 additions and 1 deletions

View file

@ -3,12 +3,15 @@
A organizer is bound to a single directory.
"""
import logging
import shutil
from pathlib import Path
from typing import List, Set
from .utils import prompt_yes_no
logger = logging.getLogger(__name__)
class Organizer():
"""A helper for managing downloaded files."""
@ -28,13 +31,19 @@ class Organizer():
"""Move a file to this organizer and mark it."""
source_absolute = self.path.joinpath(source).absolute()
target_absolute = self.path.joinpath(target).absolute()
logger.debug(f"Copying '{source_absolute}' to '{target_absolute}")
shutil.move(str(source_absolute), str(target_absolute))
self.mark_file(target)
# TODO: Name this method :/ track_file?
def mark_file(self, path: Path) -> None:
"""Mark a file as used so it will not get cleaned up."""
self._known_files.add(self.path.joinpath(path).absolute())
absolute_path = self.path.joinpath(path).absolute()
self._known_files.add(absolute_path)
logger.debug(f"Tracked {absolute_path}")
def resolve_file(self, file_path: Path) -> Path:
"""Resolve a file relative to the path of this organizer."""
@ -42,6 +51,8 @@ class Organizer():
def cleanup(self) -> None:
"""Remove all untracked files in the organizer's dir."""
logger.debug("Deleting all untracked files...")
self._cleanup(self.path)
def _cleanup(self, start_dir: Path) -> None: