From cfb58b5530b3d6d9db4d319a91eb6cc4a2862eab Mon Sep 17 00:00:00 2001 From: User Date: Fri, 21 Nov 2025 03:54:48 +0200 Subject: [PATCH 1/2] changed error message --- .../components/trashed_files/test_trashed_files.py | 2 +- trashcli/restore/trashed_files.py | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/test_restore/components/trashed_files/test_trashed_files.py b/tests/test_restore/components/trashed_files/test_trashed_files.py index 98f3642b..688008b7 100644 --- a/tests/test_restore/components/trashed_files/test_trashed_files.py +++ b/tests/test_restore/components/trashed_files/test_trashed_files.py @@ -60,7 +60,7 @@ def test_on_non_trashinfo(self): 'trashed_files': trashed_files, 'out': self.out.getvalue()} == { 'trashed_files': [], - 'out': 'WARN: Non .trashinfo file in info dir\n' + 'out': 'WARN: Found a total of 1 non .trashinfo files in trash-dirs. Use `trash-list --find-non-trashinfo` to list them.\n' } def test_on_non_parsable_trashinfo(self): diff --git a/trashcli/restore/trashed_files.py b/trashcli/restore/trashed_files.py index 29030e05..a04e2791 100644 --- a/trashcli/restore/trashed_files.py +++ b/trashcli/restore/trashed_files.py @@ -26,9 +26,12 @@ def __init__(self, def all_trashed_files(self, trash_dir_from_cli, # type: Optional[str] ): # type: (...) -> Iterable[TrashedFile] + + non_trash = 0 for event in self.all_trashed_files_internal(trash_dir_from_cli): if type(event) is NonTrashinfoFileFound: - self.logger.warning("Non .trashinfo file in info dir") + # self.logger.warning("Non .trashinfo file in info dir") + non_trash+=1 elif type(event) is NonParsableTrashInfo: self.logger.warning( "Non parsable trashinfo file: %s, because %s" % @@ -40,6 +43,12 @@ def all_trashed_files(self, else: raise RuntimeError() + if non_trash: + self.logger.warning( + "Found a total of %s non .trashinfo files in trash-dirs. Use `trash-list --find-non-trashinfo` to list them." % + (non_trash)) + + def all_trashed_files_internal(self, trash_dir_from_cli, # type: Optional[str] ): # type: (...) -> Iterable[Event] From f2ba9bc1ca06a143f766e295244e8c1da9307c1b Mon Sep 17 00:00:00 2001 From: User Date: Sun, 23 Nov 2025 18:31:35 +0200 Subject: [PATCH 2/2] modiefied restore to show missing info better --- .../components/arg_parser/test_restore_arg_parser.py | 9 ++++++--- .../components/trashed_files/test_trashed_files.py | 3 ++- trashcli/restore/args.py | 1 + trashcli/restore/restore_arg_parser.py | 8 +++++++- trashcli/restore/trashed_files.py | 12 ++++++++---- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/tests/test_restore/components/arg_parser/test_restore_arg_parser.py b/tests/test_restore/components/arg_parser/test_restore_arg_parser.py index d5aeedca..b992b197 100644 --- a/tests/test_restore/components/arg_parser/test_restore_arg_parser.py +++ b/tests/test_restore/components/arg_parser/test_restore_arg_parser.py @@ -15,7 +15,8 @@ def test_default_path(self): self.assertEqual(RunRestoreArgs(path='curdir', sort=Sort.ByDate, trash_dir=None, - overwrite=False), + overwrite=False, + show_non_trashinfo=False), args) def test_path_specified_relative_path(self): @@ -24,7 +25,8 @@ def test_path_specified_relative_path(self): self.assertEqual(RunRestoreArgs(path='curdir/path', sort=Sort.ByDate, trash_dir=None, - overwrite=False), + overwrite=False, + show_non_trashinfo=False), args) def test_path_specified_fullpath(self): @@ -33,7 +35,8 @@ def test_path_specified_fullpath(self): self.assertEqual(RunRestoreArgs(path='/a/path', sort=Sort.ByDate, trash_dir=None, - overwrite=False), + overwrite=False, + show_non_trashinfo=False), args) def test_show_version(self): diff --git a/tests/test_restore/components/trashed_files/test_trashed_files.py b/tests/test_restore/components/trashed_files/test_trashed_files.py index 688008b7..a464593c 100644 --- a/tests/test_restore/components/trashed_files/test_trashed_files.py +++ b/tests/test_restore/components/trashed_files/test_trashed_files.py @@ -60,8 +60,9 @@ def test_on_non_trashinfo(self): 'trashed_files': trashed_files, 'out': self.out.getvalue()} == { 'trashed_files': [], - 'out': 'WARN: Found a total of 1 non .trashinfo files in trash-dirs. Use `trash-list --find-non-trashinfo` to list them.\n' + 'out': 'WARN: Found a total of 1 non .trashinfo files in trash-dirs. Use `trash-restore --show-non-trashinfo` to list them.\n' } + def test_on_non_parsable_trashinfo(self): self.fs.write_file('/trash-dir/info/info_path.trashinfo', diff --git a/trashcli/restore/args.py b/trashcli/restore/args.py index bf1e1841..c9f8ef40 100644 --- a/trashcli/restore/args.py +++ b/trashcli/restore/args.py @@ -19,5 +19,6 @@ class RunRestoreArgs( ('sort', Sort), ('trash_dir', Optional[str]), ('overwrite', bool), + ('show_non_trashinfo', bool), ])): pass diff --git a/trashcli/restore/restore_arg_parser.py b/trashcli/restore/restore_arg_parser.py index 435639cf..c6138891 100644 --- a/trashcli/restore/restore_arg_parser.py +++ b/trashcli/restore/restore_arg_parser.py @@ -46,6 +46,11 @@ def parse_restore_args(self, default=False, help='Overwrite existing files with files coming out of the trash') + parser.add_argument('--show-non-trashinfo', + action='store_true', + default=False, + help='Show additional info') + parsed = parser.parse_args(sys_argv[1:]) if parsed.version: @@ -61,4 +66,5 @@ def parse_restore_args(self, 'none': Sort.DoNot }[parsed.sort]), trash_dir=parsed.trash_dir, - overwrite=parsed.overwrite) + overwrite=parsed.overwrite, + show_non_trashinfo=parsed.show_non_trashinfo) diff --git a/trashcli/restore/trashed_files.py b/trashcli/restore/trashed_files.py index a04e2791..f7fcf5b8 100644 --- a/trashcli/restore/trashed_files.py +++ b/trashcli/restore/trashed_files.py @@ -18,10 +18,12 @@ def __init__(self, logger, # type: RestoreLogger file_reader, # type: FileReader searcher, # type: InfoDirSearcher + show_non_trashinfo = False, # type: bool ): self.logger = logger self.file_reader = file_reader self.searcher = searcher + self.show_non_trashinfo=show_non_trashinfo def all_trashed_files(self, trash_dir_from_cli, # type: Optional[str] @@ -30,8 +32,10 @@ def all_trashed_files(self, non_trash = 0 for event in self.all_trashed_files_internal(trash_dir_from_cli): if type(event) is NonTrashinfoFileFound: - # self.logger.warning("Non .trashinfo file in info dir") - non_trash+=1 + if self.show_non_trashinfo: + self.logger.warning("Non .trashinfo file in info dir '%s'",event.path) + else: + non_trash+=1 elif type(event) is NonParsableTrashInfo: self.logger.warning( "Non parsable trashinfo file: %s, because %s" % @@ -43,9 +47,9 @@ def all_trashed_files(self, else: raise RuntimeError() - if non_trash: + if non_trash and not self.show_non_trashinfo: self.logger.warning( - "Found a total of %s non .trashinfo files in trash-dirs. Use `trash-list --find-non-trashinfo` to list them." % + "Found a total of %s non .trashinfo files in trash-dirs. Use `trash-restore --show-non-trashinfo` to list them." % (non_trash))