예제 #1
0
    def test_mask_time_big(self):
        path1 = os.path.join(self.folder, "a.txt")
        path2 = os.path.join(self.folder, "b.txt")
        path3 = os.path.join(self.folder, "c")

        dtime = datetime.datetime.now()

        new_path1 = stamp.add_stamp(path1, dtime)
        new_path2 = stamp.add_stamp(path2, dtime)
        new_path3 = stamp.add_stamp(path3, dtime)

        open(new_path1, "w").close()
        open(new_path2, "w").close()
        open(new_path3, "w").close()

        mask1 = stamp.extend_mask_by_stamp(path1)
        mask2 = stamp.extend_mask_by_stamp(path2)
        mask3 = stamp.extend_mask_by_stamp(path3)

        dircetory1, file_mask1 = os.path.split(mask1)
        dircetory2, file_mask2 = os.path.split(mask2)
        dircetory3, file_mask3 = os.path.split(mask3)

        files1 = utils.search(dircetory1, "", file_mask1)
        files1 = [stamp.split_stamp(f)[0] for f in files1]
        files2 = utils.search(dircetory2, "", file_mask2)
        files2 = [stamp.split_stamp(f)[0] for f in files2]
        files3 = utils.search(dircetory3, "", file_mask3)
        files3 = [stamp.split_stamp(f)[0] for f in files3]

        self.assertEqual(files1, [path1])
        self.assertEqual(files2, [path2])
        self.assertEqual(files3, [path3])
예제 #2
0
    def test_time(self):
        mask = stamp.extend_mask_by_stamp(self.path)
        dircetory, file_mask = os.path.split(mask)
        files = utils.search(dircetory, "", file_mask)
        times = [stamp.split_stamp(f)[1] for f in files]
        times.sort()

        self.assertEqual(times, [self.dtime1, self.dtime2, self.dtime3])
예제 #3
0
 def test_mask(self):
     path = os.path.join(self.folder, "a.txt")
     dtime = datetime.datetime.now()
     new_path = stamp.add_stamp(path, dtime)
     open(new_path, "w").close()
     mask = stamp.extend_mask_by_stamp(path)
     dircetory, file_mask = os.path.split(mask)
     files = utils.search(dircetory, "", file_mask)
     files = [stamp.split_stamp(f)[0] for f in files]
     self.assertEqual(files, [path])
예제 #4
0
    def get_file_time_list(self):
        """Возвращает список всех файлов в корзине.

        Список сотоит из кортежей (путь, время удаления).

        Список сортируется по дате удаления.

        """
        trash_dir = utils.get_absolute_path(self.directory)

        root_list = os.listdir(trash_dir)
        root_list_full = [os.path.join(trash_dir, path) for path in root_list]
        trash_protocols = (d for d in root_list_full if os.path.isdir(d))
        files = []
        for protocol_path in trash_protocols:
            for dirpath, _, filenames in os.walk(protocol_path):
                files.extend([os.path.join(dirpath, f) for f in filenames])

        files_ext = [self.to_external(f) for f in files]
        file_time_list = [stamp.split_stamp(f) for f in files_ext]

        file_time_list.sort(key=lambda (file_name, vers): vers)

        return file_time_list
예제 #5
0
    def remove(self, path, how_old=-1):
        """Удаляет элемент из корзины навсегда.

        Возвращает количестов очищенных файлов и их размер,
        список очищенных объектов.

        Работа возможна только во время блокировки корзины.

        Позиционные аргументы:
        path -- путь к элементу в корзине

        Непозиционные аргументы:
        how_old -- версия файла в порядке устарения даты удаления.
                   По умолчанию: -1 (все версии)

        Эффективно пересчитывает новый размер корзины и
        количество файлов в ней.

        """
        removed = []

        path = self.to_internal(path)

        delta_count = 0
        delta_size = 0

        if not os.path.isdir(path):
            if how_old >= 0:
                full_path = stamp.get_version(path, how_old)
                delta_count += 1
                delta_size += utils.get_files_size(full_path)
                removed.append(full_path)
                if not self.dryrun:
                    os.remove(full_path)
            else:
                for vers in stamp.get_versions_list(path):
                    full_path = stamp.add_stamp(path, vers)
                    delta_count += 1
                    delta_size += utils.get_files_size(full_path)
                    removed.append(full_path)
                    if not self.dryrun:
                        os.remove(full_path)
        else:
            for dirpath, _, filenames in os.walk(path, topdown=False):
                removed.append(dirpath)
                for element in filenames:
                    full_path = os.path.join(dirpath, element)
                    delta_count += 1
                    delta_size += utils.get_files_size(full_path)
                    removed.append(full_path)
                    if not self.dryrun:
                        os.remove(full_path)
                if not self.dryrun:
                    os.rmdir(dirpath)

        if self.is_locked() and not self.dryrun:
            self._size -= delta_size
            self._count -= delta_count

        removed_stplited = [stamp.split_stamp(f) for f in removed]
        removed_stplited_ext = [(self.to_external(f), d)
                                for f, d in removed_stplited]
        return delta_count, delta_size, removed_stplited_ext
예제 #6
0
 def test_none2(self):
     path = "/a/b"
     res_path, res_dtime = stamp.split_stamp(path)
     self.assertEqual((path, None), (res_path, res_dtime))
예제 #7
0
 def test_trasnit1(self):
     path = "a/b.txt"
     dtime = datetime.datetime.now()
     new_path = stamp.add_stamp(path, dtime)
     res_path, res_dtime = stamp.split_stamp(new_path)
     self.assertEqual((path, dtime), (res_path, res_dtime))