From 005a363181fd9a3802a18f343962c7f1336fe2ea Mon Sep 17 00:00:00 2001 From: Andrea Francia <260852+andreafrancia@users.noreply.github.com> Date: Thu, 9 Nov 2023 12:00:07 +0100 Subject: [PATCH] Add some debug prints to solve https://github.com/andreafrancia/trash-cli/issues/314 --- trashcli/restore/info_dir_searcher.py | 6 +++++- trashcli/restore/info_files.py | 6 ++++-- trashcli/restore/trash_directories.py | 12 ++++++++---- trashcli/trash.py | 8 ++++++++ 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/trashcli/restore/info_dir_searcher.py b/trashcli/restore/info_dir_searcher.py index 12577bca..215aa23f 100644 --- a/trashcli/restore/info_dir_searcher.py +++ b/trashcli/restore/info_dir_searcher.py @@ -1,7 +1,10 @@ -from typing import NamedTuple, Iterable, Optional +from typing import Iterable +from typing import NamedTuple +from typing import Optional from trashcli.restore.info_files import InfoFiles from trashcli.restore.trash_directories import TrashDirectories +from trashcli.trash import debug_print class InfoDirSearcher: @@ -17,6 +20,7 @@ def all_file_in_info_dir(self, ): # type: (...) -> Iterable[FileFound] for trash_dir_path, volume in self.trash_directories.list_trash_dirs( trash_dir_from_cli): + debug_print(">>>> found trash dir: %s" % trash_dir_path) for type, path in self.info_files.all_info_files(trash_dir_path): yield FileFound(type, path, volume) diff --git a/trashcli/restore/info_files.py b/trashcli/restore/info_files.py index 4cf1938d..f0bf0a74 100644 --- a/trashcli/restore/info_files.py +++ b/trashcli/restore/info_files.py @@ -1,6 +1,7 @@ import os from trashcli.restore.file_system import ListingFileSystem +from trashcli.trash import debug_print class InfoFiles: @@ -14,9 +15,10 @@ def all_info_files(self, path): info_dir = os.path.join(norm_path, 'info') try: for info_file in self.fs.list_files_in_dir(info_dir): + debug_print(">>>> info_file: %s" % info_file) if not os.path.basename(info_file).endswith('.trashinfo'): yield ('non_trashinfo', info_file) else: yield ('trashinfo', info_file) - except OSError: # when directory does not exist - pass + except OSError as e: # when directory does not exist + debug_print(">>>> exception: %s" % e) diff --git a/trashcli/restore/trash_directories.py b/trashcli/restore/trash_directories.py index 4f1c1800..73f56619 100644 --- a/trashcli/restore/trash_directories.py +++ b/trashcli/restore/trash_directories.py @@ -1,14 +1,17 @@ # Copyright (C) 2007-2023 Andrea Francia Trivolzio(PV) Italy -from abc import abstractmethod, ABCMeta +from abc import ABCMeta +from abc import abstractmethod +from typing import Optional import six -from typing import Optional from trashcli.fstab.volume_of import VolumeOf from trashcli.fstab.volumes import Volumes from trashcli.lib.environ import Environ -from trashcli.lib.trash_dirs import ( - volume_trash_dir1, volume_trash_dir2, home_trash_dir) +from trashcli.lib.trash_dirs import home_trash_dir +from trashcli.lib.trash_dirs import volume_trash_dir1 +from trashcli.lib.trash_dirs import volume_trash_dir2 +from trashcli.trash import debug_print @six.add_metaclass(ABCMeta) @@ -65,6 +68,7 @@ def __init__(self, def all_trash_directories(self): volumes_to_check = self.volumes.list_mount_points() + debug_print(">>>> volumes_to_check: %s" % volumes_to_check) for path1, volume1 in home_trash_dir(self.environ, self.volumes): yield path1, volume1 for volume in volumes_to_check: diff --git a/trashcli/trash.py b/trashcli/trash.py index db1a088a..30f61eeb 100644 --- a/trashcli/trash.py +++ b/trashcli/trash.py @@ -1,3 +1,11 @@ # Copyright (C) 2007-2011 Andrea Francia Trivolzio(PV) Italy version = '0.23.9.23' + + +def debug_print(msg): + import os + import sys + if os.environ.get('TRASHCLI_DEBUG') == '1': + print(msg, file=sys.stderr) +