Ejemplo n.º 1
0
 def makeSnap(self, context):
     if IBranch.providedBy(context):
         return self.factory.makeSnap(branch=context)
     else:
         if IGitRepository.providedBy(context):
             [context] = self.factory.makeGitRefs(repository=context)
         return self.factory.makeSnap(git_ref=context)
Ejemplo n.º 2
0
def branch_linked(bug, event):
    """Assign karma to the user who linked the bug to the branch."""
    from lp.code.interfaces.branch import IBranch
    if not IBranch.providedBy(event.other_object):
        return
    event.other_object.target.assignKarma(IPerson(event.user),
                                          'bugbranchcreated')
Ejemplo n.º 3
0
    def create(cls, requestor, artifacts=None, grantee=None, pillar=None, information_types=None):
        """See `IRemoveArtifactSubscriptionsJob`."""

        bug_ids = []
        branch_ids = []
        specification_ids = []
        if artifacts:
            for artifact in artifacts:
                if IBug.providedBy(artifact):
                    bug_ids.append(artifact.id)
                elif IBranch.providedBy(artifact):
                    branch_ids.append(artifact.id)
                elif ISpecification.providedBy(artifact):
                    specification_ids.append(artifact.id)
                else:
                    raise ValueError("Unsupported artifact: %r" % artifact)
        information_types = [info_type.value for info_type in information_types or []]
        metadata = {
            "bug_ids": bug_ids,
            "branch_ids": branch_ids,
            "specification_ids": specification_ids,
            "information_types": information_types,
            "requestor.id": requestor.id,
        }
        return super(RemoveArtifactSubscriptionsJob, cls).create(pillar, grantee, metadata)
Ejemplo n.º 4
0
 def initial_values(self):
     distroseries = BuildableDistroSeries.findSeries(self.user)
     series = [
         series for series in distroseries
         if series.status in (SeriesStatus.CURRENT,
                              SeriesStatus.DEVELOPMENT)
     ]
     if IBranch.providedBy(self.context):
         recipe_text = MINIMAL_RECIPE_TEXT_BZR % self.context.identity
     elif IGitRepository.providedBy(self.context):
         default_ref = None
         if self.context.default_branch is not None:
             default_ref = self.context.getRefByPath(
                 self.context.default_branch)
         if default_ref is not None:
             branch_name = default_ref.name
         else:
             branch_name = "ENTER-BRANCH-NAME"
         recipe_text = MINIMAL_RECIPE_TEXT_GIT % (self.context.identity,
                                                  branch_name)
     elif IGitRef.providedBy(self.context):
         recipe_text = MINIMAL_RECIPE_TEXT_GIT % (
             self.context.repository.identity, self.context.name)
     else:
         raise AssertionError("Unsupported context: %r" % (self.context, ))
     return {
         'name': self._find_unused_name(self.user),
         'recipe_text': recipe_text,
         'owner': self.user,
         'distroseries': series,
         'build_daily': True,
         'use_ppa': EXISTING_PPA,
     }
 def __init__(self, name, type, comment, line_number, branch_or_repository,
              revspec, directory, recipe_data, parent_instruction,
              source_directory):
     super(_SourcePackageRecipeDataInstruction, self).__init__()
     self.name = unicode(name)
     self.type = type
     self.comment = comment
     self.line_number = line_number
     if IGitRepository.providedBy(branch_or_repository):
         self.git_repository = branch_or_repository
     elif IGitRef.providedBy(branch_or_repository):
         self.git_repository = branch_or_repository
         if revspec is None:
             revspec = branch_or_repository.name
     elif IBranch.providedBy(branch_or_repository):
         self.branch = branch_or_repository
     else:
         raise AssertionError("Unsupported source: %r" %
                              (branch_or_repository, ))
     if revspec is not None:
         revspec = unicode(revspec)
     self.revspec = revspec
     if directory is not None:
         directory = unicode(directory)
     self.directory = directory
     self.source_directory = source_directory
     self.recipe_data = recipe_data
     self.parent_instruction = parent_instruction
 def initialize(self):
     super(BranchRecipeListingView, self).initialize()
     # Replace our context with a decorated branch, if it is not already
     # decorated.
     if (IBranch.providedBy(self.context) and
             not isinstance(self.context, DecoratedBranch)):
         self.context = DecoratedBranch(self.context)
Ejemplo n.º 7
0
    def ensure(cls, concrete_artifacts):
        """See `IAccessArtifactSource`."""
        from lp.blueprints.interfaces.specification import ISpecification
        from lp.bugs.interfaces.bug import IBug
        from lp.code.interfaces.branch import IBranch

        existing = list(cls.find(concrete_artifacts))
        if len(existing) == len(concrete_artifacts):
            return existing

        # Not everything exists. Create missing ones.
        needed = (
            set(concrete_artifacts) -
            set(abstract.concrete_artifact for abstract in existing))

        insert_values = []
        for concrete in needed:
            if IBug.providedBy(concrete):
                insert_values.append((concrete, None, None))
            elif IBranch.providedBy(concrete):
                insert_values.append((None, concrete, None))
            elif ISpecification.providedBy(concrete):
                insert_values.append((None, None, concrete))
            else:
                raise ValueError("%r is not a supported artifact" % concrete)
        new = create(
            (cls.bug, cls.branch, cls.specification),
            insert_values, get_objects=True)
        return list(existing) + new
Ejemplo n.º 8
0
    def ensure(cls, concrete_artifacts):
        """See `IAccessArtifactSource`."""
        from lp.blueprints.interfaces.specification import ISpecification
        from lp.bugs.interfaces.bug import IBug
        from lp.code.interfaces.branch import IBranch
        from lp.code.interfaces.gitrepository import IGitRepository

        existing = list(cls.find(concrete_artifacts))
        if len(existing) == len(concrete_artifacts):
            return existing

        # Not everything exists. Create missing ones.
        needed = (set(concrete_artifacts) - set(abstract.concrete_artifact
                                                for abstract in existing))

        insert_values = []
        for concrete in needed:
            if IBug.providedBy(concrete):
                insert_values.append((concrete, None, None, None))
            elif IBranch.providedBy(concrete):
                insert_values.append((None, concrete, None, None))
            elif IGitRepository.providedBy(concrete):
                insert_values.append((None, None, concrete, None))
            elif ISpecification.providedBy(concrete):
                insert_values.append((None, None, None, concrete))
            else:
                raise ValueError("%r is not a supported artifact" % concrete)
        new = create(
            (cls.bug, cls.branch, cls.gitrepository, cls.specification),
            insert_values,
            get_objects=True)
        return list(existing) + new
Ejemplo n.º 9
0
    def create(cls,
               requestor,
               artifacts=None,
               grantee=None,
               pillar=None,
               information_types=None):
        """See `IRemoveArtifactSubscriptionsJob`."""

        bug_ids = []
        branch_ids = []
        specification_ids = []
        if artifacts:
            for artifact in artifacts:
                if IBug.providedBy(artifact):
                    bug_ids.append(artifact.id)
                elif IBranch.providedBy(artifact):
                    branch_ids.append(artifact.id)
                elif ISpecification.providedBy(artifact):
                    specification_ids.append(artifact.id)
                else:
                    raise ValueError('Unsupported artifact: %r' % artifact)
        information_types = [
            info_type.value for info_type in information_types or []
        ]
        metadata = {
            'bug_ids': bug_ids,
            'branch_ids': branch_ids,
            'specification_ids': specification_ids,
            'information_types': information_types,
            'requestor.id': requestor.id
        }
        return super(RemoveArtifactSubscriptionsJob,
                     cls).create(pillar, grantee, metadata)
 def base(self, value):
     if IGitRepository.providedBy(value):
         self.base_git_repository = value
         self.base_branch = None
     elif IBranch.providedBy(value):
         self.base_branch = value
         self.base_git_repository = None
     else:
         raise AssertionError("Unsupported base: %r" % (value, ))
Ejemplo n.º 11
0
 def __init__(self, target=None, *args, **kwargs):
     if target is not None:
         assert 'branch' not in kwargs
         assert 'repository' not in kwargs
         if IBranch.providedBy(target):
             kwargs['branch'] = target
         elif IGitRepository.providedBy(target):
             kwargs['git_repository'] = target
         else:
             raise AssertionError("Unknown code import target %s" % target)
     super(CodeImport, self).__init__(*args, **kwargs)
Ejemplo n.º 12
0
 def __init__(self, context=None):
     super(BranchRestrictedOnProductVocabulary, self).__init__(context)
     if IProduct.providedBy(self.context):
         self.product = self.context
     elif IProductSeries.providedBy(self.context):
         self.product = self.context.product
     elif IBranch.providedBy(self.context):
         self.product = self.context.product
     else:
         # An unexpected type.
         raise AssertionError('Unexpected context type')
Ejemplo n.º 13
0
 def __init__(self, context=None):
     super(BranchRestrictedOnProductVocabulary, self).__init__(context)
     if IProduct.providedBy(self.context):
         self.product = self.context
     elif IProductSeries.providedBy(self.context):
         self.product = self.context.product
     elif IBranch.providedBy(self.context):
         self.product = self.context.product
     else:
         # An unexpected type.
         raise AssertionError('Unexpected context type')
Ejemplo n.º 14
0
 def _constraintForConcrete(cls, concrete_artifact):
     from lp.blueprints.interfaces.specification import ISpecification
     from lp.bugs.interfaces.bug import IBug
     from lp.code.interfaces.branch import IBranch
     if IBug.providedBy(concrete_artifact):
         col = cls.bug
     elif IBranch.providedBy(concrete_artifact):
         col = cls.branch
     elif ISpecification.providedBy(concrete_artifact):
         col = cls.specification
     else:
         raise ValueError("%r is not a valid artifact" % concrete_artifact)
     return col == concrete_artifact
    def findRecipes(branch_or_repository, revspecs=None):
        """Find recipes for a given branch or repository.

        :param branch_or_repository: The branch or repository to search for.
        :param revspecs: If not None, return only recipes whose `revspec` is
            in this sequence.
        :return: a collection of `ISourcePackageRecipe`s.
        """
        from lp.code.model.sourcepackagerecipe import SourcePackageRecipe
        store = Store.of(branch_or_repository)
        if IGitRepository.providedBy(branch_or_repository):
            data_clause = (SourcePackageRecipeData.base_git_repository ==
                           branch_or_repository)
            insn_clause = (_SourcePackageRecipeDataInstruction.git_repository
                           == branch_or_repository)
        elif IBranch.providedBy(branch_or_repository):
            data_clause = (
                SourcePackageRecipeData.base_branch == branch_or_repository)
            insn_clause = (_SourcePackageRecipeDataInstruction.branch ==
                           branch_or_repository)
        else:
            raise AssertionError("Unsupported source: %r" %
                                 (branch_or_repository, ))
        if revspecs is not None:
            concrete_revspecs = [
                revspec for revspec in revspecs if revspec is not None
            ]
            data_revspec_clause = In(SourcePackageRecipeData.revspec,
                                     concrete_revspecs)
            insn_revspec_clause = In(
                _SourcePackageRecipeDataInstruction.revspec, concrete_revspecs)
            if None in revspecs:
                data_revspec_clause = Or(
                    data_revspec_clause,
                    SourcePackageRecipeData.revspec == None)
                insn_revspec_clause = Or(
                    insn_revspec_clause,
                    _SourcePackageRecipeDataInstruction.revspec == None)
            data_clause = And(data_clause, data_revspec_clause)
            insn_clause = And(insn_clause, insn_revspec_clause)
        return store.find(
            SourcePackageRecipe,
            SourcePackageRecipe.id.is_in(
                Union(
                    Select(SourcePackageRecipeData.sourcepackage_recipe_id,
                           data_clause),
                    Select(
                        SourcePackageRecipeData.sourcepackage_recipe_id,
                        And(
                            _SourcePackageRecipeDataInstruction.recipe_data_id
                            == SourcePackageRecipeData.id, insn_clause)))))
Ejemplo n.º 16
0
 def __init__(self, existing_proposal):
     # Circular import.
     from lp.code.interfaces.branch import IBranch
     # display_name is the newer style, but IBranch uses the older style.
     if IBranch.providedBy(existing_proposal.merge_source):
         display_name = "displayname"
     else:
         display_name = "display_name"
     super(BranchMergeProposalExists, self).__init__(
             'There is already a branch merge proposal registered for '
             'branch %s to land on %s that is still active.' %
             (getattr(existing_proposal.merge_source, display_name),
              getattr(existing_proposal.merge_target, display_name)))
     self.existing_proposal = existing_proposal
Ejemplo n.º 17
0
 def _constraintForConcrete(cls, concrete_artifact):
     from lp.blueprints.interfaces.specification import ISpecification
     from lp.bugs.interfaces.bug import IBug
     from lp.code.interfaces.branch import IBranch
     if IBug.providedBy(concrete_artifact):
         col = cls.bug
     elif IBranch.providedBy(concrete_artifact):
         col = cls.branch
     elif ISpecification.providedBy(concrete_artifact):
         col = cls.specification
     else:
         raise ValueError(
             "%r is not a valid artifact" % concrete_artifact)
     return col == concrete_artifact
Ejemplo n.º 18
0
 def assertBranchImportedOKForCodeImport(self, code_import):
     """Assert that a branch was pushed into the default branch store."""
     if IBranch.providedBy(code_import.target):
         url = get_default_bazaar_branch_store()._getMirrorURL(
             code_import.branch.id)
         branch = Branch.open(url)
         commit_count = branch.revno()
     else:
         repo_path = os.path.join(self.target_store,
                                  code_import.target.unique_name)
         commit_count = int(
             subprocess.check_output(["git", "rev-list", "--count", "HEAD"],
                                     cwd=repo_path,
                                     universal_newlines=True))
     self.assertEqual(self.foreign_commit_count, commit_count)
Ejemplo n.º 19
0
 def _getHeaders(self, email, recipient):
     headers = BaseMailer._getHeaders(self, email, recipient)
     reason, rationale = self._recipients.getReason(email)
     headers['X-Launchpad-Branch'] = reason.branch.unique_name
     if IGitRef.providedBy(reason.branch):
         if IProduct.providedBy(reason.branch.target):
             headers['X-Launchpad-Project'] = reason.branch.target.name
     elif IBranch.providedBy(reason.branch):
         if reason.branch.product is not None:
             headers['X-Launchpad-Project'] = reason.branch.product.name
     if self.revno is not None:
         headers['X-Launchpad-Branch-Revision-Number'] = str(self.revno)
     if self.revision_id is not None:
         headers['X-Launchpad-Branch-Revision-ID'] = self.revision_id
     return headers
Ejemplo n.º 20
0
 def _recipe_names(self):
     """A generator of recipe names."""
     # +junk-daily doesn't make a very good recipe name, so use the
     # branch name in that case; similarly for personal Git repositories.
     if ((IBranch.providedBy(self.context)
          and self.context.target.allow_recipe_name_from_target)
             or ((IGitRepository.providedBy(self.context)
                  or IGitRef.providedBy(self.context))
                 and self.context.namespace.allow_recipe_name_from_target)):
         branch_target_name = self.context.target.name.split('/')[-1]
     else:
         branch_target_name = self.context.name
     yield "%s-daily" % branch_target_name
     counter = itertools.count(1)
     while True:
         yield "%s-daily-%s" % (branch_target_name, counter.next())
Ejemplo n.º 21
0
    def getStartedJobForImport(self, code_import):
        """Get a started `CodeImportJob` for `code_import`.

        This method approves the import, creates a job, marks it started and
        returns the job.  It also makes sure there are no branches or foreign
        trees in the default stores to interfere with processing this job.
        """
        if code_import.review_status != CodeImportReviewStatus.REVIEWED:
            code_import.updateFromData(
                {'review_status': CodeImportReviewStatus.REVIEWED},
                self.factory.makePerson())
        job = getUtility(ICodeImportJobSet).getJobForMachine('machine', 10)
        self.assertEqual(code_import, job.code_import)
        source_details = CodeImportSourceDetails.fromArguments(
            removeSecurityProxy(job.makeWorkerArguments()))
        if IBranch.providedBy(code_import.target):
            clean_up_default_stores_for_import(source_details)
            self.addCleanup(clean_up_default_stores_for_import, source_details)
        return job
Ejemplo n.º 22
0
 def related_package_branch_info(self):
     branch_to_check = self.getBranch()
     if IBranch.providedBy(branch_to_check):
         branch_target = IBranchTarget(branch_to_check.target)
         return branch_target.getRelatedPackageBranchInfo(branch_to_check,
                                                          limit_results=5)
Ejemplo n.º 23
0
 def makeSnap(self, context):
     if IBranch.providedBy(context):
         return self.factory.makeSnap(branch=context)
     else:
         return self.factory.makeSnap(git_ref=context)