Example #1
0
    def seed(self, widget=None):
        for f in self.file_list:
	    if self.parent.parent:
		launch_coroutine(wx.the_app.gui_wrap, wx.the_app.publish_torrent, f+EXTENSION, f)
	    else:
		btspawn('bittorrent', f+EXTENSION, '--publish', f)
        self.cancel()
 def seed(self, widget=None):
     for f in self.file_list:
         if self.parent.parent:
             launch_coroutine(wx.the_app.gui_wrap,
                              wx.the_app.publish_torrent, f + EXTENSION, f)
         else:
             btspawn('bittorrent', f + EXTENSION, '--publish', f)
     self.cancel()
Example #3
0
 def shutdown(self):
     self.logger.debug("multitorrent shutting down")
     print "shutting down"
     df = launch_coroutine(wrap_task(self.rawserver.add_task), self._shutdown)
     df.addErrback(lambda f : self.logger.error('shutdown failed!',
                                                exc_info=f.exc_info()))
     return df
Example #4
0
 def run(r=None):
     if w.total > 1000:
         reactor.stop()
         return
     w.total += 1
     df = launch_coroutine(wrap_task(reactor.callLater), w.do_some_things)
     df.addCallback(run)
     df.addErrback(set_event_error)
Example #5
0
 def run_task_and_exit():
     #for i in xrange(1000):
     for i in xrange(100040):
         w.total += 1
         df = launch_coroutine(wrap_task(reactor.callLater),
                               w.do_some_things)
         df.addCallback(set_event)
         df.addErrback(set_event_error)
Example #6
0
 def run_task_and_exit():
     #for i in xrange(1000):
     for i in xrange(100040):
         w.total += 1
         df = launch_coroutine(wrap_task(reactor.callLater),
                               w.do_some_things)
         df.addCallback(set_event)
         df.addErrback(set_event_error)
Example #7
0
 def make_statusrequest(self, event = None):
     """Make status request."""
     df = launch_coroutine(self.gui_wrap, self.update_status)
     def errback(f):
         self.logger.error("update_status failed",
                           exc_info=f.exc_info())
     df.addErrback(errback)
     return True
Example #8
0
 def run(r=None):
     if w.total > 1000:
         reactor.stop()
         return
     w.total += 1
     df = launch_coroutine(wrap_task(reactor.callLater),
                           w.do_some_things)
     df.addCallback(run)
     df.addErrback(set_event_error)
Example #9
0
    def make_statusrequest(self, event=None):
        """Make status request."""
        df = launch_coroutine(self.gui_wrap, self.update_status)

        def errback(f):
            self.logger.error("update_status failed", exc_info=f.exc_info())

        df.addErrback(errback)
        return True
Example #10
0
 def callback(metainfo):
     def open(metainfo):
         df = self.multitorrent.torrent_known(metainfo.infohash)
         yield df
         known = df.getResult()
         if known:
             self.torrent_already_open(metainfo)
         else:
             df = self.open_torrent_metainfo(metainfo)
             if df is not None:
                 yield df
                 try:
                     df.getResult()
                 except TorrentAlreadyInQueue:
                     pass
                 except TorrentAlreadyRunning:
                     pass
     launch_coroutine(self.gui_wrap, open, metainfo)
Example #11
0
 def check_version(self):
     """Launch the actual version check code in a coroutine since
     it needs to make three (or four, in beta) http requests, one
     disk read, and one decryption."""
     df = launch_coroutine(wrap_task(self.rawserver.external_add_task),
                           self._check_version)
     def errback(e):
         self.logger.error('check_version() run #%d: ' % self.runs,
                           exc_info=e.exc_info())
     df.addErrback(errback)
Example #12
0
        def callback(metainfo):
            def open(metainfo):
                df = self.multitorrent.torrent_known(metainfo.infohash)
                yield df
                known = df.getResult()
                if known:
                    self.torrent_already_open(metainfo)
                else:
                    df = self.open_torrent_metainfo(metainfo)
                    if df is not None:
                        yield df
                        try:
                            df.getResult()
                        except TorrentAlreadyInQueue:
                            pass
                        except TorrentAlreadyRunning:
                            pass

            launch_coroutine(self.gui_wrap, open, metainfo)
Example #13
0
 def external_command(self, action, *datas):
     """For communication via IPC"""
     datas = [d.decode("utf-8") for d in datas]
     if action == "start_torrent":
         assert len(datas) == 1, "incorrect data length"
         self.append_external_torrents(*datas)
         self.logger.info('got external_command:start_torrent: "%s"' % datas[0])
         # this call does Ye Olde Threadede Deferrede:
         self.open_external_torrents()
     elif action == "publish_torrent":
         self.logger.info('got external_command:publish_torrent: "%s" as "%s"' % datas)
         launch_coroutine(self.gui_wrap, self.publish_torrent, datas[0], datas[1])
     elif action == "show_error":
         assert len(datas) == 1, "incorrect data length"
         self.logger.error(datas[0])
     elif action == "no-op":
         self.no_op()
         self.logger.info("got external_command: no-op")
     else:
         self.logger.warning("got unknown external_command: %s" % str(action))
Example #14
0
    def check_version(self):
        """Launch the actual version check code in a coroutine since
        it needs to make three (or four, in beta) http requests, one
        disk read, and one decryption."""
        df = launch_coroutine(wrap_task(self.rawserver.external_add_task),
                              self._check_version)

        def errback(e):
            self.logger.error('check_version() run #%d: ' % self.runs,
                              exc_info=e.exc_info())

        df.addErrback(errback)
Example #15
0
    def open_external_torrents(self):
        """Open torrents added externally (on the command line before startup)."""
        if self.open_external_torrents_deferred is None and len(self.external_torrents):
            self.open_external_torrents_deferred = launch_coroutine(self.gui_wrap, self._open_external_torrents)

            def callback(*a):
                self.open_external_torrents_deferred = None

            def errback(f):
                callback()
                self.logger.error("open_external_torrents failed:", exc_info=f.exc_info())

            self.open_external_torrents_deferred.addCallback(callback)
            self.open_external_torrents_deferred.addErrback(errback)
Example #16
0
 def external_command(self, action, *datas):
     """For communication via IPC"""
     datas = [d.decode('utf-8') for d in datas]
     if action == 'start_torrent':
         assert len(datas) == 1, 'incorrect data length'
         self.append_external_torrents(*datas)
         self.logger.info('got external_command:start_torrent: "%s"' %
                          datas[0])
         # this call does Ye Olde Threadede Deferrede:
         self.open_external_torrents()
     elif action == 'publish_torrent':
         self.logger.info(
             'got external_command:publish_torrent: "%s" as "%s"' % datas)
         launch_coroutine(self.gui_wrap, self.publish_torrent, datas[0],
                          datas[1])
     elif action == 'show_error':
         assert len(datas) == 1, 'incorrect data length'
         self.logger.error(datas[0])
     elif action == 'no-op':
         self.no_op()
         self.logger.info('got external_command: no-op')
     else:
         self.logger.warning('got unknown external_command: %s' %
                             str(action))
Example #17
0
    def open_external_torrents(self):
        """Open torrents added externally (on the command line before startup)."""
        if self.open_external_torrents_deferred is None and \
               len(self.external_torrents):
            self.open_external_torrents_deferred = launch_coroutine(
                self.gui_wrap, self._open_external_torrents)

            def callback(*a):
                self.open_external_torrents_deferred = None

            def errback(f):
                callback()
                self.logger.error("open_external_torrents failed:",
                                  exc_info=f.exc_info())

            self.open_external_torrents_deferred.addCallback(callback)
            self.open_external_torrents_deferred.addErrback(errback)
Example #18
0
 def run_gen():
     def gen():
         global a
         for i in xrange(m):
             df = Deferred()
             #rawserver.add_task(0, df.callback, lambda r: r)
             df.callback(1)
             yield df
             df.getResult()
             a[i] = time.clock()
             
     mdf = launch_coroutine(wrap_task(rawserver.add_task), gen)
     def done(r=None):
         print 'yielddefer\t', len(a), a[-1] - a[0], '\t', avg_dist(a)
         i = 0
         if stackless:
             print 'stackless'
             run_gen2()
         else:
             run_gen3()
     mdf.addCallback(done)
Example #19
0
    def run_gen():
        def gen():
            global a
            for i in xrange(m):
                df = Deferred()
                #rawserver.add_task(0, df.callback, lambda r: r)
                df.callback(1)
                yield df
                df.getResult()
                a[i] = time.clock()

        mdf = launch_coroutine(wrap_task(rawserver.add_task), gen)

        def done(r=None):
            print 'yielddefer\t', len(a), a[-1] - a[0], '\t', avg_dist(a)
            i = 0
            if stackless:
                print 'stackless'
                run_gen2()
            else:
                run_gen3()

        mdf.addCallback(done)
Example #20
0
 def initialize_torrents(self):
     df = launch_coroutine(wrap_task(self.rawserver.add_task),
                           self._initialize_torrents)
     df.addErrback(lambda f: self.logger.error(
         'initialize_torrents failed!', exc_info=f.exc_info()))
     return df
Example #21
0
 def shutdown(self):
     df = launch_coroutine(wrap_task(self.rawserver.add_task),
                           self._shutdown)
     df.addErrback(lambda f: self.logger.error('shutdown failed!',
                                               exc_info=f.exc_info()))
     return df
Example #22
0
 def __init__(self, queue_task):
     self.killswitch = threading.Event()
     self.queue = defer.DeferredQueue()
     self.main_df = launch_coroutine(queue_task, self.run)
Example #23
0
 def initialize_torrents(self):
     df = launch_coroutine(wrap_task(self.rawserver.add_task), self._initialize_torrents)
     df.addErrback(lambda f : self.logger.error('initialize_torrents failed!',
                                                exc_info=f.exc_info()))
     return df
Example #24
0
 def shutdown(self):
     df = launch_coroutine(wrap_task(self.rawserver.add_task), self._shutdown)
     df.addErrback(lambda f : self.logger.error('shutdown failed!',
                                                exc_info=f.exc_info()))
     return df
Example #25
0
 def write(self, pos, s):
     df = launch_coroutine(wrap_task(self.add_task),
                           self._batch_write, pos, s)
     return df
Example #26
0
 def read(self, pos, amount):
     df = launch_coroutine(wrap_task(self.add_task),
                           self._batch_read, pos, amount)
     return df
Example #27
0
def coro(f, *args, **kwargs):
    return launch_coroutine(wrap_task(reactor.callLater), f, *args, **kwargs)
Example #28
0
 def replacement(*a, **kw):
     return launch_coroutine(wrap_task(reactor.callLater), _f, *a, **kw)
Example #29
0
 def __init__(self, queue_task):
     self.killswitch = threading.Event()
     self.queue = defer.DeferredQueue()
     self.main_df = launch_coroutine(queue_task, self.run)
Example #30
0
 def replacement(*a, **kw):
     return launch_coroutine(wrap_task(reactor.callLater), _f, *a, **kw)
Example #31
0
def coro(f, *args, **kwargs):
    return launch_coroutine(wrap_task(reactor.callLater), f, *args, **kwargs)