Пример #1
0
    def run(self, argv):
        args = argv[1:]
        self.exit_code = 0

        if not args:
            self.print_err('Usage:\n'
                           '    trash-rm PATTERN\n'
                           '\n'
                           'Please specify PATTERN')
            self.exit_code = 8
            return

        trashcan = CleanableTrashcan(FileRemover())
        cmd = Filter(trashcan.delete_trashinfo_and_backup_copy)
        cmd.use_pattern(args[0])

        listing = ListTrashinfos(cmd.delete_if_matches,
                                 self.file_reader,
                                 self.unable_to_parse_path)

        trashdirs = TrashDirs(self.environ,
                              self.getuid,
                              self.list_volumes,
                              TopTrashDirRules(self.file_reader))
        trashdirs.on_trash_dir_found = listing.list_from_volume_trashdir

        trashdirs.list_trashdirs()
Пример #2
0
    def run(self, argv):
        args = argv[1:]
        self.exit_code = 0

        if not args:
            self.stderr.write('Usage:\n'
                              '    trash-rm PATTERN\n'
                              '\n'
                              'Please specify PATTERN\n')
            self.exit_code = 8
            return

        trashcan = CleanableTrashcan(FileRemover())
        cmd = Filter(trashcan.delete_trashinfo_and_backup_copy)
        cmd.use_pattern(args[0])
        file_reader = FileSystemReader()
        listing = ListTrashinfos(cmd.delete_if_matches)
        top_trashdir_rules = TopTrashDirRules(file_reader)
        trashdirs = TrashDirs(self.environ,
                              self.getuid,
                              list_volumes=self.list_volumes,
                              top_trashdir_rules=top_trashdir_rules)
        trashdirs.on_trash_dir_found = listing.list_from_volume_trashdir

        trashdirs.list_trashdirs()
class TestDescribe_AvailableTrashDirs_when_parent_is_unsticky(
        unittest.TestCase):
    def setUp(self):
        self.fs = MagicMock()
        self.dirs = TrashDirs(
            environ={},
            getuid=lambda: 123,
            top_trashdir_rules=TopTrashDirRules(self.fs),
            list_volumes=lambda: ['/topdir'],
        )
        self.dirs.on_trashdir_skipped_because_parent_not_sticky = Mock()
        self.dirs.on_trashdir_skipped_because_parent_is_symlink = Mock()
        self.fs.is_sticky_dir.side_effect = (lambda path: {
            '/topdir/.Trash': False
        }[path])

    def test_it_should_report_skipped_dir_non_sticky(self):
        self.fs.exists.side_effect = (lambda path: {
            '/topdir/.Trash/123': True
        }[path])

        self.dirs.list_trashdirs()

        (self.dirs.on_trashdir_skipped_because_parent_not_sticky.
         assert_called_with('/topdir/.Trash/123'))

    def test_it_shouldnot_care_about_non_existent(self):
        self.fs.exists.side_effect = (lambda path: {
            '/topdir/.Trash/123': False
        }[path])

        self.dirs.list_trashdirs()

        assert [] == self.dirs.on_trashdir_skipped_because_parent_not_sticky.mock_calls
Пример #4
0
class Describe_AvailableTrashDirs_when_parent_is_unsticky:
    def setUp(self):
        self.fs = MagicMock()
        self.dirs = TrashDirs(environ = {},
                              getuid = lambda:123,
                              top_trashdir_rules = TopTrashDirRules(self.fs),
                              list_volumes = lambda: ['/topdir'],
                              )
        self.dirs.on_trashdir_skipped_because_parent_not_sticky = Mock()
        self.dirs.on_trashdir_skipped_because_parent_is_symlink = Mock()
        self.fs.is_sticky_dir.side_effect = (
                lambda path: {'/topdir/.Trash':False}[path])

    def test_it_should_report_skipped_dir_non_sticky(self):
        self.fs.exists.side_effect = (
                lambda path: {'/topdir/.Trash/123':True}[path])

        self.dirs.list_trashdirs()

        (self.dirs.on_trashdir_skipped_because_parent_not_sticky.
                assert_called_with('/topdir/.Trash/123'))

    def test_it_shouldnot_care_about_non_existent(self):
        self.fs.exists.side_effect = (
                lambda path: {'/topdir/.Trash/123':False}[path])

        self.dirs.list_trashdirs()

        assert_equals([], self.dirs.on_trashdir_skipped_because_parent_not_sticky.mock_calls)
    def trashdirs(self):
        result = []

        def append(trash_dir, volume):
            result.append(trash_dir)

        class FileReader:
            def is_sticky_dir(_, path):
                return self.Trash_dir_is_sticky

            def exists(_, path):
                return True

            def is_symlink(_, path):
                return False

        class FakeTopTrashDirRules:
            def valid_to_be_read(_, path, out):
                if self.Trash_dir_is_sticky:
                    out.is_valid()
                else:
                    out.not_valid_parent_should_be_sticky()

        trash_dirs = TrashDirs(
            environ=self.environ,
            getuid=lambda: self.uid,
            top_trashdir_rules=FakeTopTrashDirRules(),
            list_volumes=lambda: self.volumes,
        )
        trash_dirs.on_trash_dir_found = append
        trash_dirs.list_trashdirs()
        return result
Пример #6
0
    def run(self, argv):
        args = argv[1:]
        self.exit_code = 0

        if not args:
            self.print_err('Usage:\n'
                           '    trash-rm PATTERN\n'
                           '\n'
                           'Please specify PATTERN')
            self.exit_code = 8
            return

        trashcan = CleanableTrashcan(FileRemover())
        cmd = Filter(trashcan.delete_trashinfo_and_backup_copy)
        cmd.use_pattern(args[0])

        listing = ListTrashinfos(cmd.delete_if_matches,
                                 self.file_reader,
                                 self.unable_to_parse_path)

        trashdirs = TrashDirs(self.environ,
                              self.getuid,
                              self.list_volumes,
                              TopTrashDirRules(self.file_reader))
        trashdirs.on_trash_dir_found = listing.list_from_volume_trashdir

        trashdirs.list_trashdirs()
Пример #7
0
 def trashdirs(self):
     result = []
     def append(trash_dir, volume):
         result.append(trash_dir)
     class FileReader:
         def is_sticky_dir(_, path):
             return self.Trash_dir_is_sticky
         def exists(_, path):
             return True
         def is_symlink(_, path):
             return False
     class FakeTopTrashDirRules:
         def valid_to_be_read(_, path, out):
             if self.Trash_dir_is_sticky:
                 out.is_valid()
             else:
                 out.not_valid_parent_should_be_sticky()
     trash_dirs = TrashDirs(
         environ=self.environ,
         getuid=lambda:self.uid,
         top_trashdir_rules = FakeTopTrashDirRules(),
         list_volumes = lambda: self.volumes,
     )
     trash_dirs.on_trash_dir_found = append
     trash_dirs.list_trashdirs()
     return result
Пример #8
0
 def setUp(self):
     self.fs = MagicMock()
     self.dirs = TrashDirs(environ = {},
                           getuid = lambda:123,
                           top_trashdir_rules = TopTrashDirRules(self.fs),
                           list_volumes = lambda: ['/topdir'])
     self.fs.exists.side_effect = (lambda path: {'/topdir/.Trash/123':True}[path])
     self.symlink_error = Mock()
     self.dirs.on_trashdir_skipped_because_parent_is_symlink = self.symlink_error
Пример #9
0
 def setUp(self):
     self.fs = MagicMock()
     self.dirs = TrashDirs(environ = {},
                           getuid = lambda:123,
                           top_trashdir_rules = TopTrashDirRules(self.fs),
                           list_volumes = lambda: ['/topdir'],
                           )
     self.dirs.on_trashdir_skipped_because_parent_not_sticky = Mock()
     self.dirs.on_trashdir_skipped_because_parent_is_symlink = Mock()
     self.fs.is_sticky_dir.side_effect = (
             lambda path: {'/topdir/.Trash':False}[path])
    def test_howto_list_trashdirs(self):
        out = Mock()
        environ = {'HOME':'/home/user'}
        trashdirs = TrashDirs(
                environ = environ,
                getuid = lambda:123,
                list_volumes = lambda:['/vol', '/vol2'],
                top_trashdir_rules = Mock(),
                )
        trashdirs.on_trash_dir_found = out
        trashdirs.list_trashdirs()

        assert_equals([call('/home/user/.local/share/Trash', '/'),
                       call('/vol/.Trash-123', '/vol'),
                       call('/vol2/.Trash-123', '/vol2')],
                      out.mock_calls)
    def test_howto_list_trashdirs(self):
        out = Mock()
        environ = {'HOME': '/home/user'}
        trashdirs = TrashDirs(
            environ=environ,
            getuid=lambda: 123,
            list_volumes=lambda: ['/vol', '/vol2'],
            top_trashdir_rules=Mock(),
        )
        trashdirs.on_trash_dir_found = out
        trashdirs.list_trashdirs()

        assert_equal([
            call('/home/user/.local/share/Trash', '/'),
            call('/vol/.Trash-123', '/vol'),
            call('/vol2/.Trash-123', '/vol2')
        ], out.mock_calls)
Пример #12
0
 def setUp(self):
     self.fs = MagicMock()
     self.dirs = TrashDirs(environ = {},
                           getuid = lambda:123,
                           top_trashdir_rules = TopTrashDirRules(self.fs),
                           list_volumes = lambda: ['/topdir'])
     self.fs.exists.side_effect = (lambda path: {'/topdir/.Trash/123':True}[path])
     self.symlink_error = Mock()
     self.dirs.on_trashdir_skipped_because_parent_is_symlink = self.symlink_error
Пример #13
0
class Describe_AvailableTrashDirs_when_parent_is_symlink:
    def setUp(self):
        self.fs = MagicMock()
        self.dirs = TrashDirs(environ = {},
                              getuid = lambda:123,
                              top_trashdir_rules = TopTrashDirRules(self.fs),
                              list_volumes = lambda: ['/topdir'])
        self.fs.exists.side_effect = (lambda path: {'/topdir/.Trash/123':True}[path])
        self.symlink_error = Mock()
        self.dirs.on_trashdir_skipped_because_parent_is_symlink = self.symlink_error


    def test_it_should_skip_symlink(self):
        self.fs.is_sticky_dir.return_value = True
        self.fs.is_symlink.return_value    = True

        self.dirs.list_trashdirs()

        self.symlink_error.assert_called_with('/topdir/.Trash/123')
Пример #14
0
class Describe_AvailableTrashDirs_when_parent_is_symlink:
    def setUp(self):
        self.fs = MagicMock()
        self.dirs = TrashDirs(environ = {},
                              getuid = lambda:123,
                              top_trashdir_rules = TopTrashDirRules(self.fs),
                              list_volumes = lambda: ['/topdir'])
        self.fs.exists.side_effect = (lambda path: {'/topdir/.Trash/123':True}[path])
        self.symlink_error = Mock()
        self.dirs.on_trashdir_skipped_because_parent_is_symlink = self.symlink_error


    def test_it_should_skip_symlink(self):
        self.fs.is_sticky_dir.return_value = True
        self.fs.is_symlink.return_value    = True

        self.dirs.list_trashdirs()

        self.symlink_error.assert_called_with('/topdir/.Trash/123')
Пример #15
0
 def setUp(self):
     self.fs = MagicMock()
     self.dirs = TrashDirs(environ = {},
                           getuid = lambda:123,
                           top_trashdir_rules = TopTrashDirRules(self.fs),
                           list_volumes = lambda: ['/topdir'],
                           )
     self.dirs.on_trashdir_skipped_because_parent_not_sticky = Mock()
     self.dirs.on_trashdir_skipped_because_parent_is_symlink = Mock()
     self.fs.is_sticky_dir.side_effect = (
             lambda path: {'/topdir/.Trash':False}[path])
Пример #16
0
    def run(self, argv):
        args = argv[1:]
        self.exit_code = 0

        if not args:
            self.stderr.write('Usage:\n'
                              '    trash-rm PATTERN\n'
                              '\n'
                              'Please specify PATTERN\n')
            self.exit_code = 8
            return

        trashcan = CleanableTrashcan(FileRemover())
        cmd = Filter(trashcan.delete_trashinfo_and_backup_copy)
        cmd.use_pattern(args[0])
        file_reader = FileSystemReader()
        listing = ListTrashinfos(cmd.delete_if_matches)
        top_trashdir_rules = TopTrashDirRules(file_reader)
        trashdirs   = TrashDirs(self.environ, self.getuid,
                                list_volumes = self.list_volumes,
                                top_trashdir_rules = top_trashdir_rules)
        trashdirs.on_trash_dir_found = listing.list_from_volume_trashdir

        trashdirs.list_trashdirs()