def getMergeProposals(self, status=None, visible_by_user=None, eager_load=False): """See `IHasMergeProposals`.""" # Circular import. from lp.code.model.branchmergeproposal import BranchMergeProposal if not status: status = (BranchMergeProposalStatus.CODE_APPROVED, BranchMergeProposalStatus.NEEDS_REVIEW, BranchMergeProposalStatus.WORK_IN_PROGRESS) def _getProposals(interface): collection = removeSecurityProxy(interface(self)) collection = collection.visibleByUser(visible_by_user) return collection.getMergeProposals(status, eager_load=False) # SourcePackage Bazaar branches are an aberration which was not # replicated for Git, so SourcePackage does not support Git. if ISourcePackage.providedBy(self): proposals = _getProposals(IBranchCollection) else: proposals = _getProposals(IBranchCollection).union( _getProposals(IGitCollection)) if not eager_load: return proposals else: loader = partial(BranchMergeProposal.preloadDataForBMPs, user=visible_by_user) return DecoratedResultSet(proposals, pre_iter_hook=loader)
def setSourcePackage(self, sourcepackage): """Set the sourcepackage context on which to filter the search.""" # Import this here to avoid circular dependencies from lp.registry.interfaces.sourcepackage import (ISourcePackage) if isinstance(sourcepackage, any): # Unwrap the source package. self.sourcepackagename = any( *[pkg.sourcepackagename for pkg in sourcepackage.query_values]) distroseries = any(*[ pkg.distroseries for pkg in sourcepackage.query_values if ISourcePackage.providedBy(pkg) ]) distributions = any(*[ pkg.distribution for pkg in sourcepackage.query_values if not ISourcePackage.providedBy(pkg) ]) if distroseries.query_values and not distributions.query_values: self.distroseries = distroseries elif not distroseries.query_values and distributions.query_values: self.distributions = distributions else: # At this point we have determined that either we have both # distroseries and distributions, or we have neither of them. # We will set both. Doing so will give us the cross-product, # because searching source packages is # sourcepackagename-specific rather than actually # context-specific. This is not ideal but is tolerable given # no actual use of mixed-type any() exists today. self.distroseries = distroseries self.distributions = distributions return if ISourcePackage.providedBy(sourcepackage): # This is a sourcepackage in a distro series. self.distroseries = sourcepackage.distroseries else: # This is a sourcepackage in a distribution. self.distribution = sourcepackage.distribution self.sourcepackagename = sourcepackage.sourcepackagename
def setSourcePackage(self, sourcepackage): """Set the sourcepackage context on which to filter the search.""" # Import this here to avoid circular dependencies from lp.registry.interfaces.sourcepackage import ( ISourcePackage) if isinstance(sourcepackage, any): # Unwrap the source package. self.sourcepackagename = any(*[ pkg.sourcepackagename for pkg in sourcepackage.query_values]) distroseries = any(*[pkg.distroseries for pkg in sourcepackage.query_values if ISourcePackage.providedBy(pkg)]) distributions = any(*[pkg.distribution for pkg in sourcepackage.query_values if not ISourcePackage.providedBy(pkg)]) if distroseries.query_values and not distributions.query_values: self.distroseries = distroseries elif not distroseries.query_values and distributions.query_values: self.distributions = distributions else: # At this point we have determined that either we have both # distroseries and distributions, or we have neither of them. # We will set both. Doing so will give us the cross-product, # because searching source packages is # sourcepackagename-specific rather than actually # context-specific. This is not ideal but is tolerable given # no actual use of mixed-type any() exists today. self.distroseries = distroseries self.distributions = distributions return if ISourcePackage.providedBy(sourcepackage): # This is a sourcepackage in a distro series. self.distroseries = sourcepackage.distroseries else: # This is a sourcepackage in a distribution. self.distribution = sourcepackage.distribution self.sourcepackagename = sourcepackage.sourcepackagename
def milestone_matches_bugtask(milestone, bugtask): """ Return True if the milestone can be set against this bugtask.""" bug_target = bugtask.target naked_milestone = removeSecurityProxy(milestone) if IProduct.providedBy(bug_target): return bugtask.product.id == naked_milestone.productID elif IProductSeries.providedBy(bug_target): return bugtask.productseries.product.id == naked_milestone.productID elif (IDistribution.providedBy(bug_target) or IDistributionSourcePackage.providedBy(bug_target)): return bugtask.distribution.id == naked_milestone.distributionID elif (IDistroSeries.providedBy(bug_target) or ISourcePackage.providedBy(bug_target)): return bugtask.distroseries.id == naked_milestone.distroseriesID return False
def setTarget(self, target): """Constrain the search to only return items in target. This is equivalent to calling setProduct etc but the type of target does not need to be known to the caller. :param target: A `IHasBug`, or some search term like all/any/none on `IHasBug`. If using all/any all the targets must be of the same type due to implementation limitations. Currently only distroseries and productseries `IHasBug` implementations are supported. """ # Yay circular deps. from lp.registry.interfaces.distribution import IDistribution from lp.registry.interfaces.distroseries import IDistroSeries from lp.registry.interfaces.product import IProduct from lp.registry.interfaces.productseries import IProductSeries from lp.registry.interfaces.milestone import IMilestone from lp.registry.interfaces.projectgroup import IProjectGroup from lp.registry.interfaces.sourcepackage import ISourcePackage from lp.registry.interfaces.distributionsourcepackage import \ IDistributionSourcePackage if isinstance(target, (any, all)): assert len(target.query_values), \ 'cannot determine target with no targets' instance = target.query_values[0] else: instance = target if IDistribution.providedBy(instance): self.setDistribution(target) elif IDistroSeries.providedBy(instance): self.setDistroSeries(target) elif IProduct.providedBy(instance): self.setProduct(target) elif IProductSeries.providedBy(instance): self.setProductSeries(target) elif IMilestone.providedBy(instance): self.milestone = target elif ISourcePackage.providedBy(instance): self.setSourcePackage(target) elif IDistributionSourcePackage.providedBy(instance): self.setSourcePackage(target) elif IProjectGroup.providedBy(instance): self.setProjectGroup(target) else: raise AssertionError("unknown target type %r" % target)
def setTarget(self, target): """Constrain the search to only return items in target. This is equivalent to calling setProduct etc but the type of target does not need to be known to the caller. :param target: A `IHasBug`, or some search term like all/any/none on `IHasBug`. If using all/any all the targets must be of the same type due to implementation limitations. Currently only distroseries and productseries `IHasBug` implementations are supported. """ # Yay circular deps. from lp.registry.interfaces.distribution import IDistribution from lp.registry.interfaces.distroseries import IDistroSeries from lp.registry.interfaces.product import IProduct from lp.registry.interfaces.productseries import IProductSeries from lp.registry.interfaces.milestone import IMilestone from lp.registry.interfaces.projectgroup import IProjectGroup from lp.registry.interfaces.sourcepackage import ISourcePackage from lp.registry.interfaces.distributionsourcepackage import \ IDistributionSourcePackage if isinstance(target, (any, all)): assert len(target.query_values), \ 'cannot determine target with no targets' instance = target.query_values[0] else: instance = target if IDistribution.providedBy(instance): self.setDistribution(target) elif IDistroSeries.providedBy(instance): self.setDistroSeries(target) elif IProduct.providedBy(instance): self.setProduct(target) elif IProductSeries.providedBy(instance): self.setProductSeries(target) elif IMilestone.providedBy(instance): self.milestone = target elif ISourcePackage.providedBy(instance): self.setSourcePackage(target) elif IDistributionSourcePackage.providedBy(instance): self.setSourcePackage(target) elif IProjectGroup.providedBy(instance): self.setProject(target) else: raise AssertionError("unknown target type %r" % target)
def __init__(self, context): StandardLaunchpadFacets.__init__(self, context) target = context.translationtarget if IProductSeries.providedBy(target): self._is_product_series = True self.target_facets = ProductSeriesFacets(target) elif ISourcePackage.providedBy(target): self._is_product_series = False self.target_facets = SourcePackageFacets(target) else: # We don't know yet how to handle this target. raise NotImplementedError # Enable only the menus that the translation target uses. self.enable_only = self.target_facets.enable_only # From an IPOTemplate URL, we reach its translationtarget (either # ISourcePackage or IProductSeries using self.target. self.target = '../../'
def _getShortRequestName(self, request): """Return a short request name for use in email subjects.""" if IPOFile.providedBy(request): title = '%s translation of %s' % ( request.language.englishname, request.potemplate.name) productseries = request.potemplate.productseries distroseries = request.potemplate.distroseries sourcepackagename = request.potemplate.sourcepackagename elif IPOTemplate.providedBy(request): title = '%s template' % (request.name) productseries = request.productseries distroseries = request.distroseries sourcepackagename = request.sourcepackagename elif IProductSeries.providedBy(request): title = None productseries = request distroseries = None sourcepackagename = None elif ISourcePackage.providedBy(request): title = None productseries = None distroseries = request.distroseries sourcepackagename = request.sourcepackagename else: raise AssertionError( "We can not figure out short name for this translation " "export origin.") if productseries is not None: root = '%s %s' % ( productseries.product.displayname, productseries.name) else: root = '%s %s %s' % ( distroseries.distribution.displayname, distroseries.displayname, sourcepackagename.name) if title is not None: return '%s - %s' % (root, title) else: return root
def describe(self, target, link, covered_files): """See `TranslationLinksAggregator.describe`.""" strings_count = sum( [self.countStrings(pofile) for pofile in covered_files]) languages = set( [pofile.language.englishname for pofile in covered_files]) languages_list = ", ".join(sorted(languages)) if strings_count == 1: strings_wording = "%d string" else: strings_wording = "%d strings" return { 'target': target, 'count': strings_count, 'count_wording': strings_wording % strings_count, 'is_product': not ISourcePackage.providedBy(target), 'link': link, 'languages': languages_list, }
def _getShortRequestName(self, request): """Return a short request name for use in email subjects.""" if IPOFile.providedBy(request): title = '%s translation of %s' % (request.language.englishname, request.potemplate.name) productseries = request.potemplate.productseries distroseries = request.potemplate.distroseries sourcepackagename = request.potemplate.sourcepackagename elif IPOTemplate.providedBy(request): title = '%s template' % (request.name) productseries = request.productseries distroseries = request.distroseries sourcepackagename = request.sourcepackagename elif IProductSeries.providedBy(request): title = None productseries = request distroseries = None sourcepackagename = None elif ISourcePackage.providedBy(request): title = None productseries = None distroseries = request.distroseries sourcepackagename = request.sourcepackagename else: raise AssertionError( "We can not figure out short name for this translation " "export origin.") if productseries is not None: root = '%s %s' % (productseries.product.displayname, productseries.name) else: root = '%s %s %s' % (distroseries.distribution.displayname, distroseries.displayname, sourcepackagename.name) if title is not None: return '%s - %s' % (root, title) else: return root
def get_structural_subscription_targets(bugtasks): """Return (bugtask, target) pairs for each target of the bugtasks. Each bugtask may be responsible theoretically for 0 or more targets. In practice, each generates one, two or three. """ for bugtask in bugtasks: if IStructuralSubscriptionTarget.providedBy(bugtask.target): yield (bugtask, bugtask.target) if bugtask.target.parent_subscription_target is not None: yield (bugtask, bugtask.target.parent_subscription_target) # This can probably be an elif. Determining conclusively # whether it can be is not a priority at this time. The # docstring says one, two, or three targets per bugtask because # of the belief that this could be an elif; otherwise, it would # be one, two, three or four. if ISourcePackage.providedBy(bugtask.target): # Distribution series bug tasks with a package have the source # package set as their target, so we add the distroseries # explicitly to the set of subscription targets. yield (bugtask, bugtask.distroseries) if bugtask.milestone is not None: yield (bugtask, bugtask.milestone)
def __eq__(self, other): """See `ISourcePackage`.""" return ((ISourcePackage.providedBy(other)) and (self.distroseries.id == other.distroseries.id) and (self.sourcepackagename.id == other.sourcepackagename.id))