def store(self):
        package, _ = Package.objects.get_or_create(name=self.name)

        for data in self.data.values():
            try:
                release = Release.objects.get(package=package, version=data["version"])
            except Release.DoesNotExist:
                release = Release(package=package, version=data["version"])
                release.full_clean()
                release.save()

            # This is an extra database call but it should prevent ShareLocks
            Release.objects.filter(pk=release.pk).select_for_update()

            if release.hidden:
                release.hidden = False

            for key, value in data.iteritems():
                if key in ["package", "version"]:
                    # Short circuit package and version
                    continue

                if key == "uris":
                    ReleaseURI.objects.filter(release=release).delete()
                    for label, uri in value.iteritems():
                        try:
                            ReleaseURI.objects.get(release=release, label=label, uri=uri)
                        except ReleaseURI.DoesNotExist:
                            try:
                                release_uri = ReleaseURI(release=release, label=label, uri=uri)
                                release_uri.full_clean()
                                release_uri.save(force_insert=True)
                            except __HOLE__:
                                logger.exception("%s, %s for %s-%s Invalid Data" % (label, uri, release.package.name, release.version))
                elif key == "classifiers":
                    release.classifiers.clear()
                    for classifier in value:
                        try:
                            trove = TroveClassifier.objects.get(trove=classifier)
                        except TroveClassifier.DoesNotExist:
                            trove = TroveClassifier(trove=classifier)
                            trove.full_clean()
                            trove.save(force_insert=True)
                        release.classifiers.add(trove)
                elif key in ["requires", "provides", "obsoletes"]:
                    model = {"requires": ReleaseRequire, "provides": ReleaseProvide, "obsoletes": ReleaseObsolete}.get(key)
                    model.objects.filter(release=release).delete()
                    for item in value:
                        try:
                            model.objects.get(release=release, **item)
                        except model.DoesNotExist:
                            m = model(release=release, **item)
                            m.full_clean()
                            m.save(force_insert=True)
                elif key == "files":
                    files = ReleaseFile.objects.filter(release=release)
                    filenames = dict([(x.filename, x) for x in files])

                    for f in value:
                        try:
                            rf = ReleaseFile.objects.get(
                                    release=release,
                                    type=f["type"],
                                    filename=f["filename"],
                                    python_version=f["python_version"],
                                )

                            for k, v in f.iteritems():
                                if k in ["digests", "file", "filename", "type", "python_version"]:
                                    continue
                                setattr(rf, k, v)

                            rf.hidden = False
                            rf.full_clean()
                            rf.save()

                        except ReleaseFile.DoesNotExist:
                            rf = ReleaseFile(
                                    release=release,
                                    type=f["type"],
                                    filename=f["filename"],
                                    python_version=f["python_version"],
                                    **dict([(k, v) for k, v in f.iteritems() if k not in ["digests", "file", "filename", "type", "python_version"]])
                                )

                            rf.hidden = False
                            rf.full_clean()
                            rf.save()

                        if f["filename"] in filenames.keys():
                            del filenames[f["filename"]]

                    if filenames:
                        for rf in ReleaseFile.objects.filter(pk__in=[f.pk for f in filenames.values()]):
                            rf.hidden = True
                            rf.save()
                else:
                    setattr(release, key, value)

            while True:
                try:
                    release.full_clean()
                except ValidationError as e:
                    if "download_uri" in e.message_dict:
                        release.download_uri = ""
                        logger.exception("%s-%s Release Validation Error %s" % (release.package.name, release.version, str(e.message_dict)))
                    else:
                        raise
                else:
                    break
            release.save()

        # Mark unsynced as deleted when bulk processing
        if self.bulk:
            for release in Release.objects.filter(package=package).exclude(version__in=self.data.keys()):
                release.hidden = True
                release.save()

        self.stored = True
dataset/ETHPy150Open crate-archive/crate-site/crateweb/apps/pypi/processor.py/PyPIPackage.store