示例#1
0
 def run(self, *argv):
     file_reader = FileSystemReader()
     file_reader.list_volumes = lambda: self.volumes
     ListCmd(
         out=self.stdout,
         err=self.stderr,
         environ=self.environ,
         getuid=self.fake_getuid,
         file_reader=file_reader,
         list_volumes=lambda: self.volumes,
     ).run(*argv)
示例#2
0
 def run(self, *argv):
     file_reader = FileSystemReader()
     file_reader.list_volumes = lambda: self.volumes
     volumes_listing = Mock(spec=VolumesListing)
     volumes_listing.list_volumes.return_value = self.volumes
     ListCmd(
         out=self.stdout,
         err=self.stderr,
         environ=self.environ,
         getuid=self.fake_getuid,
         file_reader=file_reader,
         volumes_listing=volumes_listing,
     ).run(*argv)
示例#3
0
    def test_help_output(self):
        err, out = StringIO(), StringIO()
        cmd = EmptyCmd(
            err=err,
            out=out,
            environ={},
            list_volumes=no_volumes,
            now=None,
            file_reader=FileSystemReader(),
            getuid=None,
            file_remover=None,
            version=None,
        )
        cmd.run('trash-empty', '--help')
        assert_equal(
            out.getvalue(),
            dedent("""\
            Usage: trash-empty [days]

            Purge trashed files.

            Options:
              --version   show program's version number and exit
              -h, --help  show this help message and exit

            Report bugs to https://github.com/andreafrancia/trash-cli/issues
            """))
示例#4
0
 def setUp(self):
     require_empty_dir('sandbox')
     self.out = Mock()
     self.listing = ListTrashinfos(self.out,
                                   FileSystemReader(),
                                   None)
     self.index = 0
示例#5
0
文件: rm.py 项目: nestukh/trash-cli
    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()
示例#6
0
 def setUp(self):
     require_empty_dir('sandbox/xdh')
     self.stderr = StringIO()
     self.trash_rm = RmCmd(environ = {'XDG_DATA_HOME':'sandbox/xdh'}
                      , getuid = 123
                      , list_volumes = lambda:[]
                      , stderr = self.stderr
                      , file_reader = FileSystemReader())
示例#7
0
 def setUp(self):
     self.xdg_data_home = MyPath.make_temp_dir()
     self.stderr = StringIO()
     self.trash_rm = RmCmd(environ={'XDG_DATA_HOME': self.xdg_data_home},
                           getuid=123,
                           list_volumes=lambda: [],
                           stderr=self.stderr,
                           file_reader=FileSystemReader())
示例#8
0
 def setUp(self):
     self.xdg_data_home = MyPath.make_temp_dir()
     self.stderr = StringIO()
     self.trash_rm = RmCmd(environ={'XDG_DATA_HOME': self.xdg_data_home},
                           getuid=lambda: 123,
                           volumes_listing=VolumesListing(lambda: []),
                           stderr=self.stderr,
                           file_reader=FileSystemReader())
     self.fake_trash_dir = FakeTrashDir(self.xdg_data_home / 'Trash')
示例#9
0
def main():
    from trashcli.list_mount_points import os_mount_points
    cmd = RmCmd(environ        = os.environ
                , getuid       = os.getuid
                , list_volumes = os_mount_points
                , stderr       = sys.stderr
                , file_reader  = FileSystemReader())

    cmd.run(sys.argv)

    return cmd.exit_code
示例#10
0
 def setUp(self):
     require_empty_dir('topdir')
     self.empty=EmptyCmd(
             out          = StringIO(),
             err          = StringIO(),
             environ      = {},
             list_volumes = lambda: ['topdir'],
             now          = None,
             file_reader  = FileSystemReader(),
             getuid       = lambda: 123,
             file_remover = FileRemover(),
             version      = None,
     )
示例#11
0
 def setUp(self):
     self.err, self.out = StringIO(), StringIO()
     self.cmd = EmptyCmd(
                    err = self.err,
                    out = self.out,
                    environ = {},
                    list_volumes = no_volumes,
                    now = None,
                    file_reader = FileSystemReader(),
                    getuid = None,
                    file_remover = None,
                    version = None,
                    )
示例#12
0
def main():
    from trashcli.list_mount_points import os_mount_points
    from trashcli.fstab import VolumesListing
    volumes_listing = VolumesListing(os_mount_points)
    cmd = RmCmd(environ=os.environ,
                getuid=os.getuid,
                volumes_listing=volumes_listing,
                stderr=sys.stderr,
                file_reader=FileSystemReader())

    cmd.run(sys.argv)

    return cmd.exit_code
示例#13
0
def main(argv=sys.argv,
         stdout=sys.stdout,
         stderr=sys.stderr,
         environ=os.environ):
    return EmptyCmd(out=stdout,
                    err=stderr,
                    environ=environ,
                    volumes_listing=VolumesListing(os_mount_points),
                    now=datetime.now,
                    file_reader=FileSystemReader(),
                    getuid=os.getuid,
                    file_remover=FileRemover(),
                    version=trash.version,
                    volume_of=volume_of).run(*argv)
示例#14
0
 def setUp(self):
     self.temp_dir = MyPath.make_temp_dir()
     self.top_dir = self.temp_dir / 'topdir'
     require_empty_dir(self.top_dir)
     self.empty = EmptyCmd(
         out=StringIO(),
         err=StringIO(),
         environ={},
         list_volumes=lambda: [self.top_dir],
         now=None,
         file_reader=FileSystemReader(),
         getuid=lambda: 123,
         file_remover=FileRemover(),
         version=None,
     )
示例#15
0
 def setUp(self):
     require_empty_dir('XDG_DATA_HOME')
     self.xdg_data_home   = 'XDG_DATA_HOME'
     self.environ = {'XDG_DATA_HOME':'XDG_DATA_HOME'}
     self.now = MagicMock(side_effect=RuntimeError)
     self.empty_cmd=EmptyCmd(
         out = StringIO(),
         err = StringIO(),
         environ = self.environ,
         list_volumes = no_volumes,
         now = self.now,
         file_reader = FileSystemReader(),
         getuid = None,
         file_remover = FileRemover(),
         version = None,
     )
示例#16
0
 def test_it_print_version(self):
     err, out = StringIO(), StringIO()
     cmd = EmptyCmd(err = err,
                    out = out,
                    environ = {},
                    list_volumes = no_volumes,
                    now = None,
                    file_reader = FileSystemReader(),
                    getuid = None,
                    file_remover = None,
                    version = '1.2.3',
                    )
     cmd.run('trash-empty', '--version')
     assert_equal(out.getvalue(), dedent("""\
         trash-empty 1.2.3
         """))
示例#17
0
 def setUp(self):
     require_empty_dir('XDG_DATA_HOME')
     self.info_dir_path   = 'XDG_DATA_HOME/Trash/info'
     self.files_dir_path  = 'XDG_DATA_HOME/Trash/files'
     self.environ = {'XDG_DATA_HOME':'XDG_DATA_HOME'}
     now = MagicMock(side_effect=RuntimeError)
     self.empty_cmd = EmptyCmd(
         out = StringIO(),
         err = StringIO(),
         environ = self.environ,
         list_volumes = no_volumes,
         now = now,
         file_reader = FileSystemReader(),
         getuid = None,
         file_remover = FileRemover(),
         version = None,
     )
示例#18
0
 def setUp(self):
     self.tmp_dir = MyPath.make_temp_dir()
     self.unreadable_dir = self.tmp_dir / 'data/Trash/files/unreadable'
     self.volumes_listing = Mock(spec=VolumesListing)
     self.volumes_listing.list_volumes.return_value = [self.unreadable_dir]
     self.err=StringIO()
     self.empty = EmptyCmd(
         out=StringIO(),
         err=self.err,
         environ={'XDG_DATA_HOME':self.tmp_dir / 'data'},
         volumes_listing=self.volumes_listing,
         now=None,
         file_reader=FileSystemReader(),
         getuid=lambda: 123,
         file_remover=FileRemover(),
         version=None,
         volume_of=lambda x: "volume_of %s" % x
     )
示例#19
0
 def setUp(self):
     self.temp_dir = MyPath.make_temp_dir()
     self.top_dir = self.temp_dir / 'topdir'
     self.volumes_listing = Mock(spec=VolumesListing)
     self.volumes_listing.list_volumes.return_value = [self.top_dir]
     require_empty_dir(self.top_dir)
     self.empty = EmptyCmd(
         out=StringIO(),
         err=StringIO(),
         environ={},
         volumes_listing=self.volumes_listing,
         now=None,
         file_reader=FileSystemReader(),
         getuid=lambda: 123,
         file_remover=FileRemover(),
         version=None,
         volume_of=lambda x: "volume_of %s" % x
     )
示例#20
0
    def test_trash_empty_last_line(self):
        from trashcli.empty import EmptyCmd
        from trashcli.fs import FileSystemReader

        cmd = EmptyCmd(
            self.out,
            StringIO(),
            [],
            lambda: [],
            now=None,
            file_reader=FileSystemReader(),
            getuid=None,
            file_remover=None,
            version=None,
        )
        cmd.run('', '--help')

        self.assert_last_line_of_output_is(
            'Report bugs to https://github.com/andreafrancia/trash-cli/issues')
示例#21
0
def main(argv=sys.argv,
         stdout=sys.stdout,
         stderr=sys.stderr,
         environ=os.environ):
    from trashcli.list_mount_points import os_mount_points
    from datetime import datetime
    from trashcli.fs import FileSystemReader
    from trashcli.fs import FileRemover
    from trashcli.trash import version
    return EmptyCmd(
        out=stdout,
        err=stderr,
        environ=environ,
        list_volumes=os_mount_points,
        now=datetime.now,
        file_reader=FileSystemReader(),
        getuid=os.getuid,
        file_remover=FileRemover(),
        version=version,
    ).run(*argv)
示例#22
0
 def setUp(self):
     self.tmp_dir = MyPath.make_temp_dir()
     self.trash_dir = self.tmp_dir / 'Trash'
     self.out = Mock()
     self.listing = ListTrashinfos(self.out, FileSystemReader(), None)
     self.index = 0
示例#23
0
文件: rm.py 项目: Brijen/trash-cli
 def _report_original_location(self, trashinfo_path):
     file_reader = FileSystemReader()
     trashinfo = file_reader.contents_of(trashinfo_path)
     path = parse_path(trashinfo)
     complete_path = os.path.join(self.volume, path)
     self.out(complete_path, trashinfo_path)
示例#24
0
        run('chmod +t sandbox/sticky')

        assert has_sticky_bit('sandbox/sticky')

    def test_has_sticky_bit_returns_false(self):

        make_empty_file("sandbox/non-sticky")
        run('chmod -t sandbox/non-sticky')

        assert not has_sticky_bit("sandbox/non-sticky")

    def setUp(self):
        require_empty_dir('sandbox')


is_sticky_dir = FileSystemReader().is_sticky_dir


class Test_is_sticky_dir:
    def test_dir_non_sticky(self):
        mkdirs('sandbox/dir')
        assert not is_sticky_dir('sandbox/dir')

    def test_dir_sticky(self):
        mkdirs('sandbox/dir')
        set_sticky_bit('sandbox/dir')
        assert is_sticky_dir('sandbox/dir')

    def test_non_dir_but_sticky(self):
        make_empty_file('sandbox/dir')
        set_sticky_bit('sandbox/dir')
示例#25
0
 def setUp(self):
     self.tmp_dir = MyPath.make_temp_dir()
     self.trash_dir = self.tmp_dir / 'Trash'
     self.fake_trash_dir = FakeTrashDir(self.trash_dir)
     self.listing = ListTrashinfos(FileSystemReader())
示例#26
0
文件: rm.py 项目: nestukh/trash-cli
 def list_from_volume_trashdir(self, trashdir_path, volume):
     self.volume = volume
     self.trashdir = TrashDir(FileSystemReader())
     self.trashdir.open(trashdir_path, volume)
     self.trashdir.each_trashinfo(self._report_original_location)
示例#27
0
文件: rm.py 项目: nestukh/trash-cli
 def _report_original_location(self, trashinfo_path):
     file_reader = FileSystemReader()
     trashinfo = file_reader.contents_of(trashinfo_path)
     path = parse_path(trashinfo)
     complete_path = os.path.join(self.volume, path)
     self.out(complete_path, trashinfo_path)