Example #1
0
File: trash.py Project: ahua/python
    def trash(self, path):
        from datetime import datetime
        path = os.path.normpath(path)
        self.check()

        if not self.volume == volume_of(parent_of(path)) :
            raise IOError("file is not in the same volume of trash directory!\n"
                   + "self.volume = " + str(self.volume) + ", \n"
                   + "file.parent.volume = "
                        + str(volume_of(parent_of(path))))

        trash_info = TrashInfo(self._path_for_trashinfo(path),
                               datetime.now())

        basename = os.path.basename(trash_info.path)
        trashinfo_file_content = trash_info.render()
        (trash_info_file, trash_info_id) = self.persist_trash_info(basename,
                                                                   trashinfo_file_content)

        trashed_file = self._create_trashed_file(trash_info_id,
                                                 os.path.abspath(path),
                                                 trash_info.deletion_date)

        self.ensure_files_dir_exists()

        try :
            move(path, trashed_file.actual_path)
        except IOError as e :
            remove_file(trash_info_file)
            raise e

        return trashed_file
Example #2
0
File: trash.py Project: ahua/python
 def volume_of_parent(self, file):
     return volume_of(parent_of(file))
Example #3
0
File: trash.py Project: ahua/python
def path_of_backup_copy(path_to_trashinfo):
    from os.path import dirname as parent_of, join, basename
    trash_dir = parent_of(parent_of(path_to_trashinfo))
    return join(trash_dir, 'files', basename(path_to_trashinfo)[:-len('.trashinfo')])
Example #4
0
 def _path_of_backup_copy(self, path_to_trashinfo):
     from os.path import dirname as parent_of, join, basename
     trash_dir = parent_of(parent_of(path_to_trashinfo))
     return join(trash_dir, 'files',
                 basename(path_to_trashinfo)[:-len('.trashinfo')])