Exemplo n.º 1
0
    def __init__(self, client, options, logger=None):

        self._key_attribute = options.get('key','title')
        self._folder = None

        # self._maxsize = None

        if isinstance(client, ToodledoAPI):
            self._client = client
        else:
            self._client = ToodledoAPI.get_session(**client)

        Sync.__init__(self, options, logger, 'tdsync')

        if self.signature is None:
            if options.get('folder'):
                folder = options.get('folder')
                if self._client.folders.get(folder):
                    self._folder = self._client.folders[folder]
                    signature = {'label': options.get('label'),
                                 'folder': self._folder['name'],
                                 'id': self._folder['id']}
                    self.options.update({'signature': signature})
                else:
                    error = u'Folder [%s] not found!' % (utf8(folder))
                    self.logger.error(error)
                    raise SyncInitError(error)
            else:
                self.logger.warning(u'No folder specified in sync options')
        else:
            self._folder = self.client.folders[self.signature['id']]
Exemplo n.º 2
0
    def delete(self, key):
        '''
        delete a bean from the collection
        :param key: numeric id or string to search in self._key_attributes
        :return: True if key was found in collection
        '''
        if isinstance(key, str):
            key = utf8(key)

        beans = []; found = False
        for bean in self._beans:
            if not found:
                for attr in self._key_attributes:
                    val = bean[attr]
                    if type(val) == type(key):
                        if val == key:
                            found = True
                            break
                if found:
                    bean._deleted = True
                    self._deleted[bean.id] = bean
                    continue

            beans.append(bean)

        return found
Exemplo n.º 3
0
    def __init__(self, client, options, logger=None):

        self._key_attribute = options.get('key', 'title')
        self._folder = None

        # self._maxsize = None

        if isinstance(client, ToodledoAPI):
            self._client = client
        else:
            self._client = ToodledoAPI.get_session(**client)

        Sync.__init__(self, options, logger, 'tdsync')

        if self.signature is None:
            if options.get('folder'):
                folder = options.get('folder')
                if self._client.folders.get(folder):
                    self._folder = self._client.folders[folder]
                    signature = {
                        'label': options.get('label'),
                        'folder': self._folder['name'],
                        'id': self._folder['id']
                    }
                    self.options.update({'signature': signature})
                else:
                    error = u'Folder [%s] not found!' % (utf8(folder))
                    self.logger.error(error)
                    raise SyncInitError(error)
            else:
                self.logger.warning(u'No folder specified in sync options')
        else:
            self._folder = self.client.folders[self.signature['id']]
Exemplo n.º 4
0
 def create(self, other, sid=None):
     that = other.get()
     if that:
         self.logger.debug(u'%s: Creating task [%s] from %s' % (self.class_name, utf8(that.title), other.class_name))
         todo = self._client.create_task(title=that.title, folder=self.folder.id)
         return self.update(other, that, todo, sid=sid)
     return None
Exemplo n.º 5
0
 def create(self, other, sid=None):
     that = other.get()
     if that:
         self.logger.debug(
             u'%s: Creating task [%s] from %s' %
             (self.class_name, utf8(that.title), other.class_name))
         todo = self._client.create_task(title=that.title,
                                         folder=self.folder.id)
         return self.update(other, that, todo, sid=sid)
     return None
Exemplo n.º 6
0
    def __init__(self, ox, options, logger=None):

        self._key_attribute = options.get('key','title')
        self._maxsize = options.get('maxsize', 2048)
        self._folder = None
        self._archive = None

        Sync.__init__(self, options, logger, 'oxsync')
        OxTasks.__init__(self, ox)

        if self.signature is None:
            signature = {'label': options.get('label')}
            if options.get('folder') is not None:
                self._folder = self._ox.get_folder('tasks', utf8(options['folder']))
                self.logger.debug(u'Using folder [%s]: %s' % (self._folder.id, utf8(self._folder.title)))
                if self._folder is not None:
                    signature['folder'] = self._folder.title
                    signature['id'] = self._folder.id
                    if options.get('archive'):
                        self._archive = self._ox.get_folder('tasks', utf8(options['archive']))
                        self.logger.debug(u'Using archive folder [%s]: %s' % (self._archive.id, utf8(self._archive.title)))
                        if self._archive is not None:
                            signature['archive'] = self._archive.id
                        else:
                            error = u'Archive folder [%s] not found!' % (utf8(options['archive']))
                            # self.logger.error(error)
                            raise SyncInitError(error)
                    self.options.update({'signature': signature})
                else:
                    error = u'Folder [%s] not found!' % (utf8(options['folder']))
                    # self.logger.error(error)
                    raise SyncInitError(error)
            else:
                error = u'No folder specified in in sync options!'
                # self.logger.error(error)
                raise SyncInitError(error)
        else:
            if self.signature.get('id'):
                self._folder = self._ox.get_folder('tasks', self.signature['id'])
                if self._folder is not None:
                    self.logger.debug(u'Using folder [%s]: %s' % (self._folder.id, utf8(self._folder.title)))
                else:
                    error = u'Folder [%s] from map file not found!' % (self.signature['id'])
                    # self.logger.error(error)
                    raise SyncInitError(error)

            if self.signature.get('archive'):
                self._archive = self._ox.get_folder('tasks', self.signature['archive'])
                if self._folder is not None:
                    self.logger.debug(u'Using folder [%s]: %s' % (self._archive.id, utf8(self._archive.title)))
                else:
                    error = u'Archive folder [%s] from map file not found!' % (self.signature['archive'])
                    # self.logger.error()
                    raise SyncInitError(error)
Exemplo n.º 7
0
    def create(self, other, sid=None):
        that = other.get()
        if that:
            note = EnNote(title=that.title)
            self.logger.debug(u'%s: Creating note [%s] from %s' % (self.class_name, that.title, other.class_name))
            try:
                note = self._book.create_note(note)
            except Exception as e:
                self.logger.exception(u'Error creating note [%s]!' % (utf8(note.title)))
                return None

            if sid is not None:
                self._created[sid] = note
            return self.update(other, that, note, sid=sid)
        return None
Exemplo n.º 8
0
 def create(self, other, sid=None):
     that = other.get()
     # other must provide 'title'
     if that:
         title = utf8(that.title)
         data = {'folder_id': self.folder.id, 'title': title}
         task = OxTask(data, self._ox)
         self.logger.debug(u'%s: Creating task [%s] from %s' % (self.class_name, title, other.class_name))
         try:
             task = task.create()
         except Exception as e:
             self.logger.exception('Error creating task [%s]' % (title))
             return None
         if sid is not None:
             self._created[sid] = task
         return self.update(other, that, task, sid=sid)
     return None
Exemplo n.º 9
0
 def create(self, other, sid=None):
     that = other.get()
     # other must provide 'title'
     if that:
         title = utf8(that.title)
         data = {'folder_id': self.folder.id, 'title': title}
         task = OxTask(data, self._ox)
         self.logger.debug(u'%s: Creating task [%s] from %s' %
                           (self.class_name, title, other.class_name))
         try:
             task = task.create()
         except Exception as e:
             self.logger.exception('Error creating task [%s]' % (title))
             return None
         if sid is not None:
             self._created[sid] = task
         return self.update(other, that, task, sid=sid)
     return None
Exemplo n.º 10
0
    def __setitem__(self, key, value):

        # if key in self.properties():
        #     setattr(self, key, value)
        #     return

        if isinstance(value, str):
            value = utf8(value)

        if self.__dict__['_data'] is None:
            self.__dict__['_data'] = {}

        if key in ['folder', 'context', 'goal', 'location']:
            self._logger.debug('Processing special attribute [%s]' % (key))
            value = self._tdapi.get_list_item(key + 's', value)._id

            # call = getattr(self._tdapi, 'get_' + key)
            # if call:
            #     result = call(value)
            #     if result:
            #         value = result._id

        if key in self.__dict__['_data'] and key != 'modified':

            # modify existing attribute
            if self.__dict__['_data'][key] != value:
                self._logger.debug('Mofify bean attribute [%s]' % (key))
                if self.__dict__['_modified'] is None:
                    self.__dict__['_modified'] = {}
                self.__dict__['_modified'][key] = True

                self.__dict__['_data']['modified'] = int(time.time())

                if self.__dict__['_parent'] is not None:
                    self.__dict__['_parent']._modified[self.id] = self

        self.__dict__['_data'][key] = value
Exemplo n.º 11
0
    def update(self, other, that=None, this=None, sid=None):

        todo, task = ThisFromThat.update(self, other, that, this, sid)
        oxsync = self._engine; ox = self._engine._ox
        tdsync = self._other; tdapi = self._other.client
        update = self._update

# region Toodledo task attributes
        # id, title, note, modified, completed, added
        # folder, context, goal, location, tag,
        # startdate, duedate, duedatemod, starttime, duetime,
        # remind, repeat,
        # status, star, priority,
        # length, timer
        # parent, children, order,
        # meta, previous, attachment,
        # shared, addedby, via, attachments
# endregion

# region Open-Xchange task attributes
        # modified_by, last_modified, folder_id, categories, private_flag, color_label
        # number_of_attachments, lastModifiedOfNewestAttachmentUTC,
        # title, start_date, end_date, note, alarm, date_completed
        # priority,status, percent_completed
        # actual_costs, actual_duration, billing_information, target_costs, target_duration, currency, trip_meter, companies
        # new columns available only since Rev. 7.6.1
        # but: works not for default folder Tasks
        # start_time,end_time, full_time
# endregion

        title = utf8(todo.title)
        if title != task.title:
            task.title = title
            self.logger.debug(u'Title changed to [%s]' % (title))
            
        note = utf8(todo.note)
        if note != task.note:
            task.note = note

        DAY = 60*60 * 24
        OX_UTC_TIME = 0
        TD_UTC_TIME = 60*60 * 12 

        full_time = None

        start_time = None
        start_date = None
        
        if todo._start_time:
            full_time = False 
            start_time = todo._start_time + (ox.utc_offset/1000)
            if start_time != task.start_time:
                self.logger.debug(u'Start time changed from [%s] to [%s]' % (strflocal(task.start_time, None),
                                                                           strflocal(start_time, None)))
        else:
            if todo._start_date:
                full_time = True
                start_date = todo._start_date - TD_UTC_TIME
            if start_date != task.start_date:
                self.logger.debug(u'Start date changed from [%s] to [%s]' % (strflocal(task.start_date, None),
                                                                           strflocal(start_date, None)))
                
        task.start_time = start_time
        task.start_date = start_date
        
        end_time = None
        end_date = None
        
        if todo._due_time:
            full_time = False 
            end_time = todo._due_time + (ox.utc_offset/1000)
            if end_time != task.end_time:
                self.logger.debug(u'end time changed from [%s] to [%s]' % (strflocal(task.end_time, None),
                                                                         strflocal(end_time, None)))
        else:
            if todo._due_date:
                full_time = True
                end_date = todo._due_date - TD_UTC_TIME
            if end_date != task.end_date:
                self.logger.debug(u'end date changed from [%s] to [%s]' % (strflocal(task.end_date, None),
                                                                         strflocal(end_date, None)))
                
        task.end_time = end_time
        task.end_date = end_date
        
        task.full_time = full_time

        alarm = None
        if todo._remind_date:
            alarm = todo._remind_date
        if alarm != task.alarm:
            self.logger.debug(u'Reminder changed from [%s] to [%s]' % (strflocal(task.alarm, None),
                                                                     strflocal(alarm, None)))
        task.alarm = alarm

        tags = []
        prefix_used = []
        categories = u''

        status = 0
        if not todo.completed:    
            if todo.status is not None:
                status = self.status_map[todo.status]
                if tdsync.options.get('ox_tag_status'):
                    prefix = tdsync.options.get('ox_tag_status')
                    if todo.status not in [0, 1, 2, 5]:
                        # map to extended status tag
                        tag = prefix + ToodledoTask.STATUS[todo.status]
                        tags.append(tag)
                        prefix_used.append(prefix)
                        self.logger.debug(u'Create extended status tag [%]' % (tag))
        else:
            status = OxTask.get_status('Done')
            # task.date_completed = todo._date_completed
            
        if status != task.status:
            self.logger.debug(u'Status changed from [%s] to [%s]' % (task.status, status))
        task.status = status

        priority = None
        if todo.priority is not None:
            priority = self.priority_map[todo.priority]
            if tdsync.options.get('ox_tag_priority'):
                prefix = tdsync.options.get('ox_tag_priority')
                if todo.priority == -1:
                    tag = utf8(prefix + 'Negative')
                    tags.append(tag)
                    prefix_used.append(prefix)
                    self.logger.debug(u'Create extendend priority tag [%s]' % (tag))
                elif todo.priority == 3:
                    tag = utf8(prefix + 'Top')
                    tags.append(tag)
                    prefix_used.append(prefix)
                    self.logger.debug(u'Create extendend priority tag [%s]' % (tag))
                else:
                    pass

        if priority != task.priority:
            self.logger.debug(u'Priority changed from [%s] to [%s]' % (task.priority, priority))
        task.priority = priority

        if tdsync.options.get('ox_tag_star'):
            if todo.star:
                tag = tdsync.options.get('ox_tag_star')
                tags.append(tag)
                self.logger.debug(u'Create star tag [%s]' % (tag))

        if tdsync.options.get('ox_tag_context'):
            if todo.context:
                tag = tdsync.options.get('ox_tag_context') + tdapi.contexts[todo.context]['name']
                tags.append(tag)
                self.logger.debug(u'Create context tag [%s]' % (tag))

        if tdsync.options.get('ox_tag_goal'):
            if todo.goal:
                tag = tdsync.options.get('ox_tag_goal') + tdapi.goals[todo.goal]['name']
                tags.append(tag)
                self.logger.debug(u'Create goal tag [%s]' % (tag))

        if tdsync.options.get('ox_tag_location'):
            if todo.location:
                tag = tdsync.options.get('ox_tag_location') + tdapi.locations[todo.location]['name']
                tags.append(tag)
                self.logger.debug(u'Create location tag [%s]' % (tag))

        for tag in todo.tag_names():
            if tag == tdsync.options.get('ox_tag_star', ','):
                continue
            elif tag.startswith(tdsync.options.get('ox_tag_context', ',')):
                continue
            elif tag.startswith(tdsync.options.get('ox_tag_goal', ',')):
                continue
            elif tag.startswith(tdsync.options.get('ox_tag_location', ',')):
                continue
            elif tag.startswith(tdsync.options.get('ox_tag_status', ',')):
                continue
            elif tag.startswith(tdsync.options.get('ox_tag_priority', ',')):
                continue
            else:
                tags.append(tag)
                self.logger.debug(u'Create category tag [%s]' % (tag))

        if len(tags) > 0:
            categories = u','.join(tags)
        if categories != task.categories:
            self.logger.debug(u'Categories changed from [%s] to [%s]' % (task.categories, categories))
        task.categories = categories

        task.notification = True
        task._data['full_time'] = False

        task = task.update()
        task.load()
        self.logger.debug(u'%s: Updating completed with timestamp %s' % (self.class_name, strflocal(task.timestamp)))
        return task
Exemplo n.º 12
0
    def __init__(self, ox, options, logger=None):

        self._key_attribute = options.get('key', 'title')
        self._maxsize = options.get('maxsize', 2048)
        self._folder = None
        self._archive = None

        Sync.__init__(self, options, logger, 'oxsync')
        OxTasks.__init__(self, ox)

        if self.signature is None:
            signature = {'label': options.get('label')}
            if options.get('folder') is not None:
                self._folder = self._ox.get_folder('tasks',
                                                   utf8(options['folder']))
                self.logger.debug(u'Using folder [%s]: %s' %
                                  (self._folder.id, utf8(self._folder.title)))
                if self._folder is not None:
                    signature['folder'] = self._folder.title
                    signature['id'] = self._folder.id
                    if options.get('archive'):
                        self._archive = self._ox.get_folder(
                            'tasks', utf8(options['archive']))
                        self.logger.debug(
                            u'Using archive folder [%s]: %s' %
                            (self._archive.id, utf8(self._archive.title)))
                        if self._archive is not None:
                            signature['archive'] = self._archive.id
                        else:
                            error = u'Archive folder [%s] not found!' % (utf8(
                                options['archive']))
                            # self.logger.error(error)
                            raise SyncInitError(error)
                    self.options.update({'signature': signature})
                else:
                    error = u'Folder [%s] not found!' % (utf8(
                        options['folder']))
                    # self.logger.error(error)
                    raise SyncInitError(error)
            else:
                error = u'No folder specified in in sync options!'
                # self.logger.error(error)
                raise SyncInitError(error)
        else:
            if self.signature.get('id'):
                self._folder = self._ox.get_folder('tasks',
                                                   self.signature['id'])
                if self._folder is not None:
                    self.logger.debug(
                        u'Using folder [%s]: %s' %
                        (self._folder.id, utf8(self._folder.title)))
                else:
                    error = u'Folder [%s] from map file not found!' % (
                        self.signature['id'])
                    # self.logger.error(error)
                    raise SyncInitError(error)

            if self.signature.get('archive'):
                self._archive = self._ox.get_folder('tasks',
                                                    self.signature['archive'])
                if self._folder is not None:
                    self.logger.debug(
                        u'Using folder [%s]: %s' %
                        (self._archive.id, utf8(self._archive.title)))
                else:
                    error = u'Archive folder [%s] from map file not found!' % (
                        self.signature['archive'])
                    # self.logger.error()
                    raise SyncInitError(error)
Exemplo n.º 13
0
    def update(self, other, that=None, this=None, sid=None):

        todo, task = ThisFromThat.update(self, other, that, this, sid)
        oxsync = self._engine
        ox = self._engine._ox
        tdsync = self._other
        tdapi = self._other.client
        update = self._update

        # region Toodledo task attributes
        # id, title, note, modified, completed, added
        # folder, context, goal, location, tag,
        # startdate, duedate, duedatemod, starttime, duetime,
        # remind, repeat,
        # status, star, priority,
        # length, timer
        # parent, children, order,
        # meta, previous, attachment,
        # shared, addedby, via, attachments
        # endregion

        # region Open-Xchange task attributes
        # modified_by, last_modified, folder_id, categories, private_flag, color_label
        # number_of_attachments, lastModifiedOfNewestAttachmentUTC,
        # title, start_date, end_date, note, alarm, date_completed
        # priority,status, percent_completed
        # actual_costs, actual_duration, billing_information, target_costs, target_duration, currency, trip_meter, companies
        # new columns available only since Rev. 7.6.1
        # but: works not for default folder Tasks
        # start_time,end_time, full_time
        # endregion

        title = utf8(todo.title)
        if title != task.title:
            task.title = title
            self.logger.debug(u'Title changed to [%s]' % (title))

        note = utf8(todo.note)
        if note != task.note:
            task.note = note

        DAY = 60 * 60 * 24
        OX_UTC_TIME = 0
        TD_UTC_TIME = 60 * 60 * 12

        full_time = None

        start_time = None
        start_date = None

        if todo._start_time:
            full_time = False
            start_time = todo._start_time + (ox.utc_offset / 1000)
            if start_time != task.start_time:
                self.logger.debug(
                    u'Start time changed from [%s] to [%s]' % (strflocal(
                        task.start_time, None), strflocal(start_time, None)))
        else:
            if todo._start_date:
                full_time = True
                start_date = todo._start_date - TD_UTC_TIME
            if start_date != task.start_date:
                self.logger.debug(
                    u'Start date changed from [%s] to [%s]' % (strflocal(
                        task.start_date, None), strflocal(start_date, None)))

        task.start_time = start_time
        task.start_date = start_date

        end_time = None
        end_date = None

        if todo._due_time:
            full_time = False
            end_time = todo._due_time + (ox.utc_offset / 1000)
            if end_time != task.end_time:
                self.logger.debug(
                    u'end time changed from [%s] to [%s]' % (strflocal(
                        task.end_time, None), strflocal(end_time, None)))
        else:
            if todo._due_date:
                full_time = True
                end_date = todo._due_date - TD_UTC_TIME
            if end_date != task.end_date:
                self.logger.debug(
                    u'end date changed from [%s] to [%s]' % (strflocal(
                        task.end_date, None), strflocal(end_date, None)))

        task.end_time = end_time
        task.end_date = end_date

        task.full_time = full_time

        alarm = None
        if todo._remind_date:
            alarm = todo._remind_date
        if alarm != task.alarm:
            self.logger.debug(
                u'Reminder changed from [%s] to [%s]' %
                (strflocal(task.alarm, None), strflocal(alarm, None)))
        task.alarm = alarm

        tags = []
        prefix_used = []
        categories = u''

        status = 0
        if not todo.completed:
            if todo.status is not None:
                status = self.status_map[todo.status]
                if tdsync.options.get('ox_tag_status'):
                    prefix = tdsync.options.get('ox_tag_status')
                    if todo.status not in [0, 1, 2, 5]:
                        # map to extended status tag
                        tag = prefix + ToodledoTask.STATUS[todo.status]
                        tags.append(tag)
                        prefix_used.append(prefix)
                        self.logger.debug(u'Create extended status tag [%]' %
                                          (tag))
        else:
            status = OxTask.get_status('Done')
            # task.date_completed = todo._date_completed

        if status != task.status:
            self.logger.debug(u'Status changed from [%s] to [%s]' %
                              (task.status, status))
        task.status = status

        priority = None
        if todo.priority is not None:
            priority = self.priority_map[todo.priority]
            if tdsync.options.get('ox_tag_priority'):
                prefix = tdsync.options.get('ox_tag_priority')
                if todo.priority == -1:
                    tag = utf8(prefix + 'Negative')
                    tags.append(tag)
                    prefix_used.append(prefix)
                    self.logger.debug(u'Create extendend priority tag [%s]' %
                                      (tag))
                elif todo.priority == 3:
                    tag = utf8(prefix + 'Top')
                    tags.append(tag)
                    prefix_used.append(prefix)
                    self.logger.debug(u'Create extendend priority tag [%s]' %
                                      (tag))
                else:
                    pass

        if priority != task.priority:
            self.logger.debug(u'Priority changed from [%s] to [%s]' %
                              (task.priority, priority))
        task.priority = priority

        if tdsync.options.get('ox_tag_star'):
            if todo.star:
                tag = tdsync.options.get('ox_tag_star')
                tags.append(tag)
                self.logger.debug(u'Create star tag [%s]' % (tag))

        if tdsync.options.get('ox_tag_context'):
            if todo.context:
                tag = tdsync.options.get('ox_tag_context') + tdapi.contexts[
                    todo.context]['name']
                tags.append(tag)
                self.logger.debug(u'Create context tag [%s]' % (tag))

        if tdsync.options.get('ox_tag_goal'):
            if todo.goal:
                tag = tdsync.options.get('ox_tag_goal') + tdapi.goals[
                    todo.goal]['name']
                tags.append(tag)
                self.logger.debug(u'Create goal tag [%s]' % (tag))

        if tdsync.options.get('ox_tag_location'):
            if todo.location:
                tag = tdsync.options.get('ox_tag_location') + tdapi.locations[
                    todo.location]['name']
                tags.append(tag)
                self.logger.debug(u'Create location tag [%s]' % (tag))

        for tag in todo.tag_names():
            if tag == tdsync.options.get('ox_tag_star', ','):
                continue
            elif tag.startswith(tdsync.options.get('ox_tag_context', ',')):
                continue
            elif tag.startswith(tdsync.options.get('ox_tag_goal', ',')):
                continue
            elif tag.startswith(tdsync.options.get('ox_tag_location', ',')):
                continue
            elif tag.startswith(tdsync.options.get('ox_tag_status', ',')):
                continue
            elif tag.startswith(tdsync.options.get('ox_tag_priority', ',')):
                continue
            else:
                tags.append(tag)
                self.logger.debug(u'Create category tag [%s]' % (tag))

        if len(tags) > 0:
            categories = u','.join(tags)
        if categories != task.categories:
            self.logger.debug(u'Categories changed from [%s] to [%s]' %
                              (task.categories, categories))
        task.categories = categories

        task.notification = True
        task._data['full_time'] = False

        task = task.update()
        task.load()
        self.logger.debug(u'%s: Updating completed with timestamp %s' %
                          (self.class_name, strflocal(task.timestamp)))
        return task
Exemplo n.º 14
0
    def _key(self): return utf8(self[self.NAME])

    @property
Exemplo n.º 15
0
 def title(self):
     if self._items.get(self._key) and self._items[self._key].get('key'):
         return utf8(self._items[self._key]['key'])
     return None
Exemplo n.º 16
0
 def __str__(self):
     return u'%s: %s items' % (utf8(self.__class__.__name__), len(self._beans))
Exemplo n.º 17
0
 def __repr__(self):
     return u'%s data=%s' % (self.__str__(), utf8(self.__dict__['_data']))
Exemplo n.º 18
0
    def __str__(self):

        return u'%s: %s %s' % (utf8(self.__class__.__name__),
                               utf8(self._id),
                               utf8(self._key))
Exemplo n.º 19
0
    def update(self, other, that=None, this=None, sid=None):

        note, todo = ThisFromThat.update(self, other, that, this, sid)

        tdsync = self._engine
        tdapi = self._engine.client
        ensync = self._other
        enapi = self._other.client
        update = self._update
        maxsize = self.options.get('maxsize', 2048)
        server_url = self.options.get('server_url')

        # region Toodledo task attributes
        # id, title, note, modified, completed, added
        # folder, context, goal, location, tag,
        # startdate, duedate, duedatemod, starttime, duetime,
        # remind, repeat,
        # status, star, priority,
        # length, timer
        # parent, children, order,
        # meta, previous, attachment,
        # shared, addedby, via, attachments
        # endregion

        # region Evernote note attributes
        # title, content, contentLength, plain, html
        # attributes.sourceURL
        # endregion

        note = note.load()
        title = utf8(note.title)
        if title != todo.title:
            todo.title = title
            self.logger.debug(u'Title changed to [%s]' % (title))

        ########################
        # process task content #
        ########################

        content = ''
        if note.contentLength > maxsize:
            self.logger.debug(u'%s: Evernote content exceeds limit of %d KB!' %
                              (self.class_name, maxsize / 1024))
            content += 'Evernote content exceeds limit of %d KB!\n' % (
                maxsize / 1024)
        else:
            content += note.plain.strip() + '\n\n'

        if self.options.get('evernote_sourceURL', True):
            if note.attributes.sourceURL:
                if not note.attributes.sourceURL.startswith(server_url):
                    self.logger.debug(
                        u'%s: Updating content with source URL %s' %
                        (self.class_name, note.attributes.sourceURL))
                    content += 'SOURCE: %s\n\n' % (note.attributes.sourceURL)

        if self.options.get('evernote_link', True):
            tag = self.options.get('evernote_link_tag', 'EVERNOTE')
            content = ensync.add_evernote_link(content, note.edit_url, tag)

        if self.options.get('evernote_iframe', True):
            tag = self.options.get('evernote_iframe_tag', 'IFRAME')
            content = ensync.add_evernote_link(content, note.view_url, tag)

        content = utf8(content) or u''
        if content != todo.note:
            todo.note = content
            # self.logger.debug(u'Note changed to [%s]' % (content[:16]))

        ############################
        # process other attributes #
        ############################

        # always update reminderTime from Evernote
        attribute = self.options.get('evernote_reminderTime')
        if attribute:
            if note.attributes.reminderTime:
                reminderTime = note.attributes.reminderTime / 1000
                todo[attribute] = reminderTime
                if attribute == 'duetime':
                    todo['duedate'] = todo['duetime']
                if attribute == 'starttime':
                    todo['startdate'] = todo['starttime']
            else:
                todo[attribute] = 0
            if attribute == 'duetime':
                todo['duedate'] = todo['duetime']
            if attribute == 'starttime':
                todo['startdate'] = todo['starttime']
            self.logger.debug(
                u'%s: Updating [%s] from note reminderTime [%s]' %
                (self.class_name, attribute,
                 strflocal(note.attributes.reminderTime, None)))

        # always update reminderDoneTime and task status
        completed = note.attributes.reminderDoneTime / 1000 if note.attributes.reminderDoneTime else 0
        todo.completed = completed

        ######################
        # process categories #
        ######################

        tags = []

        self.logger.debug(u'%s: Updating categories from tags %s' %
                          (self.class_name, note.categories))

        for tag in note.tags:
            if tag == tdsync.options.get('evernote_tag_star', ','):
                todo.star = True
                self.logger.debug(u'Set toodledo star from [%s]' % (tag))
            elif tag.startswith(tdsync.options.get('evernote_tag_context',
                                                   ',')):
                todo.context = tag[1:]
                self.logger.debug(u'Set toodledo context from [%s]' % (tag))
            elif tag.startswith(tdsync.options.get('evernote_tag_goal', ',')):
                todo.goal = tag[1:]
                self.logger.debug(u'Set toodledo goal from [%s]' % (tag))
            elif tag.startswith(
                    tdsync.options.get('evernote_tag_location', ',')):
                todo.location = tag[1:]
                self.logger.debug(u'Set toodledo location from [%s]' % (tag))
            elif tag.startswith(tdsync.options.get('evernote_tag_status',
                                                   ',')):
                if tag[1:] not in ToodledoTask.STATUS:
                    if self.status_map.get(tag[1:]) is None:
                        self.logger.warning(
                            'Ignoring unknown status tag [%s]' % (tag))
                        status = ToodledoTask.STATUS.index('None')
                    else:
                        status = self.status_map.get(tag[1:])
                else:
                    status = ToodledoTask.STATUS.index(tag[1:])
                    self.logger.debug(u'Set toodledo status from [%s]' % (tag))
                todo.status = status
            elif tag.startswith(
                    tdsync.options.get('evernote_tag_priority', ',')):
                priority = ToodledoTask.PRIORITY.get(tag[1:])
                if priority is None:
                    self.logger.warning(
                        'Change unknown priority tag [%s] to [Low]' % (tag))
                    priority = ToodledoTask.PRIORITY.get(tag[1:], 'Low')
                else:
                    self.logger.debug(u'Set toodledo priority [%s] from [%s]' %
                                      (priority, tag))
                todo.priority = priority
            else:
                tags.append(utf8(tag))
                self.logger.debug(u'Set toodledo tag from [%s]' % (tag))

        todo.tag = u''
        if len(tags) > 0:
            todo.tag = u','.join(tags)

        return todo
Exemplo n.º 20
0
    def update(self, other, that=None, this=None, sid=None):

        note, todo = ThisFromThat.update(self, other, that, this, sid)

        tdsync = self._engine; tdapi = self._engine.client
        ensync = self._other ;  enapi = self._other.client
        update = self._update
        maxsize = self.options.get('maxsize', 2048)
        server_url = self.options.get('server_url')

# region Toodledo task attributes
        # id, title, note, modified, completed, added
        # folder, context, goal, location, tag,
        # startdate, duedate, duedatemod, starttime, duetime,
        # remind, repeat,
        # status, star, priority,
        # length, timer
        # parent, children, order,
        # meta, previous, attachment,
        # shared, addedby, via, attachments
# endregion

# region Evernote note attributes
        # title, content, contentLength, plain, html
        # attributes.sourceURL
# endregion

        note = note.load()
        title = utf8(note.title)
        if title != todo.title:
            todo.title = title
            self.logger.debug(u'Title changed to [%s]' % (title))

        ########################
        # process task content #
        ########################

        content = ''
        if note.contentLength > maxsize:
            self.logger.debug(u'%s: Evernote content exceeds limit of %d KB!' % (self.class_name, maxsize/1024))
            content += 'Evernote content exceeds limit of %d KB!\n' % (maxsize/1024)
        else:
            content += note.plain.strip() + '\n\n'

        if self.options.get('evernote_sourceURL', True):
            if note.attributes.sourceURL:
                if not note.attributes.sourceURL.startswith(server_url):
                    self.logger.debug(u'%s: Updating content with source URL %s' % (self.class_name, note.attributes.sourceURL))
                    content += 'SOURCE: %s\n\n' % (note.attributes.sourceURL)

        if self.options.get('evernote_link', True):
            tag = self.options.get('evernote_link_tag', 'EVERNOTE')
            content = ensync.add_evernote_link(content, note.edit_url, tag)

        if self.options.get('evernote_iframe', True):
            tag = self.options.get('evernote_iframe_tag', 'IFRAME')
            content = ensync.add_evernote_link(content, note.view_url, tag)

        content = utf8(content) or u''
        if content != todo.note:
            todo.note = content
            # self.logger.debug(u'Note changed to [%s]' % (content[:16]))

        ############################
        # process other attributes #
        ############################

        # always update reminderTime from Evernote
        attribute = self.options.get('evernote_reminderTime')
        if attribute:
            if note.attributes.reminderTime:
                reminderTime = note.attributes.reminderTime/1000
                todo[attribute] = reminderTime
                if attribute == 'duetime':
                    todo['duedate'] = todo['duetime']
                if attribute == 'starttime':
                    todo['startdate'] = todo['starttime']
            else:
                todo[attribute] = 0
            if attribute == 'duetime':
                todo['duedate'] = todo['duetime']
            if attribute == 'starttime':
                todo['startdate'] = todo['starttime']
            self.logger.debug(u'%s: Updating [%s] from note reminderTime [%s]' %
                             (self.class_name, attribute, strflocal(note.attributes.reminderTime, None)))

        # always update reminderDoneTime and task status
        completed = note.attributes.reminderDoneTime/1000 if note.attributes.reminderDoneTime else 0
        todo.completed = completed

        ######################
        # process categories #
        ######################

        tags = []

        self.logger.debug(u'%s: Updating categories from tags %s' % (self.class_name, note.categories))

        for tag in note.tags:
            if tag == tdsync.options.get('evernote_tag_star', ','):
                todo.star = True
                self.logger.debug(u'Set toodledo star from [%s]' % (tag))
            elif tag.startswith(tdsync.options.get('evernote_tag_context', ',')):
                todo.context = tag[1:]
                self.logger.debug(u'Set toodledo context from [%s]' % (tag))
            elif tag.startswith(tdsync.options.get('evernote_tag_goal', ',')):
                todo.goal = tag[1:]
                self.logger.debug(u'Set toodledo goal from [%s]' % (tag))
            elif tag.startswith(tdsync.options.get('evernote_tag_location', ',')):
                todo.location = tag[1:]
                self.logger.debug(u'Set toodledo location from [%s]' % (tag))
            elif tag.startswith(tdsync.options.get('evernote_tag_status', ',')):
                if tag[1:] not in ToodledoTask.STATUS:
                    if self.status_map.get(tag[1:]) is None:
                        self.logger.warning('Ignoring unknown status tag [%s]' % (tag))
                        status = ToodledoTask.STATUS.index('None')
                    else:
                        status = self.status_map.get(tag[1:])
                else:
                    status = ToodledoTask.STATUS.index(tag[1:])
                    self.logger.debug(u'Set toodledo status from [%s]' % (tag))
                todo.status = status
            elif tag.startswith(tdsync.options.get('evernote_tag_priority', ',')):
                priority = ToodledoTask.PRIORITY.get(tag[1:])
                if priority is None:
                    self.logger.warning('Change unknown priority tag [%s] to [Low]' % (tag))
                    priority = ToodledoTask.PRIORITY.get(tag[1:], 'Low')
                else:
                    self.logger.debug(u'Set toodledo priority [%s] from [%s]' % (priority, tag))
                todo.priority = priority
            else:
                tags.append(utf8(tag))
                self.logger.debug(u'Set toodledo tag from [%s]' % (tag))

        todo.tag = u''
        if len(tags) > 0:
            todo.tag = u','.join(tags)

        return todo
Exemplo n.º 21
0
 def title(self):
     if self._items.get(self._key) and self._items[self._key].get('key'):
         return utf8(self._items[self._key]['key'])
     return None