sauron Internals

Overview

saroun provides a thin wrapper around Saruon so that programs running outside of emacs can send notifications via the shell, either remotely or locally, without needing to use dbus or other methods. sauron requires that your system runs Emacs as a daemon, and contains support for multiple emacs daemons running on the same system or under the same user account.

Although you can run the command directly, as described in sauron, you will typically use sauron by way of the NotificationMessage() class, or in another shell script.

Implementation

The implementation of the sauron has the following components:

Data

sauron.work_emacs_daemons

A list of “work” emacs daemons.

sauron.personal_emacs_daemons

A list of “personal” emacs daemons.

sauron.emacs_daemons

A new list consisting of all the elements of work_emacs_daemons and personal_emacs_daemons.

The first instance in this list is always the “default” emacs used in other scripts.

The distinction between “work” and personal allows you to maintain different log files. Coordinate these variables with the paths to the log files in wc_track.

Methods

sauron.parse_message(message)

Processes messages, to normalize formats for messages submitted as strings or via the command line for use by Sauron.

Interfaces and Classes

class sauron.NotificationMessage(source=<hostname>, target=<emacs_daemon>, priority=<3>, message=<None>)

NotificationMessage() is the primary interface for sauron and the other modules in the stl suite as well as by the main() method. When creating NotificationMessage() objects, you only need to pass the message argument. Read the documentation of the following default instance objects in the NotificationMessage() class for information about the parameters:

target

Defaults to the first item in emacs_daemons array. Used to determine to which emacs instance send() will deliver the notification.

priority

Defaults to 3, which is the lowest priority of Sauron messages that are conveyed to emacs users by default. Sauron hides lower priorities unless users configure a different threshold.

source

A string, passed to sauron for the Orig field of the Sauron display. Use this to describe or specify the process or script that sends the notification. Defaults to the system hostname.

message

The test of the massage. You must specify a value for this variable.

NotificationMessage.send()

Call the send() to send a message to Sauron as configured, as in the following invocation:

n = NotificationMessage( message="this is a test message.")
n.send()
NotificationMessage.log()

log() is equivalent to send() except that it write message to a log file. This method will attempt to import the wc_track.work_log and wc_track.personal_log values from the wc_track module, and will output the log message to standard out if there are no log files specified.

Consider the following invocation:

n = NotificationMessage( message="this is a test message.")
n.log()
sauron.cli()

Collects input from the command line using argparse. See sauron Manual for more information about the command line interface.

The return value of cli() is the output of argparse.ArgumentParser.parse_args().

sauron.main()

The entrance point for sauron when called from the command line. Collects output from cli(), creates a NotificationMessage object, and then calls send() on the object.

Extension and Development

In many ways, the entire stl suite is a wrapper and extension of the sauron module. Future development of sauron will focus on more flexible logging, options to provide more structured logs, and increased capacity with other emacs configurations. The command line interface might benefit from some additional work or other changes.

NotificationMessage encapsulates all functionality, and makes it easy to wrap and send notifications from other scripts.