Esempio n. 1
0
 def search(self, criteria):
     # Tell API to search
     results = self.api.search(criteria)
     self.api.logout()
     if results:
         return results
     else:
         raise utils.DataError('No results.')
Esempio n. 2
0
    def queue_add(self, show):
        """
        Queues a show add

        Calls this to add a show to the list, and the remote add
        will be queued.

        show: Show dictionary

        """
        showid = show['id']

        # Add to the list
        if self.showlist.get(showid):
            raise utils.DataError("Show already in the list.")

        self.showlist[showid] = show

        # Check if the show add is already in queue
        exists = False
        for q in self.queue:
            if q['id'] == showid and q['action'] == 'add':
                # This shouldn't happen
                raise utils.DataError("Show already in the queue.")

        if not exists:
            # Use the whole show as a queue item
            item = show
            item['action'] = 'add'
            self.queue.append(item)

        show['queued'] = True

        self._save_queue()
        self._save_cache()
        self._emit_signal('queue_changed', self.queue)
        self.msg.info(self.name, "Queued add for %s" % show['title'])
Esempio n. 3
0
    def queue_delete(self, show):
        """
        Queues a show delete

        Calls this to delete a show from the list, and the remote delete
        will be queued.

        show: Show dictionary

        """
        showid = show['id']

        # Delete from the list
        if not self.showlist.get(showid):
            raise utils.DataError("Show not in the list.")

        item = self.showlist.pop(showid)

        # Check if the show add is already in queue
        exists = False
        for q in self.queue:
            if q['id'] == showid and q['action'] == 'delete':
                # This shouldn't happen
                raise utils.DataError("Show delete already in the queue.")

        if not exists:
            # Use the whole show as a queue item
            item['action'] = 'delete'
            self.queue.append(item)

        show['queued'] = True

        self._save_queue()
        self._save_cache()
        self._emit_signal('queue_changed', self.queue)
        self.msg.info(self.name, "Queued delete for %s" % item['title'])
Esempio n. 4
0
    def queue_update(self, show, key, value):
        """
        Queues a show update

        Call this to change anything of an item in the list, as it will be
        modified locally and queued for update in the next remote sync.

        show: Show dictionary
        key: The key that will be modified (it must exist beforehand)
        value: The value that it should be changed to
        """
        if key not in show:
            raise utils.DataError('Invalid key for queue update.')

        # Do update on memory
        show[key] = value

        # Check if the show update is already in queue
        exists = False
        for q in self.queue:
            if q['id'] == show['id'] and q['action'] in ['add', 'update']:
                # Add the changed value to the already existing queue item
                q[key] = value
                exists = True
                break

        if not exists:
            # Create queue item and append it
            item = {
                'id': show['id'],
                'my_id': show['my_id'],
                'action': 'update',
                'title': show['title'],
            }
            item[key] = value
            self.queue.append(item)

        show['queued'] = True

        self._save_queue()
        self._save_cache()
        self._emit_signal('queue_changed', self.queue)
        self.msg.info(self.name, "Queued update for %s" % show['title'])
        self.msg.debug(self.name, "Queued: {} -> {}".format(key, value))

        # Immediately process the action if necessary
        if self._is_queue_ready():
            self.process_queue()