Exemplo n.º 1
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)
Exemplo n.º 2
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
Exemplo n.º 3
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
Exemplo n.º 4
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)
Exemplo n.º 5
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
Exemplo n.º 6
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