Event¶
Note
The documentation in this section is aimed at people wishing to contribute to
rdial, and can be skipped if you are simply using the tool from the
command line.
-
class
rdial.events.Event(_Event__task, start=None, delta=None, message='')[source]¶ Initialise a new
Eventobject.- Parameters
-
stop(message=None, force=False)[source]¶ Stop running event.
- Parameters
- Raises
TaskNotRunningError – Event not running
- Return type
None
-
class
rdial.events.Events(_Events__iterable=None, backup=True)[source]¶ Initialise a new
Eventsobject.- Parameters
__iterable – Objects to add to container
backup (
bool) – Whether to create backup files
-
filter(_Events__filt)[source]¶ Apply filter to events.
- Parameters
__filt – Function to filter with
- Return type
- Returns
Events matching given filter function
-
for_task(_Events__task)[source]¶ Filter events for a specific task.
- Parameters
__task – Task name to filter on
- Return type
- Returns
Events marked with given task name
-
for_week(_Events__year, _Events__week)[source]¶ Filter events for a specific ISO-8601 week.
- Parameters
__year – Year to filter events on
__week – ISO-8601 week number to filter events on
- Return type
- Returns
Events occurring in given ISO-8601 week
-
last()[source]¶ Return current/last event.
Note
This handles the empty database case by returning
None.
-
static
read(_Events__directory, backup=True, write_cache=True)[source]¶ Read and parse database.
Note
Assumes a new
Eventsobject should be created if the directory is missing.
-
running()[source]¶ Check if an event is running.
We return the running task, if one exists, for easy access.
-
start(_Events__task, new=False, start='')[source]¶ Start a new event.
- Parameters
- Raises
TaskRunningError – An event is already running
- Return type
None
-
stop(message=None, force=False)[source]¶ Stop running event.
- Parameters
- Raises
TaskNotRunningError – No task running!
- Return type
None
Examples¶
>>> event = Event('test')
>>> event.running()
'test'
>>> event.stop('complete')
>>> event.running()
False
>>> data = event.writer()
>>> data['message']
'complete'
>>> event2 = Event('test', start="2013-01-01T12:00:00Z")
>>> events = Events([event, event2])
>>> events.filter(lambda x: x.message == 'complete')
Events([Event('test', '...', '...', 'complete')])
>>> events.for_date(2013, 1)
Events([Event('test', '2013-01-01T12:00:00Z', '', '')])
>>> events.for_week(2012, 53)
Events([Event('test', '2013-01-01T12:00:00Z', '', '')])
>>> events.running()
'test'