def createMessage(self, subject, spec, owner, content=None):
     """See ISpecificationMessageSet."""
     msg = Message(owner=owner,
                   rfc822msgid=make_msgid('blueprint'),
                   subject=subject)
     MessageChunk(message=msg, content=content, sequence=1)
     return SpecificationMessage(specification=spec, message=msg)
Beispiel #2
0
    def createMessage(self, subject, bug, owner, content=None):
        """See `IBugMessageSet`."""
        msg = Message(
            parent=bug.initial_message, owner=owner,
            rfc822msgid=make_msgid('malone'), subject=subject)
        MessageChunk(message=msg, content=content, sequence=1)
        bugmsg = BugMessage(bug=bug, message=msg,
            index=bug.bug_messages.count())

        # XXX 2008-05-27 jamesh:
        # Ensure that BugMessages get flushed in same order as they
        # are created.
        Store.of(bugmsg).flush()
        return bugmsg
Beispiel #3
0
    def new(distro_series_difference, owner, comment):
        """See `IDistroSeriesDifferenceCommentSource`."""
        msgid = make_msgid('distroseriesdifference')
        message = Message(parent=None,
                          owner=owner,
                          rfc822msgid=msgid,
                          subject=distro_series_difference.title)
        MessageChunk(message=message, content=comment, sequence=1)

        store = IMasterStore(DistroSeriesDifferenceComment)
        dsd_comment = DistroSeriesDifferenceComment()
        dsd_comment.distro_series_difference = distro_series_difference
        dsd_comment.message = message

        comment = store.add(dsd_comment)
        store.flush()
        return comment
Beispiel #4
0
    def createComment(self,
                      owner,
                      subject,
                      content=None,
                      vote=None,
                      review_type=None,
                      parent=None,
                      _date_created=DEFAULT,
                      _notify_listeners=True):
        """See `IBranchMergeProposal`."""
        #:param _date_created: The date the message was created.  Provided
        #    only for testing purposes, as it can break
        # BranchMergeProposal.root_message.
        review_type = self._normalizeReviewType(review_type)
        assert owner is not None, 'Merge proposal messages need a sender'
        parent_message = None
        if parent is not None:
            assert parent.branch_merge_proposal == self, \
                    'Replies must use the same merge proposal as their parent'
            parent_message = parent.message
        if not subject:
            # Get the subject from the parent if there is one, or use a nice
            # default.
            if parent is None:
                subject = self.title
            else:
                subject = parent.message.subject
            if not subject.startswith('Re: '):
                subject = 'Re: ' + subject

        # Avoid circular dependencies.
        from lp.services.messages.model.message import Message, MessageChunk
        msgid = make_msgid('codereview')
        message = Message(parent=parent_message,
                          owner=owner,
                          rfc822msgid=msgid,
                          subject=subject,
                          datecreated=_date_created)
        MessageChunk(message=message, content=content, sequence=1)
        return self.createCommentFromMessage(
            message,
            vote,
            review_type,
            original_email=None,
            _notify_listeners=_notify_listeners,
            _validate=False)
def eager_load_dsds(dsds):
    """Eager load dependencies of the given `DistroSeriesDifference`s.

    :param dsds: A concrete sequence (i.e. not a generator) of
        `DistroSeriesDifference` to eager load for.
    """
    source_pubs = dict(
        most_recent_publications(dsds,
                                 statuses=active_publishing_status,
                                 in_parent=False,
                                 match_version=False))
    parent_source_pubs = dict(
        most_recent_publications(dsds,
                                 statuses=active_publishing_status,
                                 in_parent=True,
                                 match_version=False))
    source_pubs_for_release = dict(
        most_recent_publications(dsds,
                                 statuses=active_publishing_status,
                                 in_parent=False,
                                 match_version=True))
    parent_source_pubs_for_release = dict(
        most_recent_publications(dsds,
                                 statuses=active_publishing_status,
                                 in_parent=True,
                                 match_version=True))

    latest_comment_by_dsd_id = dict(
        (comment.distro_series_difference_id, comment)
        for comment in most_recent_comments(dsds))
    latest_comments = latest_comment_by_dsd_id.values()

    # SourcePackageReleases of the parent and source pubs are often
    # referred to.
    sprs = bulk.load_related(
        SourcePackageRelease,
        chain(source_pubs.itervalues(), parent_source_pubs.itervalues(),
              source_pubs_for_release.itervalues(),
              parent_source_pubs_for_release.itervalues()),
        ("sourcepackagereleaseID", ))

    # Get packagesets and parent_packagesets for each DSD.
    dsd_packagesets = get_packagesets(dsds, in_parent=False)
    dsd_parent_packagesets = get_packagesets(dsds, in_parent=True)

    # Cache latest messages contents (MessageChunk).
    messages = bulk.load_related(Message, latest_comments, ['message_id'])
    chunks = message_chunks(messages)
    for msg in messages:
        cache = get_property_cache(msg)
        cache.text_contents = Message.chunks_text(chunks.get(msg.id, []))

    for dsd in dsds:
        spn_id = dsd.source_package_name_id
        cache = get_property_cache(dsd)
        cache.source_pub = source_pubs.get(spn_id)
        cache.parent_source_pub = parent_source_pubs.get(spn_id)
        cache.packagesets = dsd_packagesets.get(dsd.id)
        cache.parent_packagesets = dsd_parent_packagesets.get(dsd.id)
        if spn_id in source_pubs_for_release:
            spph = source_pubs_for_release[spn_id]
            cache.source_package_release = (DistroSeriesSourcePackageRelease(
                dsd.derived_series, spph.sourcepackagerelease))
        else:
            cache.source_package_release = None
        if spn_id in parent_source_pubs_for_release:
            spph = parent_source_pubs_for_release[spn_id]
            cache.parent_source_package_release = (
                DistroSeriesSourcePackageRelease(dsd.parent_series,
                                                 spph.sourcepackagerelease))
        else:
            cache.parent_source_package_release = None
        cache.latest_comment = latest_comment_by_dsd_id.get(dsd.id)

    # SourcePackageRelease.uploader can end up getting the requester
    # for a source package recipe build.
    sprbs = bulk.load_related(SourcePackageRecipeBuild, sprs,
                              ("source_package_recipe_build_id", ))

    # SourcePackageRelease.uploader can end up getting the owner of
    # the DSC signing key.
    gpgkeys = bulk.load_related(GPGKey, sprs, ("dscsigningkeyID", ))

    # Load DistroSeriesDifferenceComment owners, SourcePackageRecipeBuild
    # requesters, GPGKey owners, and SourcePackageRelease creators.
    person_ids = set().union(
        (dsdc.message.ownerID
         for dsdc in latest_comments), (sprb.requester_id for sprb in sprbs),
        (gpgkey.ownerID for gpgkey in gpgkeys), (spr.creatorID
                                                 for spr in sprs))
    uploaders = getUtility(IPersonSet).getPrecachedPersonsFromIDs(
        person_ids, need_validity=True)
    list(uploaders)

    # Load SourcePackageNames.
    bulk.load_related(SourcePackageName, dsds, ("source_package_name_id", ))
def eager_load_dsds(dsds):
    """Eager load dependencies of the given `DistroSeriesDifference`s.

    :param dsds: A concrete sequence (i.e. not a generator) of
        `DistroSeriesDifference` to eager load for.
    """
    source_pubs = dict(
        most_recent_publications(
            dsds, statuses=active_publishing_status,
            in_parent=False, match_version=False))
    parent_source_pubs = dict(
        most_recent_publications(
            dsds, statuses=active_publishing_status,
            in_parent=True, match_version=False))
    source_pubs_for_release = dict(
        most_recent_publications(
            dsds, statuses=active_publishing_status,
            in_parent=False, match_version=True))
    parent_source_pubs_for_release = dict(
        most_recent_publications(
            dsds, statuses=active_publishing_status,
            in_parent=True, match_version=True))

    latest_comment_by_dsd_id = dict(
        (comment.distro_series_difference_id, comment)
        for comment in most_recent_comments(dsds))
    latest_comments = latest_comment_by_dsd_id.values()

    # SourcePackageReleases of the parent and source pubs are often
    # referred to.
    sprs = bulk.load_related(
        SourcePackageRelease, chain(
            source_pubs.itervalues(),
            parent_source_pubs.itervalues(),
            source_pubs_for_release.itervalues(),
            parent_source_pubs_for_release.itervalues()),
        ("sourcepackagereleaseID",))

    # Get packagesets and parent_packagesets for each DSD.
    dsd_packagesets = get_packagesets(dsds, in_parent=False)
    dsd_parent_packagesets = get_packagesets(dsds, in_parent=True)

    # Cache latest messages contents (MessageChunk).
    messages = bulk.load_related(
        Message, latest_comments, ['message_id'])
    chunks = message_chunks(messages)
    for msg in messages:
        cache = get_property_cache(msg)
        cache.text_contents = Message.chunks_text(
            chunks.get(msg.id, []))

    for dsd in dsds:
        spn_id = dsd.source_package_name_id
        cache = get_property_cache(dsd)
        cache.source_pub = source_pubs.get(spn_id)
        cache.parent_source_pub = parent_source_pubs.get(spn_id)
        cache.packagesets = dsd_packagesets.get(dsd.id)
        cache.parent_packagesets = dsd_parent_packagesets.get(dsd.id)
        if spn_id in source_pubs_for_release:
            spph = source_pubs_for_release[spn_id]
            cache.source_package_release = (
                DistroSeriesSourcePackageRelease(
                    dsd.derived_series,
                    spph.sourcepackagerelease))
        else:
            cache.source_package_release = None
        if spn_id in parent_source_pubs_for_release:
            spph = parent_source_pubs_for_release[spn_id]
            cache.parent_source_package_release = (
                DistroSeriesSourcePackageRelease(
                    dsd.parent_series, spph.sourcepackagerelease))
        else:
            cache.parent_source_package_release = None
        cache.latest_comment = latest_comment_by_dsd_id.get(dsd.id)

    # SourcePackageRelease.uploader can end up getting the requester
    # for a source package recipe build.
    sprbs = bulk.load_related(
        SourcePackageRecipeBuild, sprs,
        ("source_package_recipe_build_id",))

    # SourcePackageRelease.uploader can end up getting the owner of
    # the DSC signing key.
    gpgkeys = bulk.load_related(GPGKey, sprs, ("dscsigningkeyID",))

    # Load DistroSeriesDifferenceComment owners, SourcePackageRecipeBuild
    # requesters, GPGKey owners, and SourcePackageRelease creators.
    person_ids = set().union(
        (dsdc.message.ownerID for dsdc in latest_comments),
        (sprb.requester_id for sprb in sprbs),
        (gpgkey.ownerID for gpgkey in gpgkeys),
        (spr.creatorID for spr in sprs))
    uploaders = getUtility(IPersonSet).getPrecachedPersonsFromIDs(
        person_ids, need_validity=True)
    list(uploaders)

    # Load SourcePackageNames.
    bulk.load_related(
        SourcePackageName, dsds, ("source_package_name_id",))