Decorator to set the priority attribute of a function.

class crab.util.bus.CrabStoreListener(bus)

Base class for plugins which require a store.

Listens on the “crab-store” channel, setting the instance value “store” to the store object received.

class crab.util.bus.CrabPlugin(bus, name, class_, **kwargs)

Class to launch Crab services as CherryPy plugins.

This class subscribes to the “start” channel. When it recieves a message, it constructs an instance of the service class and publishes it on the “crab-service” channel.




Restore signals which Python otherwise ignores.

For more information about this issue, please see: http://bugs.python.org/issue1652

crab.util.compat.subprocess_communicate(p, input=None, timeout=None)
crab.util.compat.subprocess_call(args, timeout=None, **kwargs)
exception crab.util.compat.TimeoutExpired


class crab.util.filter.CrabEventFilter(store, timezone=None)

Class implementing an event filtering action.

default_timezone = <UTC>

Sets the timezone used by the filter.

classmethod set_default_timezone(timezone)

Sets the default timezone for all filters.


Convert the datetime string as output by the database to a string in the specified timezone.

Includes the zone code to indicate that the conversion has been performed.



Function to try to determine the operating system’s timezone setting.

Currently this checks for a TZ environment variable. Otherwise it checks if /etc/localtime is a link or tries to find the file in /usr/share/zoneinfo which matches. It uses pytz to get a list of common timezones to try.


crab.util.pid.pidfile_write(pidfile, pid)

Attempt to write a key for the given process into the file specified.


Read the pidfile specified and check if the process is running.

If the pidfile was found then its timestamps are updated (using os.utime). This is to try to avoid the pidfile being automatically removed from temporary directories if a job runs for a very long time.


Attempt to delete the specified pidfile.


class crab.util.schedule.CrabSchedule(specifier, timezone)

Class handling the schedule of a cron job.


Determines whether the given datetime matches the scheduling rules stored in the class instance.

The datetime is converted to the stored timezone, and then the components of the time are checked against the matchers in the CronTab superclass.


return a datetime rather than number of seconds.


return a datetime rather than number of seconds.


crab.util.statuspattern.check_status_patterns(status, config, output)

Function to update a job status based on the patterns.

Compares the given output with the patterns in the job configuration, and returns the updated status.



If the given string starts and ends with matching quote marks, remove them from the returned value.

>>> remove_quotes('alpha')
>>> remove_quotes('"bravo"')
>>> remove_quotes("'charlie'")

If the quotes are mismatched it should not remove them.

>>> remove_quotes('"delta')
>>> remove_quotes("echo'")

If the given string contains space characters, return it surrounded by double quotes, otherwise return the original string.

>>> quote_multiword('alpha')
>>> quote_multiword('bravo charlie')
'"bravo charlie"'

Splits the given string on the first word boundary, unless it starts with a quote.

If quotes are present it splits at the first matching quote. Eg.:

>>> split_quoted_word('alpha bravo charlie delta echo')
['alpha', 'bravo charlie delta echo']
>>> split_quoted_word('"alpha bravo" charlie delta echo')
('alpha bravo', 'charlie delta echo')

Does not handle escaped quotes within the string.


Looks for Crab environment variables at the start of a command.

Bourne-style shells allow environment variables to be specified at the start of a command. This function takes a string corresponding to a command line to be executed by a shell, and looks for environment variables in the ‘CRAB namespace’, i.e. those consisting of CRAB followed by a number of upper case characters.

>>> split_crab_vars('some command')
('some command', {})
>>> split_crab_vars('CRABALPHA=bravo another command')
('another command', {'CRABALPHA': 'bravo'})

Returns: a tuple consisting of the remainder of the command and a dictionary of Crab’s environment variables.


Removes all non-alphanumeric characters from the string, replacing them with underscores.

>>> alphanum('a3.s_?x9!t')

Merges the lines of a string by removing newline characters.

>>> mergelines('alpha' + chr(10) + 'bravo')

Tests whether the string represents a true value.

The following strings are false:

>>> [true_string(x) for x in ['0', 'no', 'false', 'off']]
[False, False, False, False]

And anything else is taken to be true, for example:

>>> [true_string(x) for x in ['1', 'yes', 'true', 'on']]
[True, True, True, True]

The results are case insensitive.

>>> [true_string(x) for x in ['no', 'NO', 'True', 'Off']]
[False, False, True, False]


crab.util.web.abbr(text, limit=60, tolerance=10)

Returns an abbreviated and HTML-escaped version of the specified text.

The text is trimmed to the given length limit, but if a space is found within the preceeding ‘tolerance’ number of characters, then it is trimmed there. The result is an HTML span element with the full text as the title, unless it was not necessary to trim it.

>>> abbr('alpha bravo', 15, 5)
'alpha bravo'
>>> abbr('alpha bravo charlie', 15, 5)
'<span title="alpha bravo charlie">alpha bravo&hellip;</span>'