todopy Package

filter Module

class todopy.filter.StringFilter(string, model)[source]

Bases: object

Filter todo model based on a string.

Only those todos that the string matches are passed thru the filter.

>>> from model import Model
>>> m = Model()
>>> m.extend(["My first todo", "My second todo", u'Meikän unicode-todo'])
>>> f = StringFilter("second", m)
>>> len(f)
1
>>> f.total()
3
>>> list([t.todo for t in f])
['My second todo']
>>> f = StringFilter("todo", m)
>>> len(f)
3
>>> list([t.todo for t in f])
['My first todo', 'My second todo', u'Meik\xc3\xa4n unicode-todo']
>>> f = StringFilter('first', StringFilter('todo', m))
>>> len(f)
1
>>> f.total()
3
>>> list([t.todo for t in f])
['My first todo']
static find_as_utf8(needle, haystack)[source]
total()[source]

formatter Module

class todopy.formatter.ConsoleFormatter(color=False)[source]

Bases: object

color_for(priority)[source]
format(model)[source]
format_todo(todo)[source]
todopy.formatter.nop(string, *args, **kwargs)[source]

model Module

class todopy.model.Model[source]

Bases: object

Class representing a todo model.

>>> m = Model()
>>> len(m)
0
>>> m.add("My todo")
>>> len(m)
1
>>> m[0].todo
'My todo'
>>> m[0].id
1
>>> m[1]
Traceback (most recent call last):
    ...
IndexError: list index out of range
add(item)[source]

Add a todo from a string.

>>> m = Model()
>>> m.add("My todo")
>>> m[0].todo
'My todo'
append(id, text)[source]

Append text to a given todo.

>>> m = Model()
>>> m.add("My")
>>> m.append(1, 'todo')
>>> m[0].todo
'My todo'
contexts()[source]

Get all contexts defined in the todos.

>>> m = Model()
>>> m.add("My todo @context1")
>>> m.contexts()
['@context1']
>>> m.add("My other todo @context1 @context2")
>>> m.contexts()
['@context1', '@context2']
>>> m.add("Send email to address@example.com")
>>> m.contexts()
['@context1', '@context2']
extend(iterable)[source]

Extend this model with todos from some iterable.

>>> m = Model()
>>> m.add('My todo')
>>> m.extend(['My other todo'])
>>> len(m)
2
>>> m[1].todo
'My other todo'
classmethod from_store(store)[source]

Create a Model from some iterable that yields todo strings.

>>> s = ["(A) A todo", "(B) Another todo", "Third todo"]
>>> m = Model.from_store(s)
>>> len(m)
3
>>> m[0].todo
'(A) A todo'
get_by_id(id)[source]

Get todo by id.

>>> m = Model()
>>> m.add("My todo")
>>> m.add("Other todo")
>>> m.get_by_id(1).todo
'My todo'
>>> m.get_by_id(2).todo
'Other todo'
prepend(id, text)[source]

prepend text to a given todo.

>>> m = Model()
>>> m.add("todo")
>>> m.prepend(1, 'My')
>>> m[0].todo
'My todo'
projects()[source]

Get all projects defined in the todos.

>>> m = Model()
>>> m.add("My todo +project1")
>>> m.projects()
['+project1']
>>> m.add("My other todo +project1 +project2")
>>> m.projects()
['+project1', '+project2']
>>> m.add("Solve this math problem: 1+x=2")
>>> m.projects()
['+project1', '+project2']
set_done(id, done=True)[source]

Change the value of ‘done’ for a given todo.

>>> m = Model()
>>> m.add("My todo")
>>> m.set_done(1)
>>> m[0].done()
True
set_priority(id, priority)[source]

Set the priority of the todo with the given id.

If priority is None, the priority gets unset.

>>> m = Model()
>>> m.add("My todo")
>>> m.set_priority(1, "A")
>>> m[0].todo
'(A) My todo'
>>> m.set_priority(1, 'D')
>>> m[0].todo
'(D) My todo'
>>> m.set_priority(1, None)
>>> m[0].todo
'My todo'
static sort_comparator(a, b)[source]

Compare two todos and priority sort them.

>>> t1 = Todo(1, "(B) A todo")
>>> t2 = Todo(2, "(A) Another todo")
>>> Model.sort_comparator(t1, t2)
1
>>> Model.sort_comparator(t1, t1)
0
>>> Model.sort_comparator(t2, t1)
-1
total()[source]

Return the total number of items in the model.

For plain models this is the same as len(model). Filtered models must return the total unfiltered item count, i.e. total() of the original model.

class todopy.model.Todo(id, todo)[source]

Bases: object

Class representing single todo.

>>> t = Todo(1, "My todo")
>>> t.id
1
>>> t.todo
'My todo'
DONE_REGEX = '^x\\s+'
PRIORITY_REGEX = '^\\(([A-Z])\\)\\s+'
append(text)[source]

Append string to todo text, separated by a space.

>>> t = Todo(2, "My")
>>> t.append('todo')
>>> t.todo
'My todo'
done()[source]

Check done state of todo.

>>> t = Todo(1, "My todo")
>>> t.done()
False
prepend(text)[source]

Prepend string to todo text, separated by a space.

Takes care to keep priority in correct place

>>> t = Todo(2, "(A) todo")
>>> t.prepend('My')
>>> t.todo
'(A) My todo'
priority()[source]

Get priority.

>>> t = Todo(1, "My todo")
>>> t.priority()
>>> t.set_priority('A')
>>> t.priority()
'A'
set_done(done=True)[source]

Change ‘done’ state of this todo.

>>> t = Todo(1, "(A) My todo")
>>> t.set_done()
>>> t.todo
'x My todo'
set_priority(priority)[source]

Set priority, or remove if None.

>>> t = Todo(1, "My todo")
>>> t.set_priority('A')
>>> t.todo
'(A) My todo'
>>> t.set_priority(None)
>>> t.todo
'My todo'

munger Module

class todopy.munger.ContextRemover(model)[source]

Bases: object

Munger class that removes contexts from output

>>> from model import Model
>>> m = Model()
>>> m.extend(["foo @fooctx", "bar @barctx @fooctx", "@fooctx foobar@example.com"])
>>> list([t.todo for t in ContextRemover(m)])
['foo', 'bar', 'foobar@example.com']
>>> len(ContextRemover(m)) == len(m)
True
>>> ContextRemover(m).total() == len(m)
True
total()[source]
class todopy.munger.ProjectRemover(model)[source]

Bases: object

Munger class that removes projects from output

>>> from model import Model
>>> m = Model()
>>> m.extend(["foo +fooproj", "bar +barproj", "+fooproj foobar 1+x=5"])
>>> list([t.todo for t in ProjectRemover(m)])
['foo', 'bar', 'foobar 1+x=5']
>>> len(ProjectRemover(m)) == len(m)
True
>>> ProjectRemover(m).total() == len(m)
True
total()[source]

options Module

class todopy.options.Options(description=None, **kwargs)[source]

Bases: object

Combined command line args and config file parser.

There are three types of args: flags, options and positional arguments. Flags have boolean values, options and positionals unicode values.

>>> o = Options('description')
>>> o.add_flag('my_flag', help='Help for my flag')
>>> o.add_flag('other_flag', help='Help for my other flag')
>>> o.add_flag('yet_another', help='Yet another flag')
>>> o.add_option('thingy', group='other', help='Set thingy')
>>> o.add_flag('flaggy', group='other')
>>> o.add_argument('widget')

Arguments also have optional counts: ‘*’ for 0..n, ‘+’ for 1..n or any integer. Specifying a count makes the argument’s value always be a list. Not specifying the count makes the value be a plain value.

You can pass the ‘dest’ keyword-only argument to add_argument for nicer, pluralized access to list-valued arguments.

>>> o.add_argument('id', dest='ids', group='other', type=int, count='*')
>>> o.parse(argv=['--my_flag', '-y', '--thingy', 'babar 1234', 'frobozz', '1', '2', '3'])
>>> o.main.my_flag
True
>>> o.main.other_flag
False
>>> o.main.yet_another
True
>>> o.other.thingy
u'babar 1234'
>>> o.other.flaggy
False
>>> o.main.widget
u'frobozz'
>>> o.other.ids
[1, 2, 3]
add_argument(argument, **kwargs)[source]

Add a positional argument.

add_flag(flag, **kwargs)[source]

Add a boolean flag.

Command line options will be derived from flag name. Config file setting will have the same name as the flag, and the value will be accessible via an attribute with the same name also. If group keyword-only argument is not specified, the flag will be in the ‘main’ group. If default keyword-only argument is not specified, the default is True. Help text is specified with the help keyword- only argument.

add_option(option, **kwargs)[source]

Add an option taking a unicode argument.

Command line options will be derived from option name. Config file setting will have the same name as the option, and the value will be accessible via an attribute with the same name also. If group keyword-only argument is not specified, the option will be in the ‘main’ group. If default keyword-only argument is not specified, the default is None. Help text is specified with the help keyword- only argument.

add_subcommand(command, **kwargs)[source]

Add a subcommand.

Subcommands create a new argument group. To add a subcommand-specific command-line argument and option, pass the subcommand’s name as group.

>>> o = Options()
>>> o.add_subcommand('frob', help='frob the widget')
>>> o.add_flag('foo')
>>> o.add_flag('bar')
>>> o.add_flag('baz', group='frob')
>>> o.parse(argv=['-f', 'frob', '--baz'])

After parsing, the subcommand used is available as the “command” attribute.

>>> o.command
u'frob'
>>> o.frob.baz
True
parse(**kwargs)[source]

Parse command line and config file.

By default parser sys.argv, but command line args can be passed as an array too. To parse a config file too, pass ‘config_file’ kwarg. Passing that argument will also enable the config file command line option, with the default set to whatever the value of the kwarg is.

>>> import tempfile; import os
>>> (handle, filename) = tempfile.mkstemp(); os.close(handle)
>>> f = open(filename, 'w+')
>>> f.write("[main]\n")
>>> f.write("my_flag = yes\n")
>>> f.write("[mygroup]\n")
>>> f.write("a_setting = blah blah raspberry 3.14159")
>>> f.close()
>>> o = Options()
>>> o.add_flag('my_flag', default=False)
>>> o.add_flag('other_flag', default=False)
>>> o.add_option('a_setting', group='mygroup')
>>> o.parse(argv=['-o'], config_file=filename)
>>> o.main.my_flag
True
>>> o.main.other_flag
True
>>> o.mygroup.a_setting
u'blah blah raspberry 3.14159'

parse() can only be called once for a given Options instance.

>>> o.parse(argv=['--my_flag'])
Traceback (most recent call last):
...
RuntimeError: parse can only be called once for any given Options instance.

Config file overrides defaults, and command line overrides config file.

>>> o = Options()
>>> o.add_flag('my_flag', default=True)
>>> o.add_option('a_setting', group='mygroup', default='asdf')
>>> o.parse(argv=['--my_flag'], config_file=filename)
>>> o.main.my_flag
False
>>> o.mygroup.a_setting
u'blah blah raspberry 3.14159'

reader Module

class todopy.reader.FileReader(filename)[source]

Bases: object

todopy Module

todopy.todopy.main()[source]

writer Module

class todopy.writer.FileWriter(filename)[source]

Bases: object

write(model)[source]

Table Of Contents

Previous topic

Welcome to todopy’s documentation!

This Page