“Natural Language” Representation of Messages

fedmsg.meta handles the conversion of fedmsg messages (dict-like json objects) into internationalized human-readable strings: strings like "nirik voted on a tag in tagger" and "lmacken commented on a bodhi update."

The intent is to use the module 1) in the fedmsg-irc bot and 2) in the gnome-shell desktop notification widget. The sky is the limit, though.

The primary entry point is fedmsg.meta.msg2repr() which takes a dict and returns the string representation. Portions of that string are in turn produced by fedmsg.meta.msg2title(), fedmsg.meta.msg2subtitle(), and fedmsg.meta.msg2link().

Message processing is handled by a list of MessageProcessors (instances of fedmsg.meta.base.BaseProcessor) which are discovered on a setuptools entry-point. Messages for which no MessageProcessor exists are handled gracefully.

The original deployment of fedmsg in Fedora Infrastructure uses metadata providers/message processors from a plugin called fedmsg_meta_fedora_infrastructure. If you’d like to add your own processors for your own deployment, you’ll need to extend fedmsg.meta.base.BaseProcessor and override the appropriate methods. If you package up your processor and expose it on the fedmsg.meta entry-point, your new class will need to be added to the fedmsg.meta.processors list at runtime.

End users can have multiple plugin sets installed simultaneously.

exception fedmsg.meta.ProcessorsNotInitialized

Bases: exceptions.Exception

fedmsg.meta.legacy_condition(cls)
fedmsg.meta.make_processors(**config)

Initialize all of the text processors.

You’ll need to call this once before using any of the other functions in this module.

>>> import fedmsg.config
>>> import fedmsg.meta
>>> config = fedmsg.config.load_config([], None)
>>> fedmsg.meta.make_processors(**config)
>>> text = fedmsg.meta.msg2repr(some_message_dict, **config)
fedmsg.meta.msg2avatars(msg, legacy=False, **config)

Return a dict mapping of usernames to avatar URLs.

fedmsg.meta.msg2emails(msg, legacy=False, **config)

Return a dict mapping of usernames to email addresses.

fedmsg.meta.msg2icon(msg, legacy=False, **config)

Return a primary icon associated with a message.

Return a URL associated with a message.

fedmsg.meta.msg2objects(msg, legacy=False, **config)

Return a set of objects associated with a message.

“objects” here is the “objects” from english grammar.. meaning, the thing in the message upon which action is being done. The “subject” is the user and the “object” is the packages, or the wiki articles, or the blog posts.

Where possible, use slash-delimited names for objects (as in wiki URLs).

fedmsg.meta.msg2packages(msg, legacy=False, **config)

Return a set of package names associated with a message.

fedmsg.meta.msg2processor(msg, **config)

For a given message return the text processor that can handle it.

This will raise a fedmsg.meta.ProcessorsNotInitialized exception if fedmsg.meta.make_processors() hasn’t been called yet.

fedmsg.meta.msg2repr(msg, legacy=False, **config)

Return a human-readable or “natural language” representation of a dict-like fedmsg message. Think of this as the ‘top-most level’ function in this module.

fedmsg.meta.msg2secondary_icon(msg, legacy=False, **config)

Return a secondary icon associated with a message.

fedmsg.meta.msg2subtitle(msg, legacy=False, **config)

Return a ‘subtitle’ or secondary text associated with a message.

fedmsg.meta.msg2title(msg, legacy=False, **config)

Return a ‘title’ or primary text associated with a message.

fedmsg.meta.msg2usernames(msg, legacy=False, **config)

Return a set of FAS usernames associated with a message.

fedmsg.meta.with_processor()
fedmsg.meta.processors = ProcessorsNotInitialized('You must first call fedmsg.meta.make_processors(**config)',)
class fedmsg.meta.base.BaseProcessor(internationalization_callable, **config)

Bases: object

Base Processor. Without being extended, this doesn’t actually handle any messages.

Processors require that an internationalization_callable be passed to them at instantiation. Internationalization is often done at import time, but we handle it at runtime so that a single process may translate fedmsg messages into multiple languages. Think: an IRC bot that runs #fedora-fedmsg, #fedora-fedmsg-es, #fedora-fedmsg-it. Or: a twitter bot that posts to multiple language-specific accounts.

That feature is currently unused, but fedmsg.meta supports future internationalization (there may be bugs to work out).

avatars(msg, **config)

Return a dict of avatar URLs associated with a message.

emails(msg, **config)

Return a dict of emails associated with a message.

handle_msg(msg, **config)

If we can handle the given message, return the remainder of the topic.

icon(msg, **config)

Return a “icon” for the message.

Return a “link” for the message.

objects(msg, **config)

Return a set of objects associated with a message.

packages(msg, **config)

Return a set of package names associated with a message.

secondary_icon(msg, **config)

Return a “secondary icon” for the message.

subtitle(msg, **config)

Return a “subtitle” for the message.

title(msg, **config)
usernames(msg, **config)

Return a set of FAS usernames associated with a message.

fedmsg

Previous topic

Replay

Next topic

Configuration

Edit this document

Go to “Natural Language” Representation of Messages on GitHub.

Use the web interface to fork the repo, edit the file, and send a pull request.

Your changes will be queued for review under project's Pull requests tab on Github.

Fork me on GitHub