def add(self, args): if len(args) < 1: raise TodoError("insufficient arguments") # handle project if args[0].startswith("@"): if len(args) < 2: raise TodoError("insufficient arguments") task = self.__find_task_or_project(self.tasks, args[0]) if task: task.append(Task(self.last_index, " ".join(args[1:]))) return True else: project = Project(args[0][1:]) project.append(Task(self.last_index, " ".join(args[1:]))) self.tasks.append(project) self.last_index += 1 return True # handle task else: self.tasks.append(Task(self.last_index, " ".join(args))) self.last_index += 1 return True
def test_project_add_task_str(): task = Task(1, 'test-task', 'A', str(date.today())) project = Project('test-project') project.append(task) want = '{3}@test-project{1}\n {0}1: test-task >{2}{1}'.format( term.white, term.reset, str(date.today()), term.yellow) assert project.get_pretty() == want
def add(self, args): if len(args) < 1: raise TodoError('insufficient arguments') # handle project if args[0].startswith('@'): if len(args) < 2: raise TodoError('insufficient arguments') task = self.__find_task_or_project(self.tasks, args[0]) if task: task.append(Task(self.last_index, ' '.join(args[1:]))) return True else: project = Project(args[0][1:]) project.append(Task(self.last_index, ' '.join(args[1:]))) self.tasks.append(project) self.last_index += 1 return True # handle task else: self.tasks.append(Task(self.last_index, ' '.join(args))) self.last_index += 1 return True
def test_project_add_task_str(): task = Task(1, 'test-task', 'A', str(date.today())) project = Project('test-project') project.append(task) want = '{3}@test-project{1}\n {0}1: test-task >{2}{1}'.format( term.white, term.reset, str(date.today()), term.yellow ) assert project.get_pretty() == want
def archive(self, args): archived = [] project = None for task in self.tasks: if isinstance(task, Project): archived_project = None archived_tasks = task.get_done() if archived_tasks: archived_project = Project(task.name, archived_tasks) archived.append(archived_project) elif task.done: archived.append(task) self.tasks.remove(task) if archived: date = datetime.now().isoformat() name = _archive_tmpl + '_' + date with file(name, 'w') as f: pass parserGenerator = TaskParserGenerator(name) parserGenerator.generate(archived) return True
def parse(self): tasks = [] index = 0 with file(self.file_name) as f: project = None first_line = True for line in f.readlines(): if first_line: first_line = False if not line.startswith('$version 1'): raise ValueError('incorrect version in todo file') elif line.strip() == '' or line.startswith('#'): continue elif line.startswith('@'): if project: tasks.append(project) project = Project(line[1:].strip()) else: (pri, dl, done, desc) = line.split(' ', 3) # projectless tasks if not project: index += 1 tasks.append(Task(index, desc, pri, dl if dl != '-' else None, done if done != '-' else None)) # tasks in projects else: index += 1 project.append(Task(index, desc, pri, dl if dl != '-' else None, done if done != '-' else None)) if project: tasks.append(project) return tasks, index
def parse(self): tasks = [] index = 0 with file(self.file_name) as f: project = None first_line = True for line in f.readlines(): if first_line: first_line = False if not line.startswith('$version 1'): raise ValueError('incorrect version in todo file') elif line.strip() == '' or line.startswith('#'): continue elif line.startswith('@'): if project: tasks.append(project) project = Project(line[1:].strip()) else: (pri, dl, done, desc) = line.split(' ', 3) # projectless tasks if not project: index += 1 tasks.append( Task(index, desc, pri, dl if dl != '-' else None, done if done != '-' else None)) # tasks in projects else: index += 1 project.append( Task(index, desc, pri, dl if dl != '-' else None, done if done != '-' else None)) if project: tasks.append(project) return tasks, index
def test_project_add_many_task_str(): task1 = Task(1, 'test-task1', 'A', str(date.today())) task2 = Task(2, 'test-task2', 'B', str(date.today())) project = Project('test-project') project.append(task1) project.append(task2) want = '{3}@test-project{1}\n {0}1: test-task1 >{2}{1}\n {4}2: test-task2 >{2}{1}'.format( term.white, term.reset, str(date.today()), term.yellow, term.green) print project.get_pretty() print want assert project.get_pretty() == want
def test_sort(): task0 = Task(0, 'test-desc-0', 'A') task1 = Task(0, 'test-desc-1', 'B') task2 = Task(0, 'test-desc-2', 'C') project = Project('test-project') project.append(task2) project.append(task1) project.append(task0) assert project.tasks[0] == task2 assert project.tasks[1] == task1 assert project.tasks[2] == task0 project.sort_tasks() assert project.tasks[0] == task0 assert project.tasks[1] == task1 assert project.tasks[2] == task2
def test_project_add_many_task_str(): task1 = Task(1, 'test-task1', 'A', str(date.today())) task2 = Task(2, 'test-task2', 'B', str(date.today())) project = Project('test-project') project.append(task1) project.append(task2) want = '{3}@test-project{1}\n {0}1: test-task1 >{2}{1}\n {4}2: test-task2 >{2}{1}'.format( term.white, term.reset, str(date.today()), term.yellow, term.green ) print project.get_pretty() print want assert project.get_pretty() == want