def getRelatedSeriesBranchInfo(self, parent_branch, limit_results=None): """See `IBranchTarget`.""" sorted_series = [] for series in self.product.series: if (series.status != SeriesStatus.OBSOLETE and series != self.product.development_focus): sorted_series.append(series) # Now sort the list by name with newer versions before older. sorted_series = sorted_version_numbers(sorted_series, key=attrgetter('name')) # Add the development focus first. sorted_series.insert(0, self.product.development_focus) result = [] for series in sorted_series: try: branch = get_linked_to_branch(series).branch if (branch not in result and branch != parent_branch and check_permission('launchpad.View', branch)): result.append((branch, series)) except NoLinkedBranch: # If there's no branch for a particular series, we don't care. pass if limit_results is not None: # We only want the most recent branches result = result[:limit_results] return result
def _getLinkedBranchAndPath(self, provided): """Get the linked branch for 'provided', and the bzr_path. :raise CannotHaveLinkedBranch: If 'provided' can never have a linked branch. :raise NoLinkedBranch: If 'provided' could have a linked branch, but doesn't. :return: The linked branch, an `IBranch`. """ linked = get_linked_to_branch(provided) if not check_permission('launchpad.View', linked.branch): raise NoLinkedBranch(provided) return linked.branch, linked.bzr_path
def getRelatedPackageBranchInfo(self, parent_branch, limit_results=None): """See `IBranchTarget`.""" result = [] for distrosourcepackage in self.product.distrosourcepackages: try: branch = get_linked_to_branch(distrosourcepackage).branch series = distrosourcepackage.distribution.currentseries if (branch != parent_branch and series is not None and check_permission('launchpad.View', branch)): result.append((branch, series)) except NoLinkedBranch: # If there's no branch for a particular source package, # we don't care. pass result = sorted_version_numbers(result, key=lambda branch_info: ( getattr(branch_info[1], 'name'))) if limit_results is not None: # We only want the most recent branches result = result[:limit_results] return result
def getRelatedPackageBranchInfo(self, parent_branch, limit_results=None): """See `IBranchTarget`.""" result = [] for distrosourcepackage in self.product.distrosourcepackages: try: branch = get_linked_to_branch(distrosourcepackage).branch series = distrosourcepackage.distribution.currentseries if (branch != parent_branch and series is not None and check_permission('launchpad.View', branch)): result.append((branch, series)) except NoLinkedBranch: # If there's no branch for a particular source package, # we don't care. pass result = sorted_version_numbers(result, key=lambda branch_info: (getattr(branch_info[1], 'name'))) if limit_results is not None: # We only want the most recent branches result = result[:limit_results] return result
def test_get_linked_to_branch(self): branch = self.factory.makeProductBranch() product = removeSecurityProxy(branch.product) ICanHasLinkedBranch(product).setBranch(branch) got_linkable = get_linked_to_branch(product) self.assertEqual(got_linkable, ICanHasLinkedBranch(product))