Commit d7ff4f48 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Add ability to identify tasks based on their UID.

parent 947ec5ae
......@@ -6,6 +6,7 @@ default_command = ls
; archive_filename = done.txt
colors = 1
highlight_projects_contexts = 1
identifiers = linenumber ; or: text
[ls]
indent = 0
......
......@@ -15,6 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import CommandTest
from Config import config
import SortCommand
import TestFacilities
......@@ -22,6 +23,10 @@ class SortCommandTest(CommandTest.CommandTest):
def setUp(self):
self.todolist = TestFacilities.load_file_to_todolist("data/SorterTest1.txt")
def tearDown(self):
# restore to the default configuration in case a custom one was set
config("")
def test_sort1(self):
""" Alphabetically sorted """
command = SortCommand.SortCommand(["text"], self.todolist, self.out, self.error)
......@@ -35,6 +40,17 @@ class SortCommandTest(CommandTest.CommandTest):
self.assertEquals(str(self.todolist), "(A) Foo\n2014-06-14 Last\nFirst")
def test_sort3(self):
""" Check that order does not influence the UID of a todo. """
config("data/todolist-uid.conf")
todo1 = self.todolist.todo('tpi')
command = SortCommand.SortCommand(["text"], self.todolist, self.out, self.error)
command.execute()
todo2 = self.todolist.todo('tpi')
self.assertEquals(todo1.source(), todo2.source())
def test_help(self):
command = SortCommand.SortCommand(["help"], self.todolist, self.out, self.error)
command.execute()
......
......@@ -19,6 +19,7 @@
import re
import unittest
from Config import config
import Todo
import TodoFile
from TodoListBase import InvalidTodoException
......@@ -32,6 +33,10 @@ class TodoListTester(unittest.TestCase):
self.text = ''.join(lines)
self.todolist = TodoList.TodoList(lines)
def tearDown(self):
# restore to the default configuration in case a custom one was set
config("")
def test_contexts(self):
self.assertEquals(set(['Context1', 'Context2']), \
self.todolist.contexts())
......@@ -191,6 +196,19 @@ class TodoListTester(unittest.TestCase):
self.assertTrue(todo)
self.assertEquals(todo.source(), "(D) Bar @Context1 +Project2")
def test_uid1(self):
config("data/todolist-uid.conf")
self.assertEquals(self.todolist.todo('6iu').source(), "(C) Foo @Context2 Not@Context +Project1 Not+Project")
def test_uid2(self):
""" Changing the priority should not change the identifier. """
config("data/todolist-uid.conf")
todo = self.todolist.todo('6iu')
self.todolist.set_priority(todo, 'B')
self.assertEquals(self.todolist.todo('6iu').source(), "(B) Foo @Context2 Not@Context +Project1 Not+Project")
class TodoListDependencyTester(unittest.TestCase):
def setUp(self):
self.todolist = TodoList.TodoList([])
......
[topydo]
identifiers = text
......@@ -36,6 +36,7 @@ class _Config:
'highlight_projects_contexts': '1',
'filename' : 'todo.txt',
'archive_filename' : 'done.txt',
'identifiers': 'linenumber',
# ls
'indent': 0,
......@@ -93,6 +94,9 @@ class _Config:
def archive(self):
return self.cp.get('topydo', 'archive_filename')
def identifiers(self):
return self.cp.get('topydo', 'identifiers')
def list_limit(self):
try:
return self.cp.getint('ls', 'list_limit')
......
......@@ -21,6 +21,7 @@ A list of todo items.
from datetime import date
import re
from Config import config
import Filter
from HashListValues import hash_list_values
from PrettyPrinter import pretty_print_list
......@@ -56,13 +57,23 @@ class TodoListBase(object):
The _todos list has the same order as in the backend store (usually
a todo.txt file. The user refers to the first task as number 1, so use
index 0, etc.
Alternative ways to identify a todo is using a hashed version based on
the todo's text, or a regexp that matches the todo's source. The regexp
match is a fallback.
Returns None when the todo couldn't be found.
"""
result = None
try:
if config().identifiers() == 'text':
result = self._id_todo_map[p_identifier]
else:
result = self._todos[int(p_identifier) - 1]
except IndexError:
raise InvalidTodoException
except (TypeError, ValueError):
except (TypeError, ValueError, KeyError):
result = self.todo_by_regexp(p_identifier)
return result
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment