Make error reporting work for errors in logger.
[matthijs/upstream/mobilegtd.git] / src / model / projects.py
1 from project import Project
2 from observable import ObservableList
3 from filtered_list import FilteredList
4 #from tickler import TickleDirectory
5 #from inout.io import *
6 #
7 #project_directory = '@Projects/'
8
9 #
10 #def make_string_stripper(to_strip):
11 #    return lambda x: x.replace(to_strip,'')
12
13 class Projects(ObservableList,FilteredList):
14     def __init__(self):
15         super(Projects,self).__init__()
16     def with_status(self,status):
17         pass
18         return self.with_property(lambda p:p.status == status)
19     
20     def sorted_by_status(self):
21         return sorted(self,cmp=lambda x,y:y.status.__cmp__(x.status))
22 #    def __init__(self,project_directory):
23 #        self.review_directory = project_directory+'@Review/'
24 #        self.done_directory = project_directory+'@Done/'
25 #        self.someday_directory = project_directory+'@Someday/'
26 #        self.tickled_directory = project_directory+'@Tickled/'
27 #        self.project_dir_name = '@Projects/'
28 #
29 #        self.tickle_times=None
30 #        self.someday_contexts=None
31 #
32 #        self.root = project_directory
33 #        self.processed_projects = []
34 #        self.review_projects = []
35 #        self.someday_projects = []
36 #        self.tickled_projects = []
37 #        self.observers = []
38 #        
39 #    def get_tickle_times(self):
40 #        if self.tickle_times == None:
41 #                self.tickle_times=map(make_string_stripper(self.tickled_directory+'/'),list_dir(self.tickled_directory,True,is_dir))
42 #        return self.tickle_times
43 #    def get_someday_contexts(self):
44 #        if self.someday_contexts == None:
45 #            self.someday_contexts=map(make_string_stripper(self.someday_directory+'/'),list_dir(self.someday_directory,True,is_dir))
46 #        return self.someday_contexts
47 #        #self.notify()
48 #    def read(self,root,recursive=False):
49 #        # TODO Use generic read funct
50 #        return [Project(project_name) for project_name in list_dir(root, recursive, lambda name: name.endswith('.prj'))]
51 #    def get_all_projects(self):
52 #        return self.get_active_projects() + self.get_review_projects() + \
53 #            self.get_tickled_projects() + self.get_someday_projects()
54 #    def get_current_projects(self):
55 #        return self.get_active_projects() + self.get_review_projects()
56 #    def get_inactive_projects(self):
57 #        return self.get_tickled_projects() + self.get_someday_projects()
58 #    def get_active_projects(self):
59 #        if self.processed_projects == None:
60 #            self.processed_projects = self.read(self.root)
61 #        return self.processed_projects
62 #    def get_review_projects(self):
63 #        if self.review_projects == None:
64 #            self.review_projects = self.read(self.review_directory)
65 #        return self.review_projects
66 #    def get_tickled_projects(self):
67 #        if self.tickled_projects == None:
68 #            self.tickled_projects = self.read(self.tickled_directory,True)
69 #        return self.tickled_projects
70 #    def get_someday_projects(self):
71 #        if self.someday_projects == None:
72 #            self.someday_projects = self.read(self.someday_directory,True)
73 #        return self.someday_projects
74 #    def get_current_tickled_projects(self):
75 #        current_tickled_projects = []
76 #        tickled_projects = self.get_tickled_projects()
77 #        for project in tickled_projects:
78 #            if project.should_not_be_tickled():
79 #                current_tickled_projects.append(project)
80 #        return current_tickled_projects
81 #                
82 #    def add_project(self,project):
83 #        # Projects are not being reread
84 #        if self.processed_projects:
85 #            self.get_active_projects().insert(0,project)
86 #    def create_project(self,project_name):
87 #        project_file_name = (project_directory+project_name+'.prj')
88 #        project = Project(project_file_name)
89 #        project.dirty=True
90 #        project.write()
91 #        self.add_project(project)
92 #        return project
93 #
94 #
95 #    def process(self):
96 #        ##logger.log(u'Starting to process')
97 #
98 #        self.reread()
99 #        ##logger.log('Searching for projects without next act')
100 #        for project in self.get_active_projects():
101 #            #logger.log(project.name(),2)
102 #            self.process_project(project)
103 #        ##logger.log('Searching for projects that should be untickled')
104 #        for project in self.get_current_tickled_projects():
105 #            self.review(project)
106 #            project.activate()
107 #        ##logger.log('Removing obsolete tickle directories')
108 #        for tickle_dir in self.get_tickle_times():
109 #            if TickleDirectory(tickle_dir).is_obsolete():
110 #                try:
111 #                    os.removedirs(u'%s/%s'%(self.tickled_directory,tickle_dir))
112 #                except OSError:
113 #                    pass
114 #            
115 #        self.reread()
116 #        self.notify()
117 #
118 #    def process_project(self,project):
119 #        is_active = project.process()
120 #        if not is_active:
121 #            self.review(project)
122 #        
123 #    def update_status(self,project):
124 #        if project.has_active_actions() and project.get_status()==inactive:
125 #            self.activate(project)
126 #        elif not project.has_active_actions() and project.is_processed():
127 #            self.review(project)
128 #    
129 #    def review(self,project):
130 #        project.move_to(self.review_directory)
131 #    def set_done(self,project):
132 #        project.inactivate()
133 #        project.move_to(self.done_directory)
134 #    def activate(self,project):
135 #        project.move_to(self.root)
136 #
137 #    def defer(self,project,context=''):
138 #        project.inactivate()
139 #        project.move_to(u'%s/%s'%(self.someday_directory,context))
140 #    def tickle(self,project,time=''):
141 #        project.inactivate()
142 #        project.move_to(u'%s/%s'%(self.tickled_directory,time))
143
144 __all__ = ["Projects"]