-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib2do.py
49 lines (45 loc) · 1.46 KB
/
lib2do.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
45
46
47
48
49
import os
import sys
import pdb
import logging
logging.basicConfig(level=logging.DEBUG, filename =
os.path.expanduser("~/.2do.log") , filemode = "w")
class entry:
def __init__(self,line):
self.text=line.strip("\n")
self.contents = line.strip()
self.isReference = False
self.isTask = False
if self.contents == "":
pass
elif self.contents[0:2] == "./":
self.isReference = True
elif self.contents[0] == "*":
self.isTask = True
class taskContext:
def __init__(self,filename):
self.name = filename
self.fullpath = os.path.abspath(filename)
self.entries = []
try:
todofile = open(filename, "r+")
for line in todofile:
self.entries.append(entry(line))
except:
print "Opening file \"%s\" failed." % filename
def allTasks(self):
all = []
#pdb.set_trace()
logging.debug("Running allTasks() from "+self.fullpath)
os.chdir(os.path.dirname(self.fullpath))
for item in self.entries:
if item.isReference:
subtasks = taskContext(item.contents).allTasks()
for task in subtasks:
all.append(task)
os.chdir(os.path.dirname(self.fullpath))
else:
all.append(item)
return all
# def addTask(self, input):
# self.entries.append()