Пример #1
0
def conglomerate(messages, **config):
    """ Return a list of messages with some of them grouped into conglomerate
    messages.  Conglomerate messages represent several other messages.

    For example, you might pass this function a list of 40 messages.
    38 of those are git.commit messages, 1 is a bodhi.update message, and 1 is
    a badge.award message.  This function could return a list of three
    messages, one representing the 38 git commit messages, one representing the
    bodhi.update message, and one representing the badge.award message.

    Functionality is provided by fedmsg.meta plugins on a "best effort" basis.
    """

    # First, give every registered processor a chance to do its work
    for processor in processors:
        messages = processor.conglomerate(messages, **config)

    # Then, just fake it for every other ungrouped message.
    for i, message in enumerate(messages):
        # If these were successfully grouped, then skip
        if 'msg_ids' in message:
            continue

        # For ungrouped ones, replace them with a fake conglomerate
        messages[i] = BaseConglomerator.produce_template([message], **config)
        # And fill out the fields that fully-implemented conglomerators would
        # normally fill out.
        messages[i].update({
            'link': msg2link(message, **config),
            'subtitle': msg2subtitle(message, **config),
            'secondary_icon': msg2secondary_icon(message, **config),
        })

    return messages
Пример #2
0
def conglomerate(messages, subject=None, lexers=False, **config):
    """ Return a list of messages with some of them grouped into conglomerate
    messages.  Conglomerate messages represent several other messages.

    For example, you might pass this function a list of 40 messages.
    38 of those are git.commit messages, 1 is a bodhi.update message, and 1 is
    a badge.award message.  This function could return a list of three
    messages, one representing the 38 git commit messages, one representing the
    bodhi.update message, and one representing the badge.award message.

    The ``subject`` argument is optional and will return "subjective"
    representations if possible (see msg2subjective(...)).

    Functionality is provided by fedmsg.meta plugins on a "best effort" basis.
    """

    # First, give every registered processor a chance to do its work
    for processor in processors:
        messages = processor.conglomerate(messages, subject=subject, **config)

    # Then, just fake it for every other ungrouped message.
    for i, message in enumerate(messages):
        # If these were successfully grouped, then skip
        if 'msg_ids' in message:
            continue

        # For ungrouped ones, replace them with a fake conglomerate
        messages[i] = BaseConglomerator.produce_template([message],
                                                         subject=subject,
                                                         lexers=lexers,
                                                         **config)
        # And fill out the fields that fully-implemented conglomerators would
        # normally fill out.
        messages[i].update({
            'link':
            msg2link(message, **config),
            'subtitle':
            msg2subtitle(message, **config),
            'subjective':
            msg2subjective(message, subject=subject, **config),
            'secondary_icon':
            msg2secondary_icon(message, **config),
        })

    return messages
Пример #3
0
 def subtitle(self, msg, **config):
     if self.title(msg, **config) == 'pub.container.sign':
         template = self._("image {0} "
                           "was signed with key {1} in {2}")
         return template.format(msg['msg']['image_name'],
                                msg['msg']['sig_key_id'].lower(),
                                msg['headers'].get('target', '"unspecified"'))
     template = self._("{agent}'s {source} push to {target} "
                       "of {files} {status}")
     items = [item.split('/')[-1] for item in msg['msg']['file_list']]
     files = BaseConglomerator.list_to_series(items)
     status_lookup = {
         'OPEN': self._('just started'),
         'CLOSED': self._('completed successfully'),
         'FAILED': self._('failed'),
     }
     unhandled_status = self._('entered an unknown state')
     status = status_lookup.get(msg['msg']['state'], unhandled_status)
     agent = self.agent(msg, **config) or self._('unknown')
     return template.format(
         files=files,
         status=status,
         agent=agent,
         **msg['msg'])