taskw package

Submodules

taskw.exceptions module

exception taskw.exceptions.TaskwarriorError(command, stderr, stdout, code)[source]

Bases: Exception

taskw.task module

class taskw.task.Task(data, udas=None)[source]

Bases: dict

FIELDS = {'annotations': <AnnotationArrayField 'Annotations'>, 'depends': <CommaSeparatedUUIDField 'Depends Upon'>, 'description': <StringField 'Description'>, 'due': <DateField 'Due'>, 'end': <DateField 'Ended'>, 'entry': <DateField 'Entered'>, 'id': <NumericField 'ID'>, 'imask': <NumericField 'Imask'>, 'mask': <StringField 'Mask'>, 'modified': <DateField 'Modified'>, 'parent': <StringField 'Parent'>, 'priority': <ChoiceField 'Priority'>, 'project': <StringField 'Project'>, 'recur': <DurationField 'Recurrence'>, 'scheduled': <DateField 'Scheduled'>, 'start': <DateField 'Started'>, 'status': <ChoiceField 'Status'>, 'tags': <ArrayField 'Tags'>, 'until': <DateField 'Until'>, 'urgency': <NumericField 'Urgency'>, 'uuid': <UUIDField 'UUID'>, 'wait': <DateField 'Wait'>}
classmethod from_input(input_file=<_io.TextIOWrapper name='<stdin>' mode='r' encoding='UTF-8'>, modify=False, udas=None)[source]

Create a Task directly from stdin by reading one line. If modify=True, two lines are expected, which is consistent with the Taskwarrior hook system. The first line is interpreted as the original state of the Task, and the second one as the new, modified state.

Parameters:
  • input_file – Input file. Defaults to sys.stdin.
  • modify – Flag for on-modify hook event. Defaults to False.
  • udas – Taskrc udas. Defaults to None.

:return Task

classmethod from_stub(data, udas=None)[source]

Create a Task from an already deserialized dict.

get(k[, d]) → D[k] if k in D, else d. d defaults to None.[source]
get_changes(serialized=False, keep=False)[source]

Get a journal of changes that have occurred

Parameters:
  • serialized – Return changes in the serialized format used by TaskWarrior.
  • keep_changes – By default, the list of changes is reset after running .get_changes; set this to True if you would like to keep the changes recorded following running this command.
Returns:

A dictionary of 2-tuples of changes, where the key is the name of the field that has changed, and the value is a 2-tuple containing the original value and the final value respectively.

serialized()[source]

Returns a serialized representation of this task.

serialized_changes(keep=False)[source]
set(key, value)[source]

Set a key’s value regardless of whether a change is seen.

update(values, force=False)[source]

Update this task dictionary

Returns:A dictionary mapping field names specified to be updated and a boolean value indicating whether the field was changed.

taskw.taskrc module

class taskw.taskrc.TaskRc(path=None, overrides=None)[source]

Bases: dict

Access the user’s taskRC using a dictionary-like interface.

There is a downside, though:

Unfortunately, collapsing our configuration into a dict has a jarring limitation – we can’t store both of the following simultaneously:

  • color = on
  • color.header = something

In this module, we err on the side of storing subkeys rather than the actual value in situations where both are necessary.

Please forgive me.

UDA_TYPE_MAP = {'date': <class 'taskw.fields.date.DateField'>, 'duration': <class 'taskw.fields.duration.DurationField'>, 'numeric': <class 'taskw.fields.numeric.NumericField'>, 'string': <class 'taskw.fields.string.StringField'>}
get_udas()[source]
update([E, ]**F) → None. Update D from dict/iterable E and F.[source]

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

taskw.taskrc.sanitize(line)[source]

taskw.utils module

Various utilties

taskw.utils.annotation_exists_in_list(authoritative, new)[source]
taskw.utils.annotation_list_to_comparison_map(annotations)[source]
taskw.utils.clean_ctrl_chars(s)[source]

Clean string removing most (but not all) control characters

taskw.utils.clean_task(task)[source]

Clean a task by replacing any dangerous characters

taskw.utils.convert_dict_to_override_args(config, prefix='')[source]

Converts a dictionary of override arguments into CLI arguments.

  • Converts leaf nodes into dot paths of key names leading to the leaf node.
  • Does not include paths to leaf nodes not being non-dictionary type.

See taskw.test.test_utils.TestUtils.test_convert_dict_to_override_args for details.

taskw.utils.decode_task(line)[source]

Parse a single record (task) from a task database file.

I don’t understand why they don’t just use JSON or YAML. But that’s okay.

>>> decode_task('[description:"Make a python API for taskwarrior"]')
{'description': 'Make a python API for taskwarrior'}
taskw.utils.encode_query(value, version, query=True)[source]
taskw.utils.encode_task(task)[source]

Convert a dict-like task to its string representation

taskw.utils.encode_task_experimental(task)[source]

Convert a dict-like task to its string representation Used for adding a task via task add

taskw.utils.encode_task_value(key, value, query=False)[source]
taskw.utils.get_annotation_value(annotation)[source]

Can either be a dictionary, or a string.

taskw.utils.make_annotation_comparable(annotation)[source]

Make an annotation comparable.

Some transformations occur internally when storing a message in Taskwarrior. Let’s flatten those out.

taskw.utils.merge_annotations(left, right)[source]

taskw.warrior module

Code to interact with taskwarrior

This module contains an abstract base class and two different implementations for interacting with taskwarrior: TaskWarriorDirect and TaskWarriorShellout.

If it is determined that there is a binary ‘task’ on the system and that it is of a sufficiently advanced version, then TaskWarriorShellout will be made the default TaskWarrior class. If not, then the default TaskWarrior class will fall back to the older TaskWarriorDirect implementation.

class taskw.warrior.Command[source]

Bases: object

Encapsulates available commands.

ALL = 'all'
COMPLETED = 'completed'
PENDING = 'pending'
classmethod files(command)[source]
class taskw.warrior.DataFile[source]

Bases: object

Encapsulates data file names.

COMPLETED = 'completed'
PENDING = 'pending'
classmethod filename(name)[source]
class taskw.warrior.Status[source]

Bases: object

Encapsulates task status values.

COMPLETED = 'completed'
DELETED = 'deleted'
PENDING = 'pending'
WAITING = 'waiting'
classmethod is_pending(status)[source]

Identifies if the specified status is a ‘pending’ state.

classmethod to_file(status)[source]

Returns the file in which this task is stored.

taskw.warrior.TaskWarrior

alias of taskw.warrior.TaskWarriorShellout

class taskw.warrior.TaskWarriorBase(config_filename='~/.taskrc', config_overrides=None, marshal=False)[source]

Bases: object

The task warrior

Really though, a python object with methods allowing you to interact with a taskwarrior database.

filter_by(func)[source]
get_task(**kw)[source]
classmethod load_config(config_filename='~/.taskrc', overrides=None)[source]

Load ~/.taskrc into a python dict

>>> config = TaskWarrior.load_config()
>>> config['data']['location']
'/home/threebean/.task'
>>> config['_forcecolor']
'yes'
load_tasks(command='all')[source]

Load all tasks.

Similar to TaskWarrior, a specific command may be specified:

all - a list of all issues pending - a list of all pending issues completed - a list of all completed issues

By default, the ‘all’ command is run.

>>> w = TaskWarrior()
>>> tasks = w.load_tasks()
>>> tasks.keys()
['completed', 'pending']
>>> type(tasks['pending'])
<type 'list'>
>>> type(tasks['pending'][0])
<type 'dict'>
task_add(description, tags=None, **kw)[source]

Add a new task.

Takes any of the keywords allowed by taskwarrior like proj or prior.

task_delete(**kw)[source]
task_done(**kw)[source]
task_start(**kw)[source]
task_stop(**kw)[source]
task_update(task)[source]
class taskw.warrior.TaskWarriorShellout(config_filename='~/.taskrc', config_overrides=None, marshal=False)[source]

Bases: taskw.warrior.TaskWarriorBase

Interacts with taskwarrior by invoking shell commands.

This is currently the supported version and should be considered stable.

See https://github.com/ralphbean/taskw/pull/15 for discussion and https://github.com/ralphbean/taskw/issues/30 for more.

DEFAULT_CONFIG_OVERRIDES = {'confirmation': 'no', 'dependency': {'confirmation': 'no'}, 'json': {'array': 'TRUE'}, 'verbose': 'nothing'}
filter_tasks(filter_dict)[source]

Return a filtered list of tasks from taskwarrior.

Filter dict should be a dictionary mapping filter constraints with their values. For example, to return only pending tasks, you could use:

{'status': 'pending'}

Or, to return tasks that have the word “Abjad” in their description that are also pending:

{
    'status': 'pending',
    'description.contains': 'Abjad',
}

Filters can be quite complex, and are documented on Taskwarrior’s website.

get_configuration_override_args()[source]
get_task(**kw)[source]
classmethod get_version()[source]
classmethod is_supported_version()[source]

Returns true if minimum runtime requirements are met

load_tasks(command='all')[source]

Returns a dictionary of tasks for a list of command.

sync(init=False)[source]
task_add(description, tags=None, **kw)[source]

Add a new task.

Takes any of the keywords allowed by taskwarrior like proj or prior.

task_annotate(task, annotation)[source]

Annotates a task.

task_delete(**kw)[source]

Marks a task as deleted.

task_denotate(task, annotation)[source]

Removes an annotation from a task.

task_done(**kw)[source]
task_info(**kw)[source]
task_start(**kw)[source]

Marks a task as started.

task_stop(**kw)[source]

Marks a task as stopped.

task_update(task)[source]
exception taskw.warrior.UnsupportedVersionException[source]

Bases: Exception

taskw.warrior.open(fname, mode)

Module contents

taskw.TaskWarrior

alias of taskw.warrior.TaskWarriorShellout

class taskw.TaskWarriorShellout(config_filename='~/.taskrc', config_overrides=None, marshal=False)[source]

Bases: taskw.warrior.TaskWarriorBase

Interacts with taskwarrior by invoking shell commands.

This is currently the supported version and should be considered stable.

See https://github.com/ralphbean/taskw/pull/15 for discussion and https://github.com/ralphbean/taskw/issues/30 for more.

DEFAULT_CONFIG_OVERRIDES = {'confirmation': 'no', 'dependency': {'confirmation': 'no'}, 'json': {'array': 'TRUE'}, 'verbose': 'nothing'}
filter_tasks(filter_dict)[source]

Return a filtered list of tasks from taskwarrior.

Filter dict should be a dictionary mapping filter constraints with their values. For example, to return only pending tasks, you could use:

{'status': 'pending'}

Or, to return tasks that have the word “Abjad” in their description that are also pending:

{
    'status': 'pending',
    'description.contains': 'Abjad',
}

Filters can be quite complex, and are documented on Taskwarrior’s website.

get_configuration_override_args()[source]
get_task(**kw)[source]
classmethod get_version()[source]
classmethod is_supported_version()[source]

Returns true if minimum runtime requirements are met

load_tasks(command='all')[source]

Returns a dictionary of tasks for a list of command.

sync(init=False)[source]
task_add(description, tags=None, **kw)[source]

Add a new task.

Takes any of the keywords allowed by taskwarrior like proj or prior.

task_annotate(task, annotation)[source]

Annotates a task.

task_delete(**kw)[source]

Marks a task as deleted.

task_denotate(task, annotation)[source]

Removes an annotation from a task.

task_done(**kw)[source]
task_info(**kw)[source]
task_start(**kw)[source]

Marks a task as started.

task_stop(**kw)[source]

Marks a task as stopped.

task_update(task)[source]
taskw.clean_task(task)[source]

Clean a task by replacing any dangerous characters

taskw.encode_task(task)[source]

Convert a dict-like task to its string representation

taskw.decode_task(line)[source]

Parse a single record (task) from a task database file.

I don’t understand why they don’t just use JSON or YAML. But that’s okay.

>>> decode_task('[description:"Make a python API for taskwarrior"]')
{'description': 'Make a python API for taskwarrior'}
taskw.encode_task_experimental(task)[source]

Convert a dict-like task to its string representation Used for adding a task via task add