def run(self): """See `IRunnableJob`.""" requester = self.requester if requester is None: log.info("Skipping %r because the requester has been deleted." % self) return archive = self.archive if archive is None: log.info("Skipping %r because the archive has been deleted." % self) return try: self.builds = self.snap.requestBuildsFromJob( requester, archive, self.pocket, channels=self.channels, build_request=self.build_request, logger=log) self.error_message = None except self.retry_error_types: raise except Exception as e: self.error_message = str(e) # The normal job infrastructure will abort the transaction, but # we want to commit instead: the only database changes we make # are to this job's metadata and should be preserved. transaction.commit() raise
def run(self): """See `IGitRefScanJob`.""" try: with try_advisory_lock( LockType.GIT_REF_SCAN, self.repository.id, Store.of(self.repository)): hosting_path = self.repository.getInternalPath() refs_to_upsert, refs_to_remove = ( self.repository.planRefChanges(hosting_path, logger=log)) self.repository.fetchRefCommits( hosting_path, refs_to_upsert, logger=log) # The webhook delivery includes old ref information, so # prepare it before we actually execute the changes. if getFeatureFlag('code.git.webhooks.enabled'): payload = self.composeWebhookPayload( self.repository, refs_to_upsert, refs_to_remove) getUtility(IWebhookSet).trigger( self.repository, 'git:push:0.1', payload) self.repository.synchroniseRefs( refs_to_upsert, refs_to_remove, logger=log) props = getUtility(IGitHostingClient).getProperties( hosting_path) # We don't want ref canonicalisation, nor do we want to send # this change back to the hosting service. removeSecurityProxy(self.repository)._default_branch = ( props["default_branch"]) except LostObjectError: log.info( "Skipping repository %s because it has been deleted." % self._cached_repository_name)
def import_sourcepackages(distro, packages_map, package_root, importer_handler): # Goes over src_map importing the sourcepackages packages. npacks = len(packages_map.src_map) log.info("%i Source Packages to be imported", npacks) for package in sorted(packages_map.src_map.iterkeys()): for source in packages_map.src_map[package]: attempt_source_package_import(distro, source, package_root, importer_handler)
def do_one_binarypackage(distro, binary, archtag, package_root, importer_handler): binary_data = BinaryPackageData(**binary) if importer_handler.preimport_binarycheck(archtag, binary_data): log.info("%s already exists in the archive", binary_data.package) return binary_data.process_package(distro, package_root) importer_handler.import_binarypackage(archtag, binary_data) importer_handler.commit()
def do_one_binarypackage(distro, binary, archtag, package_root, importer_handler): binary_data = BinaryPackageData(**binary) if importer_handler.preimport_binarycheck(archtag, binary_data): log.info('%s already exists in the archive', binary_data.package) return binary_data.process_package(distro, package_root) importer_handler.import_binarypackage(archtag, binary_data) importer_handler.commit()
def import_sourcepackages(distro, packages_map, package_root, importer_handler): # Goes over src_map importing the sourcepackages packages. npacks = len(packages_map.src_map) log.info('%i Source Packages to be imported', npacks) for package in sorted(packages_map.src_map.iterkeys()): for source in packages_map.src_map[package]: attempt_source_package_import(distro, source, package_root, importer_handler)
def import_binarypackages(distro, packages_map, package_root, importer_handler): nosource = [] # Run over all the architectures we have for archtag in packages_map.bin_map.keys(): npacks = len(packages_map.bin_map[archtag]) log.info('%i Binary Packages to be imported for %s', npacks, archtag) # Go over binarypackages importing them for this architecture for package_name in sorted(packages_map.bin_map[archtag].iterkeys()): binary = packages_map.bin_map[archtag][package_name] try: try: do_one_binarypackage(distro, binary, archtag, package_root, importer_handler) except psycopg2.Error: log.exception( "Database errors when importing a BinaryPackage " "for %s. Retrying once..", package_name) importer_handler.abort() time.sleep(15) do_one_binarypackage(distro, binary, archtag, package_root, importer_handler) except (InvalidVersionError, MissingRequiredArguments): log.exception("Unable to create BinaryPackageData for %s", package_name) continue except (PoolFileNotFound, ExecutionError): # Problems with katie db stuff of opening files log.exception("Error processing package files for %s", package_name) continue except MultiplePackageReleaseError: log.exception("Database duplication processing %s", package_name) continue except psycopg2.Error: log.exception( "Database errors made me give up: unable to create " "BinaryPackage for %s", package_name) importer_handler.abort() continue except NoSourcePackageError: log.exception("Failed to create Binary Package for %s", package_name) nosource.append(binary) continue if nosource: # XXX kiko 2005-10-23: untested log.warn('%i source packages not found', len(nosource)) for pkg in nosource: log.warn(pkg)
def createBinaryPackage(self, bin, srcpkg, distroarchinfo, archtag): """Create a new binarypackage.""" fdir, fname = os.path.split(bin.filename) to_upload = check_not_in_librarian(fname, bin.archive_root, fdir) fname, path = to_upload[0] componentID = self.distro_handler.getComponentByName(bin.component).id sectionID = self.distro_handler.ensureSection(bin.section).id architecturespecific = (bin.architecture != "all") bin_name = getUtility(IBinaryPackageNameSet).ensure(bin.package) build = self.ensureBuild(bin, srcpkg, distroarchinfo, archtag) # Create the binarypackage entry on lp db. binpkg = BinaryPackageRelease( binarypackagename=bin_name.id, component=componentID, version=bin.version, description=bin.description, summary=bin.summary, build=build.id, binpackageformat=getBinaryPackageFormat(bin.filename), section=sectionID, priority=prioritymap[bin.priority], shlibdeps=bin.shlibs, depends=bin.depends, suggests=bin.suggests, recommends=bin.recommends, conflicts=bin.conflicts, replaces=bin.replaces, provides=bin.provides, pre_depends=bin.pre_depends, enhances=bin.enhances, breaks=bin.breaks, essential=bin.essential, installedsize=bin.installed_size, architecturespecific=architecturespecific, ) log.info('Binary Package Release %s (%s) created' % (bin_name.name, bin.version)) alias = getLibraryAlias(path, fname) BinaryPackageFile( binarypackagerelease=binpkg.id, libraryfile=alias, filetype=determine_binary_file_type(fname)) log.info('Package file %s included into library' % fname) # Return the binarypackage object. return binpkg
def createBinaryPackage(self, bin, srcpkg, distroarchinfo, archtag): """Create a new binarypackage.""" fdir, fname = os.path.split(bin.filename) to_upload = check_not_in_librarian(fname, bin.archive_root, fdir) fname, path = to_upload[0] componentID = self.distro_handler.getComponentByName(bin.component).id sectionID = self.distro_handler.ensureSection(bin.section).id architecturespecific = (bin.architecture != "all") bin_name = getUtility(IBinaryPackageNameSet).ensure(bin.package) build = self.ensureBuild(bin, srcpkg, distroarchinfo, archtag) # Create the binarypackage entry on lp db. binpkg = BinaryPackageRelease( binarypackagename=bin_name.id, component=componentID, version=bin.version, description=bin.description, summary=bin.summary, build=build.id, binpackageformat=getBinaryPackageFormat(bin.filename), section=sectionID, priority=prioritymap[bin.priority], shlibdeps=bin.shlibs, depends=bin.depends, suggests=bin.suggests, recommends=bin.recommends, conflicts=bin.conflicts, replaces=bin.replaces, provides=bin.provides, pre_depends=bin.pre_depends, enhances=bin.enhances, breaks=bin.breaks, essential=bin.essential, installedsize=bin.installed_size, architecturespecific=architecturespecific, ) log.info('Binary Package Release %s (%s) created' % (bin_name.name, bin.version)) alias = getLibraryAlias(path, fname) BinaryPackageFile(binarypackagerelease=binpkg.id, libraryfile=alias, filetype=determine_binary_file_type(fname)) log.info('Package file %s included into library' % fname) # Return the binarypackage object. return binpkg
def do_one_sourcepackage(distro, source, package_root, importer_handler): source_data = SourcePackageData(**source) skip_key = u"%s/%s/%s" % (distro, source_data.package, source_data.version) skip_list = getFeatureFlag("soyuz.gina.skip_source_versions") if skip_list is not None and skip_key in skip_list.split(): log.info("Skipping %s %s as requested by feature flag.", source_data.package, source_data.version) return if importer_handler.preimport_sourcecheck(source_data): # Don't bother reading package information if the source package # already exists in the database log.info("%s already exists in the archive", source_data.package) return source_data.process_package(distro, package_root) source_data.ensure_complete() importer_handler.import_sourcepackage(source_data) importer_handler.commit()
def do_one_sourcepackage(distro, source, package_root, importer_handler): source_data = SourcePackageData(**source) skip_key = u'%s/%s/%s' % (distro, source_data.package, source_data.version) skip_list = getFeatureFlag('soyuz.gina.skip_source_versions') if skip_list is not None and skip_key in skip_list.split(): log.info("Skipping %s %s as requested by feature flag.", source_data.package, source_data.version) return if importer_handler.preimport_sourcecheck(source_data): # Don't bother reading package information if the source package # already exists in the database log.info('%s already exists in the archive', source_data.package) return source_data.process_package(distro, package_root) source_data.ensure_complete() importer_handler.import_sourcepackage(source_data) importer_handler.commit()
def import_binarypackages(distro, packages_map, package_root, importer_handler): nosource = [] # Run over all the architectures we have for archtag in packages_map.bin_map.keys(): npacks = len(packages_map.bin_map[archtag]) log.info("%i Binary Packages to be imported for %s", npacks, archtag) # Go over binarypackages importing them for this architecture for package_name in sorted(packages_map.bin_map[archtag].iterkeys()): binary = packages_map.bin_map[archtag][package_name] try: try: do_one_binarypackage(distro, binary, archtag, package_root, importer_handler) except psycopg2.Error: log.exception( "Database errors when importing a BinaryPackage " "for %s. Retrying once..", package_name ) importer_handler.abort() time.sleep(15) do_one_binarypackage(distro, binary, archtag, package_root, importer_handler) except (InvalidVersionError, MissingRequiredArguments): log.exception("Unable to create BinaryPackageData for %s", package_name) continue except (PoolFileNotFound, ExecutionError): # Problems with katie db stuff of opening files log.exception("Error processing package files for %s", package_name) continue except MultiplePackageReleaseError: log.exception("Database duplication processing %s", package_name) continue except psycopg2.Error: log.exception("Database errors made me give up: unable to create " "BinaryPackage for %s", package_name) importer_handler.abort() continue except NoSourcePackageError: log.exception("Failed to create Binary Package for %s", package_name) nosource.append(binary) continue if nosource: # XXX kiko 2005-10-23: untested log.warn("%i source packages not found", len(nosource)) for pkg in nosource: log.warn(pkg)
def publish(self, binarypackage, bpdata): """Create the publishing entry on db if does not exist.""" # These need to be pulled from the binary package data, not the # binary package release: the data represents data from /this # specific distroseries/, whereas the package represents data # from when it was first built. if self.component_override is not None: component = self.distro_handler.getComponentByName( self.component_override) log.info('Overriding binary %s component' % binarypackage.binarypackagename.name) else: component = self.distro_handler.getComponentByName( bpdata.component) distribution = self.distroarchseries.distroseries.distribution archive = distribution.getArchiveByComponent(component.name) section = self.distro_handler.ensureSection(bpdata.section) priority = prioritymap[bpdata.priority] # Check if the binarypackage is already published and if yes, # just report it. binpkg_publishinghistory = self._checkPublishing(binarypackage) if binpkg_publishinghistory: if ((binpkg_publishinghistory.section, binpkg_publishinghistory.priority, binpkg_publishinghistory.component) == (section, priority, component)): # If nothing has changed in terms of publication # (overrides) we are free to let this one go log.info('BinaryPackageRelease already published with no ' 'changes as %s' % binpkg_publishinghistory.status.title) return BinaryPackagePublishingHistory( binarypackagerelease=binarypackage.id, binarypackagename=binarypackage.binarypackagename, component=component.id, section=section.id, priority=priority, distroarchseries=self.distroarchseries.id, status=PackagePublishingStatus.PUBLISHED, datecreated=UTC_NOW, datepublished=UTC_NOW, pocket=self.pocket, datesuperseded=None, supersededby=None, datemadepending=None, dateremoved=None, archive=archive) log.info('BinaryPackage %s-%s published into %s.' % ( binarypackage.binarypackagename.name, binarypackage.version, self.distroarchseries.architecturetag))
def publish(self, binarypackage, bpdata): """Create the publishing entry on db if does not exist.""" # These need to be pulled from the binary package data, not the # binary package release: the data represents data from /this # specific distroseries/, whereas the package represents data # from when it was first built. if self.component_override is not None: component = self.distro_handler.getComponentByName( self.component_override) log.info('Overriding binary %s component' % binarypackage.binarypackagename.name) else: component = self.distro_handler.getComponentByName( bpdata.component) distribution = self.distroarchseries.distroseries.distribution archive = distribution.getArchiveByComponent(component.name) section = self.distro_handler.ensureSection(bpdata.section) priority = prioritymap[bpdata.priority] # Check if the binarypackage is already published and if yes, # just report it. binpkg_publishinghistory = self._checkPublishing(binarypackage) if binpkg_publishinghistory: if ((binpkg_publishinghistory.section, binpkg_publishinghistory.priority, binpkg_publishinghistory.component) == (section, priority, component)): # If nothing has changed in terms of publication # (overrides) we are free to let this one go log.info('BinaryPackageRelease already published with no ' 'changes as %s' % binpkg_publishinghistory.status.title) return BinaryPackagePublishingHistory( binarypackagerelease=binarypackage.id, binarypackagename=binarypackage.binarypackagename, component=component.id, section=section.id, priority=priority, distroarchseries=self.distroarchseries.id, status=PackagePublishingStatus.PUBLISHED, datecreated=UTC_NOW, datepublished=UTC_NOW, pocket=self.pocket, datesuperseded=None, supersededby=None, datemadepending=None, dateremoved=None, archive=archive) log.info('BinaryPackage %s-%s published into %s.' % (binarypackage.binarypackagename.name, binarypackage.version, self.distroarchseries.architecturetag))
def publish(self, sourcepackagerelease, spdata): """Create the publishing entry on db if does not exist.""" # Check if the sprelease is already published and if so, just # report it. if self.component_override: component = self.distro_handler.getComponentByName( self.component_override) log.info('Overriding source %s component' % sourcepackagerelease.sourcepackagename.name) else: component = self.distro_handler.getComponentByName( spdata.component) archive = self.distroseries.distribution.getArchiveByComponent( component.name) section = self.distro_handler.ensureSection(spdata.section) source_publishinghistory = self._checkPublishing(sourcepackagerelease) if source_publishinghistory: if ((source_publishinghistory.section, source_publishinghistory.component) == (section, component)): # If nothing has changed in terms of publication # (overrides) we are free to let this one go log.info('SourcePackageRelease already published with no ' 'changes as %s' % source_publishinghistory.status.title) return entry = getUtility(IPublishingSet).newSourcePublication( distroseries=self.distroseries, sourcepackagerelease=sourcepackagerelease, component=component, section=section, pocket=self.pocket, archive=archive) entry.setPublished() log.info('Source package %s (%s) published' % ( entry.sourcepackagerelease.sourcepackagename.name, entry.sourcepackagerelease.version))
def publish(self, sourcepackagerelease, spdata): """Create the publishing entry on db if does not exist.""" # Check if the sprelease is already published and if so, just # report it. if self.component_override: component = self.distro_handler.getComponentByName( self.component_override) log.info('Overriding source %s component' % sourcepackagerelease.sourcepackagename.name) else: component = self.distro_handler.getComponentByName( spdata.component) archive = self.distroseries.distribution.getArchiveByComponent( component.name) section = self.distro_handler.ensureSection(spdata.section) source_publishinghistory = self._checkPublishing(sourcepackagerelease) if source_publishinghistory: if ((source_publishinghistory.section, source_publishinghistory.component) == (section, component)): # If nothing has changed in terms of publication # (overrides) we are free to let this one go log.info('SourcePackageRelease already published with no ' 'changes as %s' % source_publishinghistory.status.title) return entry = getUtility(IPublishingSet).newSourcePublication( distroseries=self.distroseries, sourcepackagerelease=sourcepackagerelease, component=component, section=section, pocket=self.pocket, archive=archive) entry.setPublished() log.info('Source package %s (%s) published' % (entry.sourcepackagerelease.sourcepackagename.name, entry.sourcepackagerelease.version))
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 run_gina(options, ztm, target_section): # Avoid circular imports. from lp.registry.interfaces.pocket import PackagePublishingPocket package_root = target_section.root distro = target_section.distro pocket_distroseries = target_section.pocketrelease distroseries = target_section.distroseries components = [c.strip() for c in target_section.components.split(",")] archs = [a.strip() for a in target_section.architectures.split(",")] pocket = target_section.pocket component_override = target_section.componentoverride source_only = target_section.source_only spnames_only = target_section.sourcepackagenames_only LIBRHOST = config.librarian.upload_host LIBRPORT = config.librarian.upload_port log.info("") log.info("=== Processing %s/%s/%s ===", distro, distroseries, pocket) log.debug("Packages read from: %s", package_root) log.info("Components to import: %s", ", ".join(components)) if component_override is not None: log.info("Override components to: %s", component_override) log.info("Architectures to import: %s", ", ".join(archs)) log.debug("Launchpad database: %s", config.database.rw_main_master) log.info("SourcePackage Only: %s", source_only) log.info("SourcePackageName Only: %s", spnames_only) log.debug("Librarian: %s:%s", LIBRHOST, LIBRPORT) log.info("") if not hasattr(PackagePublishingPocket, pocket.upper()): log.error("Could not find a pocket schema for %s", pocket) sys.exit(1) pocket = getattr(PackagePublishingPocket, pocket.upper()) if component_override: valid_components = [component.name for component in getUtility(IComponentSet)] if component_override not in valid_components: log.error("Could not find component %s", component_override) sys.exit(1) try: arch_component_items = ArchiveComponentItems(package_root, pocket_distroseries, components, archs, source_only) except MangledArchiveError: log.exception("Failed to analyze archive for %s", pocket_distroseries) sys.exit(1) packages_map = PackagesMap(arch_component_items) importer_handler = ImporterHandler(ztm, distro, distroseries, package_root, pocket, component_override) import_sourcepackages(distro, packages_map, package_root, importer_handler) importer_handler.commit() # XXX JeroenVermeulen 2011-09-07 bug=843728: Dominate binaries as well. dominate_imported_source_packages(ztm, log, distro, distroseries, pocket, packages_map) ztm.commit() if source_only: log.info("Source only mode... done") return for archtag in archs: try: importer_handler.ensure_archinfo(archtag) except DataSetupError: log.exception("Database setup required for run on %s", archtag) sys.exit(1) import_binarypackages(distro, packages_map, package_root, importer_handler) importer_handler.commit()
def run_gina(options, ztm, target_section): package_root = target_section.root distro = target_section.distro pocket_distroseries = target_section.pocketrelease distroseries = target_section.distroseries components = [c.strip() for c in target_section.components.split(",")] archs = [a.strip() for a in target_section.architectures.split(",")] pocket = target_section.pocket component_override = target_section.componentoverride source_only = target_section.source_only spnames_only = target_section.sourcepackagenames_only LIBRHOST = config.librarian.upload_host LIBRPORT = config.librarian.upload_port log.info("") log.info("=== Processing %s/%s/%s ===", distro, distroseries, pocket) log.debug("Packages read from: %s", package_root) log.info("Components to import: %s", ", ".join(components)) if component_override is not None: log.info("Override components to: %s", component_override) log.info("Architectures to import: %s", ", ".join(archs)) log.debug("Launchpad database: %s", config.database.rw_main_master) log.info("SourcePackage Only: %s", source_only) log.info("SourcePackageName Only: %s", spnames_only) log.debug("Librarian: %s:%s", LIBRHOST, LIBRPORT) log.info("") if not hasattr(PackagePublishingPocket, pocket.upper()): log.error("Could not find a pocket schema for %s", pocket) sys.exit(1) pocket = getattr(PackagePublishingPocket, pocket.upper()) if component_override: valid_components = [ component.name for component in getUtility(IComponentSet) ] if component_override not in valid_components: log.error("Could not find component %s", component_override) sys.exit(1) try: arch_component_items = ArchiveComponentItems(package_root, pocket_distroseries, components, archs, source_only) except MangledArchiveError: log.exception("Failed to analyze archive for %s", pocket_distroseries) sys.exit(1) packages_map = PackagesMap(arch_component_items) importer_handler = ImporterHandler(ztm, distro, distroseries, package_root, pocket, component_override) import_sourcepackages(distro, packages_map, package_root, importer_handler) importer_handler.commit() # XXX JeroenVermeulen 2011-09-07 bug=843728: Dominate binaries as well. dominate_imported_source_packages(ztm, log, distro, distroseries, pocket, packages_map) ztm.commit() if source_only: log.info('Source only mode... done') return for archtag in archs: try: importer_handler.ensure_arch(archtag) except DataSetupError: log.exception("Database setup required for run on %s", archtag) sys.exit(1) import_binarypackages(distro, packages_map, package_root, importer_handler) importer_handler.commit()