Ejemplo 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']]
Ejemplo n.º 2
0
    def delete(self, sid=None):

        try:
            task = self._ox.get_task(self.folder.id, self.key)
        except Exception as e:
            self.logger.exception('Error loading task details for task [%s]: %s' % (self.key, self.title))
            return None

        if task.status and task.status == OxTask.get_status('Done'):
            if self._archive is not None:
                self.logger.debug(u'Moving completed task [%s] to archive [%s]' % (task.title, self._archive.title))
                try:
                    self._ox.move_task(self.folder.id, self.key, self._archive)
                except Exception as e:
                    self.logger.exception('Error moving completed task to archive [%s]: %s' % (self._archive.id, self._archive.title))
                    return None
                Sync.delete(self, sid)
                return

        self.logger.debug(u'Deleting task [%s]: %s' % (task.id, task.title))
        try:
            self._ox.delete_task(self.folder.id, self.key)
        except Exception as e:
            self.logger.exception('Error deleting task [%s]: %s' % (self.key, self.title))
            return None
        self._deleted[sid] = self._items[self.key]
        Sync.delete(self, sid)
Ejemplo 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']]
Ejemplo n.º 4
0
    def __init__(self, client, options, logger=None):

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

        if isinstance(client, EnClient):
            self._client = client
        else:
            self._client = EnClient.get_client(**client)

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

        if options.get('signature') is None:
            self._book = self._client.notebook(options.get('notebook'))
            if self._book is not None:
                signature = {'label': options.get('label')}
                signature['notebook'] = self._book.name
                signature['guid'] = self._book.guid
                self.options.update({'signature': signature})
            else:
                error = u'Evernote notebook [%s] not found' % (options.get('notebook'))
                self.logger.error(error)
                raise SyncInitError(error)
        else:
            self._book = self._client.notebook(self.signature.get('guid'))
            if self._book is None:
                error = u'Evernote notebook [%s] not loaded' % (options.get(self.signature.get('guid')))
                self.logger.error(error)
                raise SyncInitError(error)
Ejemplo n.º 5
0
    def delete(self, sid=None):

        try:
            task = self._ox.get_task(self.folder.id, self.key)
        except Exception as e:
            self.logger.exception(
                'Error loading task details for task [%s]: %s' %
                (self.key, self.title))
            return None

        if task.status and task.status == OxTask.get_status('Done'):
            if self._archive is not None:
                self.logger.debug(
                    u'Moving completed task [%s] to archive [%s]' %
                    (task.title, self._archive.title))
                try:
                    self._ox.move_task(self.folder.id, self.key, self._archive)
                except Exception as e:
                    self.logger.exception(
                        'Error moving completed task to archive [%s]: %s' %
                        (self._archive.id, self._archive.title))
                    return None
                Sync.delete(self, sid)
                return

        self.logger.debug(u'Deleting task [%s]: %s' % (task.id, task.title))
        try:
            self._ox.delete_task(self.folder.id, self.key)
        except Exception as e:
            self.logger.exception('Error deleting task [%s]: %s' %
                                  (self.key, self.title))
            return None
        self._deleted[sid] = self._items[self.key]
        Sync.delete(self, sid)
Ejemplo n.º 6
0
 def delete(self, sid=None):
     try:
         self._client.delete_note(self.key)
     except Exception as e:
         self.logger.exception(u'Note [%s] not found!' % (self.title))
         return None
     if sid is not None:
         self._deleted[sid] = self._items[self.key]
     Sync.delete(self, sid)
Ejemplo n.º 7
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)
Ejemplo n.º 8
0
 def map_item(self, ref=None):
     if isinstance(ref, OxTask):
         return {
             'id': ref.id,
             'key': ref[self._key_attribute],
             'time': ref.timestamp
         }
     else:
         return Sync.map_item(self, ref)
Ejemplo n.º 9
0
 def map_item(self, ref=None):
     if isinstance(ref, ToodledoTask):
         # return {'id': ref.id, 'key': ref[self._key_attribute], 'time': ref.modified * 1000}
         return {
             'id': ref._id,
             'key': ref[self._key_attribute],
             'time': ref._time
         }
     else:
         return Sync.map_item(self, ref)
Ejemplo n.º 10
0
    def changed(self, sync):

        if not Sync.changed(self, sync):

            # check extra attributes
            sync_extra = sync.get('extra')

            item = self._items.get(self._key)
            item_extra = item.get('extra')
            self.logger.debug(u'%s: Checking extra attributes %s' % (self.class_name, item_extra))

            if sync_extra is not None and item_extra is not None:
                if sync_extra.get('reminderTime') == item_extra.get('reminderTime'):
                    if sync_extra.get('reminderDoneTime') == item_extra.get('reminderDoneTime'):
                        if EnClientSync.compare_tags(sync_extra.get('tags'), item_extra.get('tags')):
                            return False
                        else:
                            self.logger.debug(u'%s: Tags changed' % (self.class_name))
                    else:
                        self.logger.debug(u'%s: Reminder done time changed' % (self.class_name))
                else:
                    self.logger.debug(u'%s: Reminder time changed' % (self.class_name))
        return True
Ejemplo n.º 11
0
 def map_item(self, ref=None):
     if isinstance(ref, ToodledoTask):
         # return {'id': ref.id, 'key': ref[self._key_attribute], 'time': ref.modified * 1000}
         return {'id': ref._id, 'key': ref[self._key_attribute], 'time': ref._time}
     else:
         return Sync.map_item(self, ref)
Ejemplo n.º 12
0
 def delete(self, sid=None):
     self._client.delete_task(self.key)
     Sync.delete(self, sid)
Ejemplo n.º 13
0
 def changed(self, sync):
     return Sync.changed(self, sync)
Ejemplo n.º 14
0
 def delete(self, sid=None):
     self._client.delete_task(self.key)
     Sync.delete(self, sid)
Ejemplo n.º 15
0
 def changed(self, sync):
     return Sync.changed(self, sync)
Ejemplo n.º 16
0
 def map_item(self, ref=None):
     if isinstance(ref, OxTask):
         return {'id': ref.id, 'key': ref[self._key_attribute], 'time': ref.timestamp}
     else:
         return Sync.map_item(self, ref)
Ejemplo n.º 17
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)