Example #1
0
    def load(self, filename=None):
        pub.sendMessage('taskfile.aboutToRead', taskFile=self)
        self.__loading = True
        if filename:
            self.setFilename(filename)
        try:
            if self.exists():
                fd = self._openForRead()
                tasks, categories, globalcategories, notes, syncMLConfig, changes, guid = self._read(
                    fd)
                fd.close()
            else:
                tasks = []
                categories = []
                notes = []
                changes = dict()
                guid = generate()
                syncMLConfig = createDefaultSyncConfig(guid)
            self.clear()
            self.__monitor.reset()
            self.__changes = changes
            self.__changes[self.__monitor.guid()] = self.__monitor
            self.categories().extend(categories)
            self.tasks().extend(tasks)
            self.notes().extend(notes)

            def registerOtherObjects(objects):
                for obj in objects:
                    if isinstance(obj, base.CompositeObject):
                        registerOtherObjects(obj.children())
                    if isinstance(obj, note.NoteOwner):
                        registerOtherObjects(obj.notes())
                    if isinstance(obj, attachment.AttachmentOwner):
                        registerOtherObjects(obj.attachments())
                    if isinstance(obj, task.Task):
                        registerOtherObjects(obj.efforts())
                    if isinstance(obj, note.Note) or \
                           isinstance(obj, attachment.Attachment) or \
                           isinstance(obj, effort.Effort):
                        self.__monitor.setChanges(obj.id(), set())

            registerOtherObjects(self.categories().rootItems())
            registerOtherObjects(self.tasks().rootItems())
            registerOtherObjects(self.notes().rootItems())
            self.__monitor.resetAllChanges()
            self.__syncMLConfig = syncMLConfig
            self.__guid = guid

            if os.path.exists(self.filename()):
                # We need to reset the changes on disk because we're up to date.
                xml.ChangesXMLWriter(file(self.filename() + '.delta',
                                          'wb')).write(self.__changes)
        except:
            self.setFilename('')
            raise
        finally:
            self.__loading = False
            self.markClean()
            self.__changedOnDisk = False
        pub.sendMessage('taskfile.justRead', taskFile=self)
Example #2
0
 def load(self, filename=None):
     self.__loading = True
     if filename:
         self.setFilename(filename)
     try:
         if self.exists():
             fd = self._openForRead()
             tasks, categories, notes, syncMLConfig, guid = self._read(fd)
             fd.close()
         else: 
             tasks = []
             categories = []
             notes = []
             guid = generate()
             syncMLConfig = createDefaultSyncConfig(guid)
         self.clear()
         self.categories().extend(categories)
         self.tasks().extend(tasks)
         self.notes().extend(notes)
         self.__syncMLConfig = syncMLConfig
         self.__guid = guid
     except:
         self.setFilename('')
         raise
     finally:
         self.__loading = False
         self.__needSave = False
Example #3
0
 def createTestFile(self):
     taskList = task.TaskList([task.Task('test') for _ in range(self.nrTasks)])
     taskfile = file(self.taskfilename, 'w')
     taskWriter = persistence.XMLWriter(taskfile)
     taskWriter.write(taskList, category.CategoryList(), note.NoteContainer(),
                      createDefaultSyncConfig('fake'), 'fake')
     taskfile.close()
Example #4
0
 def load(self, filename=None):
     self.__loading = True
     if filename:
         self.setFilename(filename)
     try:
         if self.exists():
             fd = self._openForRead()
             tasks, categories, notes, syncMLConfig, guid = self._read(fd)
             fd.close()
         else:
             tasks = []
             categories = []
             notes = []
             guid = generate()
             syncMLConfig = createDefaultSyncConfig(guid)
         self.clear()
         self.categories().extend(categories)
         self.tasks().extend(tasks)
         self.notes().extend(notes)
         self.__syncMLConfig = syncMLConfig
         self.__guid = guid
     except:
         self.setFilename('')
         raise
     finally:
         self.__loading = False
         self.__needSave = False
Example #5
0
    def __init__(self, *args, **kwargs):
        self.__filename = self.__lastFilename = ''
        self.__needSave = self.__loading = False
        self.__tasks = task.TaskList()
        self.__categories = category.CategoryList()
        self.__notes = note.NoteContainer()
        self.__efforts = effort.EffortList(self.tasks())
        self.__guid = generate()
        self.__syncMLConfig = createDefaultSyncConfig(self.__guid)
        super(TaskFile, self).__init__(*args, **kwargs)
        # Register for tasks, categories, efforts and notes being changed so we
        # can monitor when the task file needs saving (i.e. is 'dirty'):
        for container in self.tasks(), self.categories(), self.notes():
            for eventType in container.modificationEventTypes():
                self.registerObserver(self.onDomainObjectAddedOrRemoved,
                                      eventType,
                                      eventSource=container)

        for eventType in (base.Object.markDeletedEventType(),
                          base.Object.markNotDeletedEventType()):
            self.registerObserver(self.onDomainObjectAddedOrRemoved, eventType)

        for eventType in task.Task.modificationEventTypes():
            self.registerObserver(self.onTaskChanged, eventType)
        for eventType in effort.Effort.modificationEventTypes():
            self.registerObserver(self.onEffortChanged, eventType)
        for eventType in note.Note.modificationEventTypes():
            self.registerObserver(self.onNoteChanged, eventType)
        for eventType in category.Category.modificationEventTypes():
            self.registerObserver(self.onCategoryChanged, eventType)
        for eventType in attachment.FileAttachment.modificationEventTypes() + \
                         attachment.URIAttachment.modificationEventTypes() + \
                         attachment.MailAttachment.modificationEventTypes():
            self.registerObserver(self.onAttachmentChanged, eventType)
Example #6
0
 def __init__(self, *args, **kwargs):
     self.__filename = self.__lastFilename = ''
     self.__needSave = self.__loading = False
     self.__tasks = task.TaskList()
     self.__categories = category.CategoryList()
     self.__notes = note.NoteContainer()
     self.__efforts = effort.EffortList(self.tasks())
     self.__guid = generate()
     self.__syncMLConfig = createDefaultSyncConfig(self.__guid)
     super(TaskFile, self).__init__(*args, **kwargs)
     # Register for tasks, categories, efforts and notes being changed so we 
     # can monitor when the task file needs saving (i.e. is 'dirty'):
     for container in self.tasks(), self.categories(), self.notes():
         for eventType in container.modificationEventTypes():
             self.registerObserver(self.onDomainObjectAddedOrRemoved,
                                   eventType, eventSource=container)
         
     for eventType in (base.Object.markDeletedEventType(),
                       base.Object.markNotDeletedEventType()):
         self.registerObserver(self.onDomainObjectAddedOrRemoved, eventType)
         
     for eventType in task.Task.modificationEventTypes():
         self.registerObserver(self.onTaskChanged, eventType)
     for eventType in effort.Effort.modificationEventTypes():
         self.registerObserver(self.onEffortChanged, eventType)
     for eventType in note.Note.modificationEventTypes():
         self.registerObserver(self.onNoteChanged, eventType)
     for eventType in category.Category.modificationEventTypes():
         self.registerObserver(self.onCategoryChanged, eventType)
     for eventType in attachment.FileAttachment.modificationEventTypes() + \
                      attachment.URIAttachment.modificationEventTypes() + \
                      attachment.MailAttachment.modificationEventTypes(): 
         self.registerObserver(self.onAttachmentChanged, eventType) 
Example #7
0
 def clear(self, regenerate=True):
     self.tasks().clear()
     self.categories().clear()
     self.notes().clear()
     if regenerate:
         self.__guid = generate()
         self.__syncMLConfig = createDefaultSyncConfig(self.__guid)
Example #8
0
 def clear(self, regenerate=True, event=None):
     self.tasks().clear(event=event)
     self.categories().clear(event=event)
     self.notes().clear(event=event)
     if regenerate:
         self.__guid = generate()
         self.__syncMLConfig = createDefaultSyncConfig(self.__guid)
Example #9
0
    def __parseSyncMLNode(self, nodes, guid):
        syncML = createDefaultSyncConfig(guid)

        for node in nodes:
            if node.nodeName == 'syncml':
                self.__parseSyncMLNodes(node.childNodes, syncML)

        return syncML
Example #10
0
    def load(self, filename=None):
        pub.sendMessage('taskfile.aboutToRead', taskFile=self)
        self.__loading = True
        if filename:
            self.setFilename(filename)
        try:
            if self.exists():
                fd = self._openForRead()
                try:
                    tasks, categories, notes, syncMLConfig, changes, guid = self._read(fd)
                finally:
                    fd.close()
            else:
                tasks = []
                categories = []
                notes = []
                changes = dict()
                guid = generate()
                syncMLConfig = createDefaultSyncConfig(guid)
            self.clear()
            self.__monitor.reset()
            self.__changes = changes
            self.__changes[self.__monitor.guid()] = self.__monitor
            self.categories().extend(categories)
            self.tasks().extend(tasks)
            self.notes().extend(notes)
            def registerOtherObjects(objects):
                for obj in objects:
                    if isinstance(obj, base.CompositeObject):
                        registerOtherObjects(obj.children())
                    if isinstance(obj, note.NoteOwner):
                        registerOtherObjects(obj.notes())
                    if isinstance(obj, attachment.AttachmentOwner):
                        registerOtherObjects(obj.attachments())
                    if isinstance(obj, task.Task):
                        registerOtherObjects(obj.efforts())
                    if isinstance(obj, note.Note) or \
                           isinstance(obj, attachment.Attachment) or \
                           isinstance(obj, effort.Effort):
                        self.__monitor.setChanges(obj.id(), set())
            registerOtherObjects(self.categories().rootItems())
            registerOtherObjects(self.tasks().rootItems())
            registerOtherObjects(self.notes().rootItems())
            self.__monitor.resetAllChanges()
            self.__syncMLConfig = syncMLConfig
            self.__guid = guid

            if os.path.exists(self.filename()):
                # We need to reset the changes on disk because we're up to date.
                xml.ChangesXMLWriter(file(self.filename() + '.delta', 'wb')).write(self.__changes)
        except:
            self.setFilename('')
            raise
        finally:
            self.__loading = False
            self.markClean()
            self.__changedOnDisk = False
            pub.sendMessage('taskfile.justRead', taskFile=self)
 def __init__(self, *args, **kwargs):
     self.__filename = self.__lastFilename = ''
     self.__needSave = self.__loading = False
     self.__tasks = task.TaskList()
     self.__categories = category.CategoryList()
     self.__notes = note.NoteContainer()
     self.__efforts = effort.EffortList(self.tasks())
     self.__guid = generate()
     self.__syncMLConfig = createDefaultSyncConfig(self.__guid)
     self.__monitor = ChangeMonitor()
     self.__changes = dict()
     self.__changes[self.__monitor.guid()] = self.__monitor
     self.__changedOnDisk = False
     if kwargs.pop('poll', True):
         self.__notifier = TaskCoachFilesystemPollerNotifier(self)
     else:
         self.__notifier = TaskCoachFilesystemNotifier(self)
     self.__saving = False
     for collection in [self.__tasks, self.__categories, self.__notes]:
         self.__monitor.monitorCollection(collection)
     for domainClass in [task.Task, category.Category, note.Note, effort.Effort,
                         attachment.FileAttachment, attachment.URIAttachment,
                         attachment.MailAttachment]:
         self.__monitor.monitorClass(domainClass)
     super(TaskFile, self).__init__(*args, **kwargs)
     # Register for tasks, categories, efforts and notes being changed so we 
     # can monitor when the task file needs saving (i.e. is 'dirty'):
     for container in self.tasks(), self.categories(), self.notes():
         for eventType in container.modificationEventTypes():
             self.registerObserver(self.onDomainObjectAddedOrRemoved,
                                   eventType, eventSource=container)
         
     for eventType in (base.Object.markDeletedEventType(),
                       base.Object.markNotDeletedEventType()):
         self.registerObserver(self.onDomainObjectAddedOrRemoved, eventType)
         
     for eventType in task.Task.modificationEventTypes():
         if not eventType.startswith('pubsub'):
             self.registerObserver(self.onTaskChanged_Deprecated, eventType)
     pub.subscribe(self.onTaskChanged, 'pubsub.task')
     for eventType in effort.Effort.modificationEventTypes():
         self.registerObserver(self.onEffortChanged, eventType)
     for eventType in note.Note.modificationEventTypes():
         if not eventType.startswith('pubsub'):
             self.registerObserver(self.onNoteChanged_Deprecated, eventType)
     pub.subscribe(self.onNoteChanged, 'pubsub.note')
     for eventType in category.Category.modificationEventTypes():
         if not eventType.startswith('pubsub'):
             self.registerObserver(self.onCategoryChanged_Deprecated, 
                                   eventType)
     pub.subscribe(self.onCategoryChanged, 'pubsub.category')
     for eventType in attachment.FileAttachment.modificationEventTypes() + \
                      attachment.URIAttachment.modificationEventTypes() + \
                      attachment.MailAttachment.modificationEventTypes():
         if not eventType.startswith('pubsub'):
             self.registerObserver(self.onAttachmentChanged_Deprecated, eventType) 
     pub.subscribe(self.onAttachmentChanged, 'pubsub.attachment')
Example #12
0
 def clear(self, regenerate=True, event=None):
     pub.sendMessage('taskfile.aboutToClear', taskFile=self)
     try:
         self.tasks().clear(event=event)
         self.categories().clear(event=event)
         self.notes().clear(event=event)
         if regenerate:
             self.__guid = generate()
             self.__syncMLConfig = createDefaultSyncConfig(self.__guid)
     finally:
         pub.sendMessage('taskfile.justCleared', taskFile=self)
Example #13
0
    def _parseSyncMLNode(self, nodes, guid):
        syncML = createDefaultSyncConfig(guid)

        nodeName = "syncmlconfig"
        if self.__tskversion < 25:
            nodeName = "syncml"

        for node in nodes.findall(nodeName):
            self._parseSyncMLNodes(node, syncML)

        return syncML
Example #14
0
    def __init__(self, filename='', *args, **kwargs):
        self.__filename = self.__lastFilename = filename
        self.__needSave = self.__loading = False
        self.__tasks = task.TaskList()
        self.__categories = category.CategoryList()
        self.__notes = note.NoteContainer()
        self.__efforts = effort.EffortList(self.tasks())
        self.__guid = generate()
        self.__syncMLConfig = createDefaultSyncConfig(self.__guid)
        super(TaskFile, self).__init__(*args, **kwargs)
        # Register for tasks, categories, efforts and notes being changed so we 
        # can monitor when the task file needs saving (i.e. is 'dirty'):
        for eventType in (self.tasks().addItemEventType(), 
                          self.tasks().removeItemEventType(), 
                          self.categories().addItemEventType(),
                          self.categories().removeItemEventType(),
                          self.notes().addItemEventType(),
                          self.notes().removeItemEventType(),
                          'object.markdeleted',
                          'object.marknotdeleted'):
            patterns.Publisher().registerObserver(self.onDomainObjectAddedOrRemoved, 
                                                  eventType)

        for eventType in (task.Task.subjectChangedEventType(), 
            task.Task.descriptionChangedEventType(), 'task.startDate', 
            'task.dueDate', 'task.completionDate', 'task.priority', 
            'task.budget', 'task.hourlyFee', 'task.fixedFee',
            'task.timeSpent', 'task.reminder',
            'task.setting.shouldMarkCompletedWhenAllChildrenCompleted',
            task.Task.addChildEventType(), task.Task.removeChildEventType(),
            'task.effort.add', 'task.effort.remove', 
            task.Task.categoryAddedEventType(), 
            task.Task.categoryRemovedEventType(), 
            'task.attachment.add', 'task.attachment.remove', 'task.attachment.changed'):
            patterns.Publisher().registerObserver(self.onTaskChanged, 
                                                  eventType=eventType)
        for eventType in ('effort.description', 'effort.start', 'effort.stop'):
            # We don't need to observe 'effort.task', because when an
            # effort record is assigned to a different task we already will 
            # get a notification through 'task.effort.add'                
            patterns.Publisher().registerObserver(self.onEffortChanged, 
                                                  eventType=eventType)
        for eventType in (note.Note.subjectChangedEventType(), 
                note.Note.descriptionChangedEventType(), 
                note.Note.addChildEventType(), 
                note.Note.removeChildEventType()):
            patterns.Publisher().registerObserver(self.onNoteChanged, 
                                                  eventType=eventType)
        for eventType in (category.Category.filterChangedEventType(), 
                category.Category.subjectChangedEventType(),
                category.Category.descriptionChangedEventType(),
                category.Category.colorChangedEventType()):
            patterns.Publisher().registerObserver(self.onCategoryChanged, 
                eventType=eventType)
Example #15
0
    def _parseSyncMLNode(self, nodes, guid):
        syncML = createDefaultSyncConfig(guid)

        nodeName = 'syncmlconfig'
        if self.__tskversion < 25:
            nodeName = 'syncml'

        for node in nodes.findall(nodeName):
            self._parseSyncMLNodes(node, syncML)

        return syncML
 def clear(self, regenerate=True, event=None):
     pub.sendMessage('taskfile.aboutToClear', taskFile=self)
     try:
         self.tasks().clear(event=event)
         self.categories().clear(event=event)
         self.notes().clear(event=event)
         if regenerate:
             self.__guid = generate()
             self.__syncMLConfig = createDefaultSyncConfig(self.__guid)
     finally:
         pub.sendMessage('taskfile.justCleared', taskFile=self)
Example #17
0
    def __parse_syncml_node(self, nodes, guid):
        ''' Parse the SyncML node from the nodes. '''
        syncml_config = createDefaultSyncConfig(guid)

        node_name = 'syncmlconfig'
        if self.__tskversion < 25:
            node_name = 'syncml'

        for node in nodes.findall(node_name):
            self.__parse_syncml_nodes(node, syncml_config)
        return syncml_config
Example #18
0
    def __parse_syncml_node(self, nodes, guid):
        """ Parse the SyncML node from the nodes. """
        syncml_config = createDefaultSyncConfig(guid)

        node_name = "syncmlconfig"
        if self.__tskversion < 25:
            node_name = "syncml"

        for node in nodes.findall(node_name):
            self.__parse_syncml_nodes(node, syncml_config)
        return syncml_config
Example #19
0
 def load(self):
     self.__loading = True
     try:
         if self.exists():
             fd = self._openForRead()
             tasks, categories, notes, syncMLConfig, guid = self._read(fd)
             fd.close()
         else: 
             tasks = []
             categories = []
             notes = []
             guid = generate()
             syncMLConfig = createDefaultSyncConfig(guid)
         self._clear()
         self.tasks().extend(tasks)
         self.categories().extend(categories)
         self.notes().extend(notes)
         self.__syncMLConfig = syncMLConfig
         self.__guid = guid
     finally:
         self.__loading = False
         self.__needSave = False
Example #20
0
 def _clear(self):
     self.tasks().clear()
     self.categories().clear()
     self.notes().clear()
     self.__guid = generate()
     self.__syncMLConfig = createDefaultSyncConfig(self.__guid)
Example #21
0
 def _clear(self):
     self.tasks().removeItems(list(self.tasks()))
     self.categories().removeItems(list(self.categories()))
     self.notes().removeItems(list(self.notes()))
     self.__guid = generate()
     self.__syncMLConfig = createDefaultSyncConfig(self.__guid)
Example #22
0
    def __init__(self, *args, **kwargs):
        self.__filename = self.__lastFilename = ''
        self.__needSave = self.__loading = False
        self.__tasks = task.TaskList()
        self.__categories = category.CategoryList()
        self.__notes = note.NoteContainer()
        self.__efforts = effort.EffortList(self.tasks())
        self.__guid = generate()
        self.__syncMLConfig = createDefaultSyncConfig(self.__guid)
        self.__monitor = ChangeMonitor()
        self.__changes = dict()
        self.__changes[self.__monitor.guid()] = self.__monitor
        self.__changedOnDisk = False
        if kwargs.pop('poll', True):
            self.__notifier = TaskCoachFilesystemPollerNotifier(self)
        else:
            self.__notifier = TaskCoachFilesystemNotifier(self)
        self.__saving = False
        for collection in [self.__tasks, self.__categories, self.__notes]:
            self.__monitor.monitorCollection(collection)
        for domainClass in [
                task.Task, category.Category, note.Note, effort.Effort,
                attachment.FileAttachment, attachment.URIAttachment,
                attachment.MailAttachment
        ]:
            self.__monitor.monitorClass(domainClass)
        super(TaskFile, self).__init__(*args, **kwargs)
        # Register for tasks, categories, efforts and notes being changed so we
        # can monitor when the task file needs saving (i.e. is 'dirty'):
        for container in self.tasks(), self.categories(), self.notes():
            for eventType in container.modificationEventTypes():
                self.registerObserver(self.onDomainObjectAddedOrRemoved,
                                      eventType,
                                      eventSource=container)

        for eventType in (base.Object.markDeletedEventType(),
                          base.Object.markNotDeletedEventType()):
            self.registerObserver(self.onDomainObjectAddedOrRemoved, eventType)

        for eventType in task.Task.modificationEventTypes():
            if not eventType.startswith('pubsub'):
                self.registerObserver(self.onTaskChanged_Deprecated, eventType)
        pub.subscribe(self.onTaskChanged, 'pubsub.task')
        for eventType in effort.Effort.modificationEventTypes():
            self.registerObserver(self.onEffortChanged, eventType)
        for eventType in note.Note.modificationEventTypes():
            if not eventType.startswith('pubsub'):
                self.registerObserver(self.onNoteChanged_Deprecated, eventType)
        pub.subscribe(self.onNoteChanged, 'pubsub.note')
        for eventType in category.Category.modificationEventTypes():
            if not eventType.startswith('pubsub'):
                self.registerObserver(self.onCategoryChanged_Deprecated,
                                      eventType)
        pub.subscribe(self.onCategoryChanged, 'pubsub.category')
        for eventType in attachment.FileAttachment.modificationEventTypes() + \
                         attachment.URIAttachment.modificationEventTypes() + \
                         attachment.MailAttachment.modificationEventTypes():
            if not eventType.startswith('pubsub'):
                self.registerObserver(self.onAttachmentChanged_Deprecated,
                                      eventType)
        pub.subscribe(self.onAttachmentChanged, 'pubsub.attachment')