Ejemplo n.º 1
0
def CompareRepresentationXMLFiles(self):
    Validation.objects.filter(task=self.get_processtask()).delete()
    ip = InformationPackage.objects.get(pk=self.ip)

    reps_path, reps_dir = find_destination("representations", ip.get_structure(), ip.object_path)
    if reps_path is None:
        return None

    representations_dir = os.path.join(reps_path, reps_dir)

    for p in find_pointers(os.path.join(ip.object_path, ip.content_mets_path)):
        rep_mets_path = p.path
        rep_mets_path = os.path.join(ip.object_path, rep_mets_path)
        rep_path = os.path.relpath(rep_mets_path, representations_dir)
        rep_path = PurePath(rep_path).parts[0]

        rep_premis_path = get_premis_ref(etree.parse(rep_mets_path)).path
        rep_premis_path = os.path.join(representations_dir, rep_path, rep_premis_path)

        validator = XMLComparisonValidator(
            context=rep_premis_path,
            options={
                'rootdir': os.path.join(representations_dir, rep_path),
                'representation': rep_path,
                'recursive': False,
            },
            task=self.get_processtask(),
            ip=self.ip,
            responsible=ip.responsible,
        )
        validator.validate(rep_mets_path)

    msg = "All XML files in the representations have the same set of files"
    self.create_success_event(msg)
Ejemplo n.º 2
0
    def run(self):
        Validation.objects.filter(task=self.get_processtask()).delete()
        ip = InformationPackage.objects.get(pk=self.ip)

        reps_path, reps_dir = find_destination("representations", ip.get_structure(), ip.object_path)
        if reps_path is None:
            return None

        representations_dir = os.path.join(reps_path, reps_dir)

        for p in find_pointers(ip.content_mets_path):
            rep_mets_path = p.path
            rep_mets_path = os.path.join(ip.object_path, rep_mets_path)
            rep_path = os.path.relpath(rep_mets_path, representations_dir)
            rep_path = PurePath(rep_path).parts[0]

            rep_premis_path = get_premis_ref(etree.parse(rep_mets_path)).path
            rep_premis_path = os.path.join(representations_dir, rep_path, rep_premis_path)

            validator = XMLComparisonValidator(
                context=rep_premis_path,
                options={
                    'rootdir': os.path.join(representations_dir, rep_path),
                    'representation': rep_path,
                },
                task=self.get_processtask(),
                ip=self.ip,
                responsible=ip.responsible,
            )
            validator.validate(rep_mets_path)
Ejemplo n.º 3
0
    def validate(self, path, expected=None):
        xmlfile = self.context
        objs = []
        self._reset_dicts()
        self._reset_counters()
        logger.debug(u'Validating {path} against {xml}'.format(path=path,
                                                               xml=xmlfile))
        checksum_in_context_file = self.checksums.get(path)

        if checksum_in_context_file:
            try:
                self._pop_checksum_dict(self.deleted, checksum_in_context_file,
                                        path)
                self._pop_checksum_dict(self.present, checksum_in_context_file,
                                        path)
            except (KeyError, ValueError):
                pass

        skip_files = [os.path.relpath(xmlfile, self.rootdir)]
        skip_files.extend([p.path for p in find_pointers(path)])
        skip_files = list(map(normalize_path, skip_files))
        for f in find_files(path, rootdir=self.rootdir, skip_files=skip_files):
            if f in self.exclude:
                continue
            objs.append(self._validate(f))

        delete_count = self._validate_deleted_files(objs)
        self._validate_present_files(objs)

        if checksum_in_context_file:
            try:
                self.deleted[checksum_in_context_file].append(path)
            except KeyError:
                self.deleted[checksum_in_context_file] = [path]

            try:
                self.present[checksum_in_context_file].append(path)
            except KeyError:
                self.present[checksum_in_context_file] = [path]

        objs = [o for o in objs if o is not None]
        Validation.objects.bulk_create(objs, batch_size=100)

        if delete_count + self.added + self.changed + self.renamed > 0:
            msg = (
                'Comparison of {path} against {xml} failed: '
                '{cfmd} confirmed, {a} added, {c} changed, {r} renamed, {d} deleted'
            ).format(path=path,
                     xml=self.context,
                     cfmd=self.confirmed,
                     a=self.added,
                     c=self.changed,
                     r=self.renamed,
                     d=delete_count)
            logger.warning(msg)
            raise ValidationError(msg)

        logger.info(u"Successful comparison of {path} against {xml}".format(
            path=path, xml=self.context))
Ejemplo n.º 4
0
 def _get_files(self):
     skip_files = [p.path for p in find_pointers(self.context)]
     self.logical_files = find_files(
         self.context,
         rootdir=self.rootdir,
         skip_files=skip_files,
         recursive=self.recursive,
     )