Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions trashcli/restore/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ class RunRestoreArgs(
('sort', Sort),
('trash_dir', Optional[str]),
('overwrite', bool),
('show_non_trashinfo', bool),
])):
pass
8 changes: 7 additions & 1 deletion trashcli/restore/restore_arg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
15 changes: 14 additions & 1 deletion trashcli/restore/trashed_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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" %
Expand All @@ -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]
Expand Down