Esempio n. 1
0
File: Task.py Progetto: iven/Yaner
 def pause(self):
     """Pause task if it's running."""
     if self.is_pausable:
         deferred = self.pool.proxy.call('aria2.pause', self.gid)
         deferred.add_callback(self._on_paused)
         deferred.add_errback(self._on_xmlrpc_error)
         deferred.start()
Esempio n. 2
0
 def pause(self):
     """Pause task if it's running."""
     if self.is_pausable:
         deferred = self.pool.proxy.call('aria2.pause', self.gid)
         deferred.add_callback(self._on_paused)
         deferred.add_errback(self._on_xmlrpc_error)
         deferred.start()
Esempio n. 3
0
 def trash(self):
     """Move task to dustbin."""
     if not self.is_trashed:
         if self.is_running:
             deferred = self.pool.proxy.call('aria2.remove', self.gid)
             deferred.add_callback(self._on_trashed)
             deferred.add_errback(self._on_xmlrpc_error)
             deferred.start()
         else:
             self._on_trashed()
Esempio n. 4
0
 def start(self):
     """Unpause task if it's paused, otherwise add it (again)."""
     if self.is_unpausable:
         deferred = self.pool.proxy.call('aria2.unpause', self.gid)
         deferred.add_callback(self._on_unpaused)
         deferred.add_errback(self._on_xmlrpc_error)
         deferred.start()
     elif self.is_addable:
         self.add()
         self.pool.queuing.add_task(self)
Esempio n. 5
0
File: Task.py Progetto: iven/Yaner
 def trash(self):
     """Move task to dustbin."""
     if not self.is_trashed:
         if self.is_running:
             deferred = self.pool.proxy.call('aria2.remove', self.gid)
             deferred.add_callback(self._on_trashed)
             deferred.add_errback(self._on_xmlrpc_error)
             deferred.start()
         else:
             self._on_trashed()
Esempio n. 6
0
File: Task.py Progetto: iven/Yaner
 def start(self):
     """Unpause task if it's paused, otherwise add it (again)."""
     if self.is_unpausable:
         deferred = self.pool.proxy.call('aria2.unpause', self.gid)
         deferred.add_callback(self._on_unpaused)
         deferred.add_errback(self._on_xmlrpc_error)
         deferred.start()
     elif self.is_addable:
         self.add()
         self.pool.queuing.add_task(self)
Esempio n. 7
0
    def _update_session_id(self):
        """Get session id of the pool and store it in task."""
        def on_got_session_info(deferred):
            """Set session id the task belongs to."""
            self.session_id = deferred.result['sessionId']
            SQLSession.commit()

        deferred = self.pool.proxy.call('aria2.getSessionInfo', self.gid)
        deferred.add_callback(on_got_session_info)
        deferred.add_errback(self._on_xmlrpc_error)
        deferred.start()
Esempio n. 8
0
File: Task.py Progetto: iven/Yaner
    def _update_session_id(self):
        """Get session id of the pool and store it in task."""
        def on_got_session_info(deferred):
            """Set session id the task belongs to."""
            self.session_id = deferred.result['sessionId']
            SQLSession.commit()

        deferred = self.pool.proxy.call('aria2.getSessionInfo', self.gid)
        deferred.add_callback(on_got_session_info)
        deferred.add_errback(self._on_xmlrpc_error)
        deferred.start()
Esempio n. 9
0
    def _call_tell_status(self):
        """Call pool for the status of this task.

        Return True to keep calling this when timeout else stop.

        """
        if self.is_running:
            deferred = self.pool.proxy.call('aria2.tellStatus', self.gid)
            deferred.add_callback(self._update_status)
            deferred.add_errback(self._on_xmlrpc_error)
            deferred.start()
            return True
        else:
            self.end_update_status()
            return False
Esempio n. 10
0
    def add(self):
        """Add the task to pool."""
        proxy = self.pool.proxy
        options = dict(self.options)
        if self.metafile:
            deferred = proxy.call('aria2.addMetalink', self.metafile, options)
        elif self.torrent:
            deferred = proxy.call('aria2.addTorrent', self.torrent, self.uris,
                                  options)
        else:
            deferred = proxy.call('aria2.addUri', self.uris, options)

        deferred.add_callback(self._on_started)
        deferred.add_errback(self._on_xmlrpc_error)
        deferred.start()
Esempio n. 11
0
File: Task.py Progetto: iven/Yaner
    def _call_tell_status(self):
        """Call pool for the status of this task.

        Return True to keep calling this when timeout else stop.

        """
        if self.is_running:
            deferred = self.pool.proxy.call('aria2.tellStatus', self.gid)
            deferred.add_callback(self._update_status)
            deferred.add_errback(self._on_xmlrpc_error)
            deferred.start()
            return True
        else:
            self.end_update_status()
            return False
Esempio n. 12
0
File: Task.py Progetto: iven/Yaner
    def add(self):
        """Add the task to pool."""
        proxy = self.pool.proxy
        options = dict(self.options)
        if self.metafile:
            deferred = proxy.call('aria2.addMetalink', self.metafile, options)
        elif self.torrent:
            deferred = proxy.call('aria2.addTorrent', self.torrent,
                                  self.uris, options)
        else:
            deferred = proxy.call('aria2.addUri', self.uris, options)

        deferred.add_callback(self._on_started)
        deferred.add_errback(self._on_xmlrpc_error)
        deferred.start()