Exemplo n.º 1
0
    def read(self,
             storage_object,
             dst,
             extract=False,
             include_xml=True,
             block_size=DEFAULT_TAPE_BLOCK_SIZE):
        tape_pos = int(storage_object.content_location_value)
        medium = storage_object.storage_medium
        ip = storage_object.ip
        block_size = medium.block_size * 512

        # TODO: Create temp dir inside configured temp directory
        tmp_path = tempfile.mkdtemp()

        try:
            drive = TapeDrive.objects.get(storage_medium=medium)
        except TapeDrive.DoesNotExist:
            raise ValueError("Tape not mounted")

        set_tape_file_number(drive.device, tape_pos)
        read_tape(drive.device, path=tmp_path, block_size=block_size)

        drive.last_change = timezone.now()
        drive.save(update_fields=['last_change'])

        src = os.path.join(tmp_path, ip.object_identifier_value)
        if storage_object.container:
            src_tar = src + '.tar'
            src_xml = src + '.xml'
            src_aic_xml = os.path.join(tmp_path, str(ip.aic.pk)) + '.xml'

            if include_xml:
                copy(src_xml, dst, block_size=block_size)
                copy(src_aic_xml, dst, block_size=block_size)
            if extract:
                with tarfile.open(src_tar) as t:
                    root = os.path.commonprefix(t.getnames())
                    t.extractall(dst)
                    new = os.path.join(dst, root)
            else:
                new = copy(src_tar, dst, block_size=block_size)
        else:
            new = copy(src, dst, block_size=block_size)

        try:
            shutil.rmtree(tmp_path)
        except OSError as e:
            if e.errno != errno.ENOENT:
                raise
        return new
Exemplo n.º 2
0
def ReadTape(self, medium=None, path='.', block_size=DEFAULT_TAPE_BLOCK_SIZE):
    """
    Reads the tape in the given drive
    """

    try:
        drive = TapeDrive.objects.get(storage_medium__pk=medium)
    except TapeDrive.DoesNotExist:
        raise ValueError("Tape not mounted")

    read_tape(drive.device, path=path, block_size=block_size)

    drive.last_change = timezone.now()
    drive.save(update_fields=['last_change'])

    return None
Exemplo n.º 3
0
    def run(self, medium=None, path='.', block_size=DEFAULT_TAPE_BLOCK_SIZE):
        """
        Reads the tape in the given drive
        """

        try:
            drive = TapeDrive.objects.get(storage_medium__pk=medium)
        except TapeDrive.DoesNotExist:
            raise ValueError("Tape not mounted")

        return read_tape(drive.device, path=path, block_size=block_size)
Exemplo n.º 4
0
    def verify(self):
        if self.content_location_type == TAPE:
            verifydir = Path.objects.get(entity='verify').value
            tmppath = os.path.join(verifydir,
                                   self.storage_medium.storage_target.target)

            if not os.path.exists(tmppath):
                try:
                    os.mkdir(tmppath)
                except OSError as e:
                    if e.errno != errno.EEXIST:
                        raise

            drive = self.storage_medium.tape_drive
            if drive is None:
                raise ValueError("Tape not mounted")

            set_tape_file_number(drive.device,
                                 int(self.content_location_value))
            read_tape(drive.device,
                      path=tmppath,
                      block_size=self.storage_medium.block_size * 512)

            drive.last_change = timezone.now()
            drive.save(update_fields=['last_change'])

            filename = os.path.join(tmppath,
                                    self.ip.object_identifier_value + '.tar'),
            algorithm = self.ip.get_message_digest_algorithm_display()
            options = {
                'expected': self.ip.message_digest,
                'algorithm': algorithm
            }

            validator = ChecksumValidator(context='checksum_str',
                                          options=options)
            validator.validate(filename)