-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproject.py
44 lines (33 loc) · 1.01 KB
/
project.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from todotxt import TodoFile
from .task import Task
class Project:
def __init__(self, name, create=False):
self.name = name
self.loaded = False
self.create = create
self.refresh()
def refresh(self):
try:
self.project = TodoFile(self.name)
self.project.load()
self.loaded = True
self.create = False
except FileNotFoundError:
if not self.create:
raise
def commit(self):
self.project.save()
def add(self, task):
self.project.add_entry(task.entry)
task.project = self
def _entries(self):
return sorted(self.project.todo_entries, key=lambda x: x.priority or 'ZZ')
def tasks(self):
return map(Task, self._entries())
def first_task(self, skip_completed=True):
tasks = self.tasks()
for task in tasks:
if skip_completed and task.entry.completed:
continue
return task
return None