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 98f3642b..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: Non .trashinfo file in info dir\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 29030e05..f7fcf5b8 100644 --- a/trashcli/restore/trashed_files.py +++ b/trashcli/restore/trashed_files.py @@ -18,17 +18,24 @@ 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] ): # 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") + 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" % @@ -40,6 +47,12 @@ def all_trashed_files(self, else: raise RuntimeError() + 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-restore --show-non-trashinfo` to list them." % + (non_trash)) + + def all_trashed_files_internal(self, trash_dir_from_cli, # type: Optional[str] ): # type: (...) -> Iterable[Event]