Don't let ListView call a non-existent method on its superclass.
[matthijs/upstream/mobilegtd.git] / src / persistence / projects_directory.py
1 from inout.io import *
2 from model.project import Project
3 #from project_file import ProjectFile
4 import project_file
5 from log.logging import logger
6 def is_project(path):
7     return os.path.splitext(path)[1]=='.prj'
8
9
10
11 class ProjectsDirectory:
12     def __init__(self,projects):
13         self.projects = projects
14         self.projects.observers.append(self)
15         self.projects.reread = self.read
16         self.directories = {}
17         self.num_elements = 0
18     
19     def add_directory(self,directory,recursive = False):
20         self.directories[directory] = recursive
21
22     def read(self):
23         for p in range(0,self.num_elements):
24             self.projects.pop()
25             self.num_elements -= 1
26         for directory,recursive in self.directories.items():
27             self.read_directory(directory,recursive)
28
29     def read_directory(self,directory,recursive=False):
30         for f in list_dir(directory,recursive=recursive,filter=is_project):
31             
32             p,actions,infos = project_file.read(f)
33 #            if not p in self.projects:
34             self.projects.append(p)
35             self.num_elements += 1
36             logger.log(u'Read project %s, actions %s, infos %s'%(p,actions,infos))
37             for a in actions:
38                 p.add_action(a)
39             for info in infos:    
40                 p.add_info(info)
41 #            logger.log(u'Result %s'%repr(p))
42
43     def notify(self,projects,attribute,new=None,old=None):
44         logger.log(repr(type(projects)))
45 #        p_rep = repr(projects)
46 #        a_rep = repr(attribute)
47 #        n_rep = repr(new)
48 #        logger.log(u"ProjectsDirectory notified of %s | %s | %s"%(p_rep,a_rep,n_rep))
49         if attribute == 'add_item':
50             p_file = project_file.ProjectFile(new)
51             new.observers.append(p_file)
52             p_file.write() 
53