def _getSource(self, sourcepackagename, version, distroseries): """Returns a sourcepackagerelease by its name and version.""" # XXX kiko 2005-11-05: we use the source package publishing tables # here, but I think that's a bit flawed. We should have a way of # saying "my distroseries overlays the version namespace of that # distroseries" and use that to decide on whether we've seen # this package before or not. The publishing tables may be # wrong, for instance, in the context of proper derivation. # Check here to see if this release has ever been published in # the distribution, no matter what status. query = """ SourcePackageRelease.sourcepackagename = %s AND SourcePackageRelease.version = %s AND SourcePackagePublishingHistory.sourcepackagerelease = SourcePackageRelease.id AND SourcePackagePublishingHistory.distroseries = DistroSeries.id AND SourcePackagePublishingHistory.archive = %s AND DistroSeries.distribution = %s """ % sqlvalues(sourcepackagename, version, distroseries.main_archive, distroseries.distribution) ret = SourcePackageRelease.select( query, clauseTables=['SourcePackagePublishingHistory', 'DistroSeries'], orderBy=["-SourcePackagePublishingHistory.datecreated"]) if not ret: return None return ret[0]
def _getSource(self, sourcepackagename, version, distroseries): """Returns a sourcepackagerelease by its name and version.""" # XXX kiko 2005-11-05: we use the source package publishing tables # here, but I think that's a bit flawed. We should have a way of # saying "my distroseries overlays the version namespace of that # distroseries" and use that to decide on whether we've seen # this package before or not. The publishing tables may be # wrong, for instance, in the context of proper derivation. # Check here to see if this release has ever been published in # the distribution, no matter what status. query = """ SourcePackageRelease.sourcepackagename = %s AND SourcePackageRelease.version = %s AND SourcePackagePublishingHistory.sourcepackagerelease = SourcePackageRelease.id AND SourcePackagePublishingHistory.distroseries = DistroSeries.id AND SourcePackagePublishingHistory.archive = %s AND DistroSeries.distribution = %s """ % sqlvalues(sourcepackagename, version, distroseries.main_archive, distroseries.distribution) ret = SourcePackageRelease.select(query, clauseTables=['SourcePackagePublishingHistory', 'DistroSeries'], orderBy=["-SourcePackagePublishingHistory.datecreated"]) if not ret: return None return ret[0]
def decorate(spr_ids): # Find the SPPHs for each SPR in our result. load(SourcePackageRelease, spr_ids) sprs = [SourcePackageRelease.get(spr_id) for spr_id in spr_ids] pubs = DistributionSourcePackageRelease.getPublishingHistories( self.distribution, sprs) sprs_by_id = dict((spr, list(pubs)) for (spr, pubs) in itertools.groupby( pubs, attrgetter('sourcepackagereleaseID'))) return [(DistributionSourcePackageRelease( distribution=self.distribution, sourcepackagerelease=spr), sprs_by_id[spr.id]) for spr in sprs]
def createSourcePackageRelease(self, src, distroseries): """Create a SourcePackagerelease and db dependencies if needed. Returns the created SourcePackageRelease, or None if it failed. """ displayname, emailaddress = src.maintainer comment = 'when the %s package was imported into %s' % ( src.package, distroseries.displayname) maintainer = getUtility(IPersonSet).ensurePerson( emailaddress, displayname, PersonCreationRationale.SOURCEPACKAGEIMPORT, comment=comment) # XXX Debonzi 2005-05-16: Check it later. # if src.dsc_signing_key_owner: # key = self.getGPGKey(src.dsc_signing_key, # *src.dsc_signing_key_owner) # else: key = None to_upload = check_not_in_librarian(src.files, src.archive_root, src.directory) # Create the SourcePackageRelease (SPR) componentID = self.distro_handler.getComponentByName(src.component).id sectionID = self.distro_handler.ensureSection(src.section).id maintainer_line = "%s <%s>" % (displayname, emailaddress) name = self.ensureSourcePackageName(src.package) spr = SourcePackageRelease( section=sectionID, creator=maintainer.id, component=componentID, sourcepackagename=name.id, maintainer=maintainer.id, dscsigningkey=key, urgency=ChangesFile.urgency_map[src.urgency], dateuploaded=src.date_uploaded, dsc=src.dsc, copyright=src.copyright, version=src.version, changelog_entry=src.changelog_entry, builddepends=src.build_depends, builddependsindep=src.build_depends_indep, build_conflicts=src.build_conflicts, build_conflicts_indep=src.build_conflicts_indep, architecturehintlist=src.architecture, format=SourcePackageType.DPKG, upload_distroseries=distroseries.id, dsc_format=src.format, dsc_maintainer_rfc822=maintainer_line, dsc_standards_version=src.standards_version, dsc_binaries=", ".join(src.binaries), upload_archive=distroseries.main_archive) log.info('Source Package Release %s (%s) created' % (name.name, src.version)) # Upload the changelog to the Librarian if src.changelog is not None: changelog_lfa = getUtility(ILibraryFileAliasSet).create( "changelog", len(src.changelog), StringIO(src.changelog), "text/x-debian-source-changelog") spr.changelog = changelog_lfa # Insert file into the library and create the # SourcePackageReleaseFile entry on lp db. for fname, path in to_upload: alias = getLibraryAlias(path, fname) SourcePackageReleaseFile( sourcepackagerelease=spr.id, libraryfile=alias, filetype=determine_source_file_type(fname)) log.info('Package file %s included into library' % fname) return spr
def _update(cls, distro, sourcepackagename, archive, log): """Update cached source package details. Update cache details for a given ISourcePackageName, including generated binarypackage names, summary and description fti. 'log' is required and only prints debug level information. """ # Get the set of published sourcepackage releases. sprs = list(SourcePackageRelease.select(""" SourcePackageRelease.id = SourcePackagePublishingHistory.sourcepackagerelease AND SourcePackagePublishingHistory.sourcepackagename = %s AND SourcePackagePublishingHistory.distroseries = DistroSeries.id AND DistroSeries.distribution = %s AND SourcePackagePublishingHistory.archive = %s AND SourcePackagePublishingHistory.dateremoved is NULL """ % sqlvalues(sourcepackagename, distro, archive), orderBy='id', clauseTables=['SourcePackagePublishingHistory', 'DistroSeries'], distinct=True)) if len(sprs) == 0: log.debug("No sources releases found.") return # Find or create the cache entry. cache = DistributionSourcePackageCache.selectOne(""" distribution = %s AND archive = %s AND sourcepackagename = %s """ % sqlvalues(distro, archive, sourcepackagename)) if cache is None: log.debug("Creating new source cache entry.") cache = DistributionSourcePackageCache( archive=archive, distribution=distro, sourcepackagename=sourcepackagename) # Make sure the name is correct. cache.name = sourcepackagename.name # Get the sets of binary package names, summaries, descriptions. # XXX Julian 2007-04-03: # This bit of code needs fixing up, it is doing stuff that # really needs to be done in SQL, such as sorting and uniqueness. # This would also improve the performance. binpkgnames = set() binpkgsummaries = set() binpkgdescriptions = set() sprchangelog = set() for spr in sprs: log.debug("Considering source version %s" % spr.version) # changelog may be empty, in which case we don't want to add it # to the set as the join would fail below. if spr.changelog_entry is not None: sprchangelog.add(spr.changelog_entry) binpkgs = BinaryPackageRelease.select(""" BinaryPackageRelease.build = BinaryPackageBuild.id AND BinaryPackageBuild.source_package_release = %s """ % sqlvalues(spr.id), clauseTables=['BinaryPackageBuild']) for binpkg in binpkgs: log.debug("Considering binary '%s'" % binpkg.name) binpkgnames.add(binpkg.name) binpkgsummaries.add(binpkg.summary) binpkgdescriptions.add(binpkg.description) # Update the caches. cache.binpkgnames = ' '.join(sorted(binpkgnames)) cache.binpkgsummaries = ' '.join(sorted(binpkgsummaries)) cache.binpkgdescriptions = ' '.join(sorted(binpkgdescriptions)) cache.changelog = ' '.join(sorted(sprchangelog))
def sourcepackagerelease(self): return SourcePackageRelease.get(self.sourcepackagerelease_id)
def createSourcePackageRelease(self, src, distroseries): """Create a SourcePackagerelease and db dependencies if needed. Returns the created SourcePackageRelease, or None if it failed. """ displayname, emailaddress = src.maintainer comment = 'when the %s package was imported into %s' % ( src.package, distroseries.displayname) maintainer = getUtility(IPersonSet).ensurePerson( emailaddress, displayname, PersonCreationRationale.SOURCEPACKAGEIMPORT, comment=comment) # XXX Debonzi 2005-05-16: Check it later. # if src.dsc_signing_key_owner: # key = self.getGPGKey(src.dsc_signing_key, # *src.dsc_signing_key_owner) # else: key = None to_upload = check_not_in_librarian(src.files, src.archive_root, src.directory) # Create the SourcePackageRelease (SPR) componentID = self.distro_handler.getComponentByName(src.component).id sectionID = self.distro_handler.ensureSection(src.section).id maintainer_line = "%s <%s>" % (displayname, emailaddress) name = self.ensureSourcePackageName(src.package) spr = SourcePackageRelease( section=sectionID, creator=maintainer.id, component=componentID, sourcepackagename=name.id, maintainer=maintainer.id, dscsigningkey=key, urgency=ChangesFile.urgency_map[src.urgency], dateuploaded=src.date_uploaded, dsc=src.dsc, copyright=src.copyright, version=src.version, changelog_entry=src.changelog_entry, builddepends=src.build_depends, builddependsindep=src.build_depends_indep, build_conflicts=src.build_conflicts, build_conflicts_indep=src.build_conflicts_indep, architecturehintlist=src.architecture, format=SourcePackageType.DPKG, upload_distroseries=distroseries.id, dsc_format=src.format, dsc_maintainer_rfc822=maintainer_line, dsc_standards_version=src.standards_version, dsc_binaries=", ".join(src.binaries), upload_archive=distroseries.main_archive) log.info('Source Package Release %s (%s) created' % (name.name, src.version)) # Upload the changelog to the Librarian if src.changelog is not None: changelog_lfa = getUtility(ILibraryFileAliasSet).create( "changelog", len(src.changelog), StringIO(src.changelog), "text/x-debian-source-changelog") spr.changelog = changelog_lfa # Insert file into the library and create the # SourcePackageReleaseFile entry on lp db. for fname, path in to_upload: alias = getLibraryAlias(path, fname) SourcePackageReleaseFile( sourcepackagerelease=spr.id, libraryfile=alias, filetype=determine_source_file_type(fname)) log.info('Package file %s included into library' % fname) return spr