Exemple #1
0
 def _replaceHttpFetchObj(self, queueId, torrentData):
     failureMsg = None
     info = self.queue.infoGet(queueId)
     
     #save torrent file
     torrentFilePath = self._getTorrentFilePath(queueId)
     try:
         fl = open(torrentFilePath, 'wb')
         with fl:
             fl.write(torrentData)
     except (IOError, OSError):
         failureMsg = 'Failed to save torrent data to "%s"' % (encodeStrForPrinting(torrentFilePath),)
     
     if failureMsg is None:
         #create bt object
         failureMsg, btObj = self._getBtObj(queueId, info['dataPath'])
         
         if failureMsg is None:
             #replace obj
             self.queueJobs[queueId].shutdown()
             self.queueJobs[queueId] = btObj
             
             #remove url from set
             self.queue.setRemove('torrentUrl', info['url'])
             
             #modify info
             del info['url']
             info['type'] = 'bt'
             self.queue.infoSet(queueId, info)
     return failureMsg
Exemple #2
0
 def addTorrentByFile(self, torrentFileData, torrentDataPath):
     with self.lock:
         #get id
         torrentId = self.queue.queueNextId()
         
         #store torrent file in torrent directory
         torrentFilePath = self._getTorrentFilePath(torrentId)
         try:
             fl = open(torrentFilePath, 'wb')
             with fl:
                 fl.write(torrentFileData)
         except (IOError, OSError):
             raise BtQueueManagerException('Failed to save torrent data to "%s"', encodeStrForPrinting(torrentFilePath))
         
         #add to queue
         info = {'type':'bt',
                 'dataPath':torrentDataPath}
         failureMsg = self._addJob(torrentId, info)
         if failureMsg is not None:
             self.log.info("Failed to add torrent, reason: %s", failureMsg)
             raise BtQueueManagerException(failureMsg)
         return torrentId
Exemple #3
0
 def _getTorrentObj(self, torrentId):
     failureMsg = None
     torrent = None
     
     #try to load torrent data from the usual place
     torrentFilePath = self._getTorrentFilePath(torrentId)
     self.log.debug('Torrent %i: trying to read torrent data from "%s"', torrentId, torrentFilePath)
     try:
         fl = open(torrentFilePath, 'rb')
         with fl:
             torrentFileData = fl.read()
     except (IOError, OSError):
         failureMsg = 'Could not read torrent file from "%s"' % encodeStrForPrinting(torrentFilePath)
 
     if failureMsg is None:
         #successfully read the torrent data
         self.log.debug('Torrent %i: trying to parse read torrent data', torrentId)
         torrent = Torrent()
         try:
             torrent.load(torrentFileData)
         except TorrentException, e:
             failureMsg = e.reason
         except:
Exemple #4
0
            fl = open(torrentFilePath, 'rb')
            with fl:
                torrentFileData = fl.read()
        except (IOError, OSError):
            failureMsg = 'Could not read torrent file from "%s"' % encodeStrForPrinting(torrentFilePath)
    
        if failureMsg is None:
            #successfully read the torrent data
            self.log.debug('Torrent %i: trying to parse read torrent data', torrentId)
            torrent = Torrent()
            try:
                torrent.load(torrentFileData)
            except TorrentException, e:
                failureMsg = e.reason
            except:
                failureMsg = 'Failed to parse torrent file "%s"!\nTraceback: %s' % (encodeStrForPrinting(torrentFilePath), encodeStrForPrinting(logTraceback()))
        
        return failureMsg, torrent
    

    def _getBtObj(self, torrentId, torrentDataPath):
        btObj = None
        infoHash = None
        failureMsg, torrent = self._getTorrentObj(torrentId)
        if failureMsg is None:
            #valid torrent data
            infohash = torrent.getTorrentHash()
            if self.queue.setContains('torrentHash', infohash):
                #torrent is already on the queue
                failureMsg = 'Torrent is already queued'
            else: