toxicnotifications package

Submodules

toxicnotifications.base module

class toxicnotifications.base.MetaNotification(name, bases, attrs)[source]

Bases: PluginMeta, TopLevelDocumentMetaclass

Metaclass that sets name to the class definition as mongo fields while keeping the interface of setting your notification’s name as string in definition time.

class toxicnotifications.base.Notification(*args, **kwargs)[source]

Bases: LoggerMixin, Plugin, Document

Base class for notifications. It creates 3 fields:

  • repository_id: The id of the repository that sends notifications.

  • branches: A list of branches that may send notifications. If no branch, all branches may send messages.

  • statuses: A list of statuses that may send notifications. If no status, all statuses may send notifications.

exception DoesNotExist

Bases: DoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

branches
description = 'Base for notifications'
events = ['buildset-started', 'buildset-finished']
classmethod get_repo_notifications(repository_id, event=None)[source]

Returns a queryset with the notifications for a given repository and event.

Parameters:
  • repository_id – The id of the repository that sent an event.

  • event – The event that will trigger notifications.

classmethod get_schema(to_serialize=False)[source]

Returns a dictionary with the schema of the plugin.

id

A field wrapper around MongoDB’s ObjectIds.

name = 'BaseNotification'
no_list = False
objects

The default QuerySet Manager.

Custom QuerySet Manager functions can extend this class and users can add extra queryset functionality. Any custom manager methods must accept a Document class as its first argument, and a QuerySet as its second argument.

The method function should return a QuerySet , probably the same one that was passed in, but modified in some way.

pretty_name = ''
repository_id

A field wrapper around MongoDB’s ObjectIds.

async run(buildset_info)[source]

Executed when a notification about a build arrives. Reacts to buildsets that started or finished.

Parameters:

buildset_info – A dictionary with information about a buildset.

async send_finished_message(buildset_info)[source]

Sends a message when a buildset is finished. You must override it.

async send_started_message(buildset_info)[source]

Sends a message when a buildset is started. You must override it.

statuses
to_dict()[source]

toxicnotifications.cmds module

class toxicnotifications.cmds.SettingsPatcher[source]

Bases: MonkeyPatcher

Patches the settings from pyrocumulus to use the same settings as toxibuild.

patch_pyro_settings(settings)[source]
toxicnotifications.cmds.create(root_dir)[source]

Creates a new toxicnotifications environment.

Parameters:

--root_dir – Root directory for toxicnotifications.

async toxicnotifications.cmds.create_auth_token(workdir=None)[source]
toxicnotifications.cmds.create_token(workdir, conffile=None)[source]

Creates an access token for the notifications api.

Parameters:
  • workdir – Work directory for server.

  • --conffile (-c,) – path to config file. Defaults to None. If not conffile, will look for a file called toxicnotifications.conf inside workdir.

toxicnotifications.cmds.notifications_init(addr, port, use_ssl, certfile, keyfile, loglevel)[source]
toxicnotifications.cmds.output_handler_init(handler)[source]

Starts the output server

toxicnotifications.cmds.restart(workdir, pidfile='toxicnotifications.pid', loglevel='info')[source]

Restarts toxicnotifications

The instance of toxicnotifications in workdir will be restarted. :param workdir: Workdir for instance to be killed. :param –pidfile: Name of the file to use as pidfile. :param –loglevel: Level for logging messages.

toxicnotifications.cmds.start(workdir, daemonize=False, stdout='./toxicnotifications.log', stderr='./toxicnotifications.log', conffile=None, loglevel='info', pidfile='toxicnotifications.pid')[source]

Starts toxicnotifications.

Parameters:
  • workdir – Work directory for server.

  • --daemonize – Run as daemon. Defaults to False

  • --stdout – stdout path. Defaults to /dev/null

  • --stderr – stderr path. Defaults to /dev/null

  • --conffile (-c,) – path to config file. Defaults to None. If not conffile, will look for a file called toxicnotifications.conf inside workdir

  • --loglevel – Level for logging messages. Defaults to info.

  • --pidfile – Name of the file to use as pidfile. Defaults to toxicnotifications.pid

toxicnotifications.cmds.stop(workdir, pidfile='toxicnotifications.pid', kill=False)[source]

Stops toxicnotifications.

Parameters:
  • workdir – Work directory for the ui to be killed.

  • --pidfile – pid file for the process.

  • kill – If true, send signum 9, otherwise, 15.

toxicnotifications.custom_webhook module

class toxicnotifications.custom_webhook.CustomWebhookNotification(*args, **kwargs)[source]

Bases: Notification

Sends a POST request to a custom URL. The request content type is application/json and the body of the request has a json with information about a buildset.

exception DoesNotExist

Bases: DoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

description = 'Sends messages to a custom webhook.'
name = 'custom-webhook'
no_list = False
pretty_name = 'Custom Webhook'
async send_finished_message(buildset_info)[source]

Sends a message when a buildset is finished. You must override it.

async send_started_message(buildset_info)[source]

Sends a message when a buildset is started. You must override it.

webhook_url

toxicnotifications.fields module

class toxicnotifications.fields.PrettyFieldMixin(*args, **kwargs)[source]

Bases: object

A field with a descriptive name for humans

class toxicnotifications.fields.PrettyListField(*args, **kwargs)[source]

Bases: PrettyFieldMixin, ListField

class toxicnotifications.fields.PrettyStringField(*args, **kwargs)[source]

Bases: PrettyFieldMixin, StringField

class toxicnotifications.fields.PrettyURLField(*args, **kwargs)[source]

Bases: PrettyFieldMixin, URLField

toxicnotifications.mail module

class toxicnotifications.mail.EmailNotification(*args, **kwargs)[source]

Bases: Notification

Sends notification about buildsets through email

exception DoesNotExist

Bases: DoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

description = 'Sends email messages'
name = 'email-notification'
no_list = False
pretty_name = 'Email'
recipients
async send_finished_message(buildset_info)[source]

Sends a message when a buildset is finished. You must override it.

async send_started_message(buildset_info)[source]

Sends a message when a buildset is started. You must override it.

class toxicnotifications.mail.MailSender(recipients)[source]

Bases: MailSender

Mail sender that take its configurations from the settings file

async toxicnotifications.mail.send_email(recipients, subject, message)[source]

toxicnotifications.server module

class toxicnotifications.server.NotificationsProtocol(loop, connection_lost_cb=None)[source]

Bases: BaseToxicProtocol

actions = {'disable-notification', 'enable-notification', 'list-notifications', 'send-email', 'update-notification'}
async client_connected()[source]

Coroutine that handles connections. You must implement this in your sub-classes. When this method is called, self.data, containing a dictionary with the data passed in the request and self.action, a string indicating which action to take are already available.

async disable_notification()[source]
async enable_notification()[source]
property encrypted_token

The type of the None singleton.

async list_notifications()[source]
async send_email()[source]
async update_notification()[source]
class toxicnotifications.server.NotificationsServer(*args, **kwargs)[source]

Bases: ToxicServer

PROTOCOL_CLS

alias of NotificationsProtocol

async shutdown()[source]

Overwrite this to handle the shutdown of your server

start()[source]

Starts the build server.

class toxicnotifications.server.OutputMessageHandler(loop=None)[source]

Bases: LoggerMixin

Fetchs messages from notification queues and dispatches the needed output methods.

EXCHANGE = <toxiccommon.exchange.Exchange object>
add_running_task()[source]
remove_running_task()[source]
async run()[source]
async run_notifications(msg)[source]

Runs all notifications for a given repository that react to a given event type.

Parameters:

msg – The incomming message from a notification

async shutdown()[source]
sync_shutdown(signum=None, frame=None)[source]
toxicnotifications.server.run_server(addr='0.0.0.0', port=1234, loop=None, use_ssl=False, **ssl_kw)[source]

toxicnotifications.slack module

class toxicnotifications.slack.SlackNotification(*args, **kwargs)[source]

Bases: Notification

Plugin that send notifications about builds to slack.

exception DoesNotExist

Bases: DoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

channel_name
description = 'Sends messages to a slack channel'
name = 'slack-notification'
no_list = False
pretty_name = 'Slack'
async send_finished_message(buildset_info)[source]

Sends a message when a buildset is finished. You must override it.

async send_started_message(buildset_info)[source]

Sends a message when a buildset is started. You must override it.

webhook_url

Module contents

toxicnotifications.create_settings_and_connect()[source]