def create_torrent(self, metainfo, save_incomplete_as, save_as,
                       hidden=False, is_auto_update=False, feedback=None):
        if self.is_single_torrent and len(self.torrents) > 0:
            raise TooManyTorrents(_("MultiTorrent is set to download only "
                 "a single torrent, but tried to create more than one."))

        #save_as, junk = encode_for_filesystem(save_as)
        #save_incomplete_as, junk = encode_for_filesystem(save_incomplete_as)
        infohash = metainfo.infohash
        if self.torrent_known(infohash):
            if self.torrent_running(infohash):
                msg = _("This torrent (or one with the same contents) is "
                        "already running.")
                raise TorrentAlreadyRunning(msg)
            else:
                raise TorrentAlreadyInQueue(_("This torrent (or one with "
                                              "the same contents) is "
                                              "already waiting to run."))
        self._dump_metainfo(metainfo)

        #BUG.  Use _read_torrent_config for 5.0?  --Dave
        config = configfile.read_torrent_config(self.config,
                                                self.data_dir,
                                                infohash,
                                                lambda s : self.global_error(logging.ERROR, s))

        t = Torrent(metainfo, save_incomplete_as, save_as, self.config,
                    self.data_dir, self.rawserver, self.choker,
                    self.singleport_listener, self.up_ratelimiter,
                    self.down_ratelimiter, self.total_downmeasure,
                    self.filepool, self.dht, self,
                    self.log_root, hidden=hidden, is_auto_update=is_auto_update)
        if feedback:
            t.add_feedback(feedback)

        retdf = Deferred()

        def torrent_started(*args):
            if config:
                t.update_config(config)

            t._dump_torrent_config()
            if self.resume_from_torrent_config:
                self._dump_torrents()
            t.metainfo.show_encoding_errors(self.logger.log)

            retdf.callback(t)

        df = self._init_torrent(t, use_policy=False)
        df.addCallback(torrent_started)

        return retdf
Example #2
0
    def create_torrent(self, metainfo, save_incomplete_as, save_as,
                       hidden=False, is_auto_update=False, feedback=None):
        if self.is_single_torrent and len(self.torrents) > 0:
            raise TooManyTorrents(_("MultiTorrent is set to download only "
                 "a single torrent, but tried to create more than one."))

        infohash = metainfo.infohash
        if self.torrent_known(infohash):
            if self.torrent_running(infohash):
                msg = _("This torrent (or one with the same contents) is "
                        "already running.")
                raise TorrentAlreadyRunning(msg)
            else:
                raise TorrentAlreadyInQueue(_("This torrent (or one with "
                                              "the same contents) is "
                                              "already waiting to run."))
        self._dump_metainfo(metainfo)

        #BUG.  Use _read_torrent_config for 5.0?  --Dave
        config = configfile.read_torrent_config(self.config,
                                                self.data_dir,
                                                infohash,
                                                lambda s : self.global_error(logging.ERROR, s))

        t = Torrent(metainfo, save_incomplete_as, save_as, self.config,
                    self.data_dir, self.rawserver, self.choker,
                    self.singleport_listener, self.up_ratelimiter,
                    self.down_ratelimiter, self.total_downmeasure,
                    self.filepool, self.dht, self,
                    self.log_root, hidden=hidden,
                    is_auto_update=is_auto_update)
        if feedback:
            t.add_feedback(feedback)

        retdf = Deferred()

        def torrent_started(*args):
            if config:
                t.update_config(config)

            t._dump_torrent_config()
            if self.resume_from_torrent_config:
                self._dump_torrents()
            t.metainfo.show_encoding_errors(self.logger.log)

            retdf.callback(t)

        df = self._init_torrent(t, use_policy=False)
        df.addCallback(torrent_started)

        return retdf
Example #3
0
                except:
                    pass
                self.logger.error((_("Error reading metainfo file \"%s\".") %
                                   hashtext) + " (" + str_exc(e) + "), " +
                                  _("cannot restore state completely"))
                return None
            except Exception, e:
                self.logger.error((_(
                    "Corrupt data in metainfo \"%s\", cannot restore torrent.")
                                   % hashtext) + '(' + str_exc(e) + ')')
                return None

            b = encode_for_filesystem(u'')[0]
            t = Torrent(metainfo, b, b, self.config, self.data_dir,
                        self.rawserver, self.choker, self.singleport_listener,
                        self.up_ratelimiter, self.down_ratelimiter,
                        self.total_downmeasure, self.filepool, self.dht, self,
                        self.log_root)
            t.metainfo.reported_errors = True  # suppress redisplay on restart
            if infohash != t.metainfo.infohash:
                self.logger.error(
                    (_("Corrupt data in \"%s\", cannot restore torrent.") %
                     hashtext) + _("(infohash mismatch)"))
                return None
            if len(line) == 41:
                t.working_path = None
                t.destination_path = None
                return infohash, t
            try:
                if version < 2:
                    t.working_path = line[41:-1].decode('string_escape')
                    f.close()
                except:
                    pass
                self.logger.error((_("Error reading metainfo file \"%s\".") %
                                  hashtext) + " (" + str_exc(e)+ "), " +
                                  _("cannot restore state completely"))
                return None
            except Exception, e:
                self.logger.error((_("Corrupt data in metainfo \"%s\", cannot restore torrent.") % hashtext) +
                                  '('+str_exc(e)+')')
                return None

            b = encode_for_filesystem(u'')[0]
            t = Torrent(metainfo, b, b, self.config, self.data_dir,
                        self.rawserver, self.choker,
                        self.singleport_listener, self.up_ratelimiter,
                        self.down_ratelimiter,
                        self.total_downmeasure, self.filepool, self.dht, self,
                        self.log_root)
            t.metainfo.reported_errors = True # suppress redisplay on restart
            if infohash != t.metainfo.infohash:
                self.logger.error((_("Corrupt data in \"%s\", cannot restore torrent.") % hashtext) +
                                  _("(infohash mismatch)"))
                return None
            if len(line) == 41:
                t.working_path = None
                t.destination_path = None
                return infohash, t
            try:
                if version < 2:
                    t.working_path = line[41:-1].decode('string_escape')
                    t.working_path = t.working_path.decode('utf-8')