File: handler.py

package info (click to toggle)
trash-cli 0.24.5.26-0.3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,972 kB
  • sloc: python: 9,789; sh: 121; makefile: 11
file content (52 lines) | stat: -rw-r--r-- 2,187 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from __future__ import print_function
from __future__ import unicode_literals

from typing import List

from trashcli.lib.my_input import Input
from trashcli.restore.file_system import ReadCwd
from trashcli.restore.output import Output
from trashcli.restore.output_recorder import OutputRecorder
from trashcli.restore.restore_asking_the_user import RestoreAskingTheUser
from trashcli.restore.restorer import Restorer
from trashcli.restore.run_restore_action import Handler
from trashcli.restore.trashed_file import TrashedFile


class HandlerImpl(Handler):
    def __init__(self,
                 input,  # type: Input
                 cwd,  # type: ReadCwd
                 restorer,  # type: Restorer
                 output,  # type: Output
                 ):
        self.input = input
        self.cwd = cwd
        self.restorer = restorer
        self.output = output

    def handle_trashed_files(self,
                             trashed_files,  # type: List[TrashedFile]
                             overwrite,  # type: bool
                             ):
        if not trashed_files:
            self.report_no_files_found(self.cwd.getcwd_as_realpath())
        else:
            for i, trashed_file in enumerate(trashed_files):
                self.output.println("%4d %s %s" % (i,
                                                   trashed_file.deletion_date,
                                                   trashed_file.original_location))
            self.restore_asking_the_user(trashed_files, overwrite)

    def restore_asking_the_user(self, trashed_files, overwrite=False):
        my_output = OutputRecorder()
        restore_asking_the_user = RestoreAskingTheUser(self.input,
                                                       self.restorer,
                                                       my_output)
        restore_asking_the_user.restore_asking_the_user(trashed_files,
                                                        overwrite)
        my_output.apply_to(self.output)

    def report_no_files_found(self, directory):  # type: (str) -> None
        self.output.println(
            "No files trashed from current dir ('%s')" % directory)