def _save_package(self, path, ownerid): meta = self._get_meta(path) try: # can't use get_or_create as that demands there be an owner package = Package.objects.get(name=meta.name) isnewpackage = False except Package.DoesNotExist: package = Package(name=meta.name) isnewpackage = True release = package.get_release(meta.version) if not isnewpackage and release and release.version == meta.version: print "%s-%s already added" % (meta.name, meta.version) return # algorithm as follows: If owner is given, try to grab user with that # username from db. If doesn't exist, bail. If no owner set look at # mail address from metadata and try to get that user. If it exists # use it. If not, bail. owner = None if ownerid: try: if "@" in ownerid: owner = User.objects.get(email=ownerid) else: owner = User.objects.get(username=ownerid) except User.DoesNotExist: pass else: try: owner = User.objects.get(email=meta.author_email) except User.DoesNotExist: pass if not owner: print "No owner defined. Use --owner to force one" return # at this point we have metadata and an owner, can safely add it. package.owner = owner # Some packages don't have proper licence, seems to be a problem # with setup.py upload. Use "UNKNOWN" package.license = meta.license or "Unknown" package.metadata_version = meta.metadata_version package.author = meta.author package.home_page = meta.home_page package.download_url = meta.download_url package.summary = meta.summary package.description = meta.description package.author_email = meta.author_email package.save() for classifier in meta.classifiers: package.classifiers.add( Classifier.objects.get_or_create(name=classifier)[0]) release = Release() release.version = meta.version release.package = package filename = os.path.basename(path) file = File(open(path, "rb")) release.distribution.save(filename, file) release.save() print "%s-%s added" % (meta.name, meta.version)
def _save_package(self, path, ownerid): meta = self._get_meta(path) try: # can't use get_or_create as that demands there be an owner package = Package.objects.get(name=meta.name) isnewpackage = False except Package.DoesNotExist: package = Package(name=meta.name) isnewpackage = True release = package.get_release(meta.version) if not isnewpackage and release and release.version == meta.version: print "%s-%s already added" % (meta.name, meta.version) return # algorithm as follows: If owner is given, try to grab user with that # username from db. If doesn't exist, bail. If no owner set look at # mail address from metadata and try to get that user. If it exists # use it. If not, bail. owner = None if ownerid: try: if "@" in ownerid: owner = User.objects.get(email=ownerid) else: owner = User.objects.get(username=ownerid) except User.DoesNotExist: pass else: try: owner = User.objects.get(email=meta.author_email) except User.DoesNotExist: pass if not owner: print "No owner defined. Use --owner to force one" return # at this point we have metadata and an owner, can safely add it. package.save() package.owners.add(owner) package.maintainers.add(owner) for classifier in meta.classifiers: package.classifiers.add( Classifier.objects.get_or_create(name=classifier)[0]) release = Release() release.version = meta.version release.package = package release.metadata_version = meta.metadata_version package_info = MultiValueDict() package_info.update(meta.__dict__) release.package_info = package_info release.save() file = File(open(path, "rb")) if isinstance(meta, pkginfo.SDist): dist = 'sdist' elif meta.filename.endswith('.rmp') or meta.filename.endswith('.srmp'): dist = 'bdist_rpm' elif meta.filename.endswith('.exe'): dist = 'bdist_wininst' elif meta.filename.endswith('.egg'): dist = 'bdist_egg' elif meta.filename.endswith('.dmg'): dist = 'bdist_dmg' else: dist = 'bdist_dumb' release.distributions.create(content=file, uploader=owner, filetype=dist) print "%s-%s added" % (meta.name, meta.version)
def _save_package(self, path, ownerid): meta = self._get_meta(path) try: # can't use get_or_create as that demands there be an owner package = Package.objects.get(name=meta.name) isnewpackage = False except Package.DoesNotExist: package = Package(name=meta.name) isnewpackage = True release = package.get_release(meta.version) if not isnewpackage and release and release.version == meta.version: print "%s-%s already added" % (meta.name, meta.version) return # algorithm as follows: If owner is given, try to grab user with that # username from db. If doesn't exist, bail. If no owner set look at # mail address from metadata and try to get that user. If it exists # use it. If not, bail. owner = None if ownerid: try: if "@" in ownerid: owner = User.objects.get(email=ownerid) else: owner = User.objects.get(username=ownerid) except User.DoesNotExist: pass else: try: owner = User.objects.get(email=meta.author_email) except User.DoesNotExist: pass if not owner: print "No owner defined. Use --owner to force one" return # at this point we have metadata and an owner, can safely add it. package.save() package.owners.add(owner) package.maintainers.add(owner) release = Release() release.version = meta.version release.package = package release.metadata_version = meta.metadata_version package_info = MultiValueDict() package_info.update(meta.__dict__) release.package_info = package_info release.save() file = File(open(path, "rb")) if isinstance(meta, pkginfo.SDist): dist = 'sdist' elif meta.filename.endswith('.rmp') or meta.filename.endswith('.srmp'): dist = 'bdist_rpm' elif meta.filename.endswith('.exe'): dist = 'bdist_wininst' elif meta.filename.endswith('.egg'): dist = 'bdist_egg' elif meta.filename.endswith('.dmg'): dist = 'bdist_dmg' else: dist = 'bdist_dumb' release.distributions.create(content=file, uploader=owner, filetype=dist) print "%s-%s added" % (meta.name, meta.version)
def _save_package(self, path, ownerid): meta = self._get_meta(path) try: # can't use get_or_create as that demands there be an owner package = Package.objects.get(name=meta.name) isnewpackage = False except Package.DoesNotExist: package = Package(name=meta.name) isnewpackage = True release = package.get_release(meta.version) if not isnewpackage and release and release.version == meta.version: print "%s-%s already added" % (meta.name, meta.version) return # algorithm as follows: If owner is given, try to grab user with that # username from db. If doesn't exist, bail. If no owner set look at # mail address from metadata and try to get that user. If it exists # use it. If not, bail. owner = None if ownerid: try: if "@" in ownerid: owner = User.objects.get(email=ownerid) else: owner = User.objects.get(username=ownerid) except User.DoesNotExist: pass else: try: owner = User.objects.get(email=meta.author_email) except User.DoesNotExist: pass if not owner: print "No owner defined. Use --owner to force one" return # at this point we have metadata and an owner, can safely add it. package.owner = owner # Some packages don't have proper licence, seems to be a problem # with setup.py upload. Use "UNKNOWN" package.license = meta.license or "Unknown" package.metadata_version = meta.metadata_version package.author = meta.author package.home_page = meta.home_page package.download_url = meta.download_url package.summary = meta.summary package.description = meta.description package.author_email = meta.author_email package.save() # TODO: Do I need add classifieres objects??? # for classifier in meta.classifiers: # package.classifiers.add( # Classifier.objects.get_or_create(name=classifier)[0]) release = Release() release.version = meta.version release.package = package release.package_info = self._get_pkg_info(meta) # Classifiers is processed separatily since it is a list a must be # properly set son getlist returns the right result for cs in meta.classifiers: release.package_info.update({'classifiers': cs}) release.save() dis = Distribution() dis.release = release dis.content.file = open(path, 'rb') dis.content.name = settings.DJANGOPYPI_RELEASE_UPLOAD_TO + '/' +\ path.split('/')[-1] # TODO: Very bad hack here, how can I fix it? shutil.copy(path, settings.MEDIA_ROOT + '/' + dis.content.name) dis.md5_digest = self._get_md5(path) dis.filetype = self._get_filetype(path) dis.uploader = owner dis.comment = '' dis.pyversion = meta.requires_python or '' dis.signature = '' dis.save() print "%s-%s added" % (meta.name, meta.version)