def _restore_state(self): def decode_line(line): hashtext = line[:40] try: infohash = hashtext.decode('hex') except: raise BTFailure("Invalid state file contents") if len(infohash) != 20: raise BTFailure("Invalid state file contents") try: path = os.path.join(self.config['data_dir'], 'metainfo', hashtext) f = file(path, 'rb') data = f.read() f.close() except Exception, e: try: f.close() except: pass self.global_error("ERROR", "Error reading file %s (%s), \ cannot restore state completely" % (path, str(e))) return None if infohash in self.torrents: raise BTFailure("Invalid state file (duplicate entry)") t = Torrent(infohash) self.torrents[infohash] = t try: t.metainfo = ConvertedMetainfo(bdecode(data)) except Exception, e: self.global_error("ERROR", "Corrupt data in "+path+ " , cannot restore torrent ("+str(e)+")") return None
def _restore_state(self): def decode_line(line): hashtext = line[:40] try: infohash = hashtext.decode('hex') except: raise BTFailure("Invalid state file contents") if len(infohash) != 20: raise BTFailure("Invalid state file contents") try: path = os.path.join(self.config['data_dir'], 'metainfo', hashtext) f = file(path, 'rb') data = f.read() f.close() except Exception, e: try: f.close() except: pass self.global_error( "ERROR", "Error reading file %s (%s), \ cannot restore state completely" % (path, str(e))) return None if infohash in self.torrents: raise BTFailure("Invalid state file (duplicate entry)") t = Torrent(infohash) self.torrents[infohash] = t try: t.metainfo = ConvertedMetainfo(bdecode(data)) except Exception, e: self.global_error( "ERROR", "Corrupt data in " + path + " , cannot restore torrent (" + str(e) + ")") return None
def start_new_torrent(self, data): t = Torrent() try: t.metainfo = ConvertedMetainfo(bdecode(data)) except Exception, e: self.global_error("ERROR", "This is not a valid torrent file. (%s)" % str(e)) return
def start_new_torrent(self, data): t = Torrent() try: t.metainfo = ConvertedMetainfo(bdecode(data)) except Exception, e: self.global_error( "ERROR", "This is not a valid torrent file. (%s)" % str(e)) return