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
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
t.working_path = working_path.decode('string_escape') t.working_path = t.working_path.decode('utf-8') t.working_path = encode_for_filesystem(t.working_path)[0] t.destination_path = t.working_path elif version >= 4: up, down = line[41:-1].split(' ', 1) t.uptotal = t.uptotal_old = int(up) t.downtotal = t.downtotal_old = int(down) except ValueError: # unpack, int(), decode() raise BTFailure(_("Invalid state file (bad entry)")) torrent_config = self.config try: if version < 5: torrent_config = configfile.read_torrent_config( self.config, self.data_dir, infohash, lambda s: self.global_error(logging.ERROR, s)) else: torrent_config = self._read_torrent_config(infohash) t.update_config(torrent_config) except BTFailure, e: self.logger.error("Read torrent config failed", exc_info=sys.exc_info()) # if read_torrent_config fails then ignore the torrent... return None return infohash, t # BEGIN _restore_state assert self.resume_from_torrent_config filename = os.path.join(self.data_dir, 'ui_state')
t.working_path = t.working_path.decode('utf-8') t.working_path = encode_for_filesystem(t.working_path)[0] t.destination_path = t.working_path elif version >= 4: up, down = line[41:-1].split(' ', 1) t.uptotal = t.uptotal_old = int(up) t.downtotal = t.downtotal_old = int(down) except ValueError: # unpack, int(), decode() raise BTFailure(_("Invalid state file (bad entry)")) torrent_config = self.config try: if version < 5: torrent_config = configfile.read_torrent_config( self.config, self.data_dir, infohash, lambda s : self.global_error(logging.ERROR, s)) else: torrent_config = self._read_torrent_config(infohash) t.update_config(torrent_config) except BTFailure, e: self.logger.error("Read torrent config failed", exc_info=sys.exc_info()) # if read_torrent_config fails then ignore the torrent... return None return infohash, t # BEGIN _restore_state assert self.resume_from_torrent_config filename = os.path.join(self.data_dir, 'ui_state')
try: if version < 2: t.dlpath = line[41:-1].decode('string_escape') elif version == 3: up, down, dlpath = line[41:-1].split(' ', 2) t.uptotal = t.uptotal_old = int(up) t.downtotal = t.downtotal_old = int(down) t.dlpath = dlpath.decode('string_escape') elif version >= 4: up, down = line[41:-1].split(' ', 1) t.uptotal = t.uptotal_old = int(up) t.downtotal = t.downtotal_old = int(down) except ValueError: # unpack, int(), decode() raise BTFailure(_("Invalid state file (bad entry)")) config = configfile.read_torrent_config(self.config, self.config['data_dir'], infohash, self.global_error) t.config.update(config) return infohash, t filename = os.path.join(self.config['data_dir'], 'ui_state') if not os.path.exists(filename): return f = None try: f = file(filename, 'rb') lines = f.readlines() f.close() except Exception, e: if f is not None: f.close() raise BTFailure(str(e))
try: if version < 2: t.dlpath = line[41:-1].decode('string_escape') elif version == 3: up, down, dlpath = line[41:-1].split(' ', 2) t.uptotal = t.uptotal_old = int(up) t.downtotal = t.downtotal_old = int(down) t.dlpath = dlpath.decode('string_escape') elif version >= 4: up, down = line[41:-1].split(' ', 1) t.uptotal = t.uptotal_old = int(up) t.downtotal = t.downtotal_old = int(down) except ValueError: # unpack, int(), decode() raise BTFailure(_("Invalid state file (bad entry)")) config = configfile.read_torrent_config(self.config, self.config['data_dir'], infohash, self.global_error) t.config.update(config) return infohash, t filename = os.path.join(self.config['data_dir'], 'ui_state') if not os.path.exists(filename): return f = None try: f = file(filename, 'rb') lines = f.readlines() f.close() except Exception, e: if f is not None: f.close()