Beispiel #1
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
Beispiel #2
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)
Beispiel #3
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)
Beispiel #4
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)
Beispiel #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) 
Beispiel #6
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
Beispiel #7
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)
Beispiel #8
0
    def __init__(self, id_=None):
        super(ChangeMonitor, self).__init__()

        self.__guid = id_ or guid.generate()
        self.__frozen = False
        self.__collections = []

        self.reset()
Beispiel #9
0
    def __init__(self, id_=None):
        super(ChangeMonitor, self).__init__()

        self.__guid = id_ or guid.generate()
        self.__frozen = False
        self.__collections = []

        self.reset()
Beispiel #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')
Beispiel #12
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)
 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)
Beispiel #14
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)
    def close(self):
        if os.path.exists(self.filename()):
            changes = xml.ChangesXMLReader(self.filename() + '.delta').read()
            del changes[self.__monitor.guid()]
            xml.ChangesXMLWriter(file(self.filename() + '.delta', 'wb')).write(changes)

        self.setFilename('')
        self.__guid = generate()
        self.clear()
        self.__monitor.reset()
        self.markClean()
        self.__changedOnDisk = False
Beispiel #16
0
    def close(self):
        if os.path.exists(self.filename()):
            changes = xml.ChangesXMLReader(self.filename() + '.delta').read()
            del changes[self.__monitor.guid()]
            xml.ChangesXMLWriter(file(self.filename() + '.delta',
                                      'wb')).write(changes)

        self.setFilename('')
        self.__guid = generate()
        self.clear()
        self.__monitor.reset()
        self.markClean()
        self.__changedOnDisk = False
Beispiel #17
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
Beispiel #18
0
 def __parseGUIDNode(self, node):
     guid = self._parseText(node).strip()
     return guid if guid else generate()
Beispiel #19
0
 def __parse_guid_node(self, node):
     ''' Parse the GUID from the node. '''
     guid = self.__parse_text(node).strip()
     return guid if guid else generate()
Beispiel #20
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)
Beispiel #21
0
 def __parse_guid_node(self, node):
     """ Parse the GUID from the node. """
     guid = self.__parse_text(node).strip()
     return guid if guid else generate()
Beispiel #22
0
 def __findGUIDNode(self, nodes):
     for node in nodes:
         if node.nodeName == 'guid':
             return self.__parseTextNode(node)
     return generate()
Beispiel #23
0
 def close(self):
     self.setFilename('')
     self.__guid = generate()
     self.clear()
     self.__needSave = False
Beispiel #24
0
 def close(self):
     self.setFilename('')
     self.__guid = generate()
     self.clear()
     self.__needSave = False
Beispiel #25
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')
Beispiel #26
0
 def _clear(self):
     self.tasks().clear()
     self.categories().clear()
     self.notes().clear()
     self.__guid = generate()
     self.__syncMLConfig = createDefaultSyncConfig(self.__guid)
Beispiel #27
0
 def __parseGUIDNode(self, node):
     guid = self._parseText(node).strip()
     return guid if guid else generate()