示例#1
0
def crcFailedRequeue(segment, encodingMessage):
    """ Requeue a segment that failed the CRC verification for download via the twisted main
    thread """
    restartedDownloader = False
    try:
        if not Hellanzb.downloading:
            # We need to requeue after downloading everything in this NZB. Readd the NZB
            # to the queue, for tryFinishNZB
            debug('crcFailedRequeue: Downloader stopped and we need to attempt requeue: '
                  'restarting downloader')
            beginDownload(segment.nzbFile.nzb)
            restartedDownloader = True

        Hellanzb.queue.requeueMissing(segment.fromServer.factory, segment)
    except PoolsExhausted:
        if restartedDownloader and len(Hellanzb.queue.nzbs) == 1 and \
                segment.nzbFile.nzb in Hellanzb.queue.nzbs:
            # We restarted the downloader for no reason -- stop it
            debug('crcFailedRequeue: Restarted downloader and caught PoolsExhausted: '
                  ' stopping downloader')
            endDownload()

        # All servers failed to get a good copy of this segment
        error(encodingMessage)

        # Acquire the assembly lock to avoid potential clashing with postpone() 
        segment.nzbFile.nzb.assembleLock.acquire()

        if len(segment.failedServerPools) > 1:
            # Use the largest file (by size) downloaded from the servers, and delete the
            # rest
            failedFiles = []
            for serverPoolName in segment.failedServerPools:
                failedFile = segment.getDestination() + '-hellafailed_%s' % serverPoolName
                if not os.path.exists(failedFile):
                    # Failed files won't exist in the case the server reported
                    # the article as missing
                    continue
                failedFiles.append((os.path.getsize(failedFile), failedFile))
            failedFiles.sort()
            useFile = failedFiles.pop()[1]
            for failedFile in failedFiles:
                nuke(failedFile[1])
        else:
            # FIXME: crcFailedRequeue should really never be triggered when there's only
            # one server to fail on
            useFile = segment.getDestination() + '-hellafailed_%s' % segment.failedServerPools[0]
        os.rename(useFile, segment.getDestination())

        segment.nzbFile.nzb.assembleLock.release()

        postDecode(segment)
    else:
        debug('%s from server: %s. requeued to alternate server' % \
              (encodingMessage, segment.fromServer.factory.serverPoolName))
示例#2
0
def crcFailedRequeue(segment, encodingMessage):
    """ Requeue a segment that failed the CRC verification for download via the twisted main
    thread """
    restartedDownloader = False
    try:
        if not Hellanzb.downloading:
            # We need to requeue after downloading everything in this NZB. Readd the NZB
            # to the queue, for tryFinishNZB
            debug('crcFailedRequeue: Downloader stopped and we need to attempt requeue: '
                  'restarting downloader')
            beginDownload(segment.nzbFile.nzb)
            restartedDownloader = True

        Hellanzb.queue.requeueMissing(segment.fromServer.factory, segment)
    except PoolsExhausted:
        if restartedDownloader and len(Hellanzb.queue.nzbs) == 1 and \
                segment.nzbFile.nzb in Hellanzb.queue.nzbs:
            # We restarted the downloader for no reason -- stop it
            debug('crcFailedRequeue: Restarted downloader and caught PoolsExhausted: '
                  ' stopping downloader')
            endDownload()

        # All servers failed to get a good copy of this segment
        error(encodingMessage)

        # Acquire the assembly lock to avoid potential clashing with postpone() 
        segment.nzbFile.nzb.assembleLock.acquire()

        if len(segment.failedServerPools) > 1:
            # Use the largest file (by size) downloaded from the servers, and delete the
            # rest
            failedFiles = []
            for serverPoolName in segment.failedServerPools:
                failedFile = segment.getDestination() + '-hellafailed_%s' % serverPoolName
                if not os.path.exists(failedFile):
                    # Failed files won't exist in the case the server reported
                    # the article as missing
                    continue
                failedFiles.append((os.path.getsize(failedFile), failedFile))
            failedFiles.sort()
            useFile = failedFiles.pop()[1]
            for failedFile in failedFiles:
                nuke(failedFile[1])
        else:
            # FIXME: crcFailedRequeue should really never be triggered when there's only
            # one server to fail on
            useFile = segment.getDestination() + '-hellafailed_%s' % segment.failedServerPools[0]
        os.rename(useFile, segment.getDestination())

        segment.nzbFile.nzb.assembleLock.release()

        postDecode(segment)
    else:
        debug('%s from server: %s. requeued to alternate server' % \
              (encodingMessage, segment.fromServer.factory.serverPoolName))
示例#3
0
    def deactivateClient(self, client, justThisDownloadPool=False):
        """ Deactive the specified client """
        self.activeClients.remove(client)

        # Reset stats if necessary
        if not len(self.activeClients):
            # XXX:
            #self.sessionReadBytes = 0
            self.activated = False

        if justThisDownloadPool:
            # This serverPool is finished but there are segments pending in the
            # queue for other serverPools (not completely done)
            return

        # Completely finished downloading the NZB?
        for nsf in Hellanzb.nsfs:
            if nsf.activated:
                # Not yet
                return

        # No more active factories, finished downloading
        endDownload()
示例#4
0
    def deactivateClient(self, client, justThisDownloadPool = False):
        """ Deactive the specified client """
        self.activeClients.remove(client)
        
        # Reset stats if necessary
        if not len(self.activeClients):
            # XXX:
            #self.sessionReadBytes = 0
            self.activated = False

        if justThisDownloadPool:
            # This serverPool is finished but there are segments pending in the
            # queue for other serverPools (not completely done)
            return

        # Completely finished downloading the NZB?
        for nsf in Hellanzb.nsfs:
            if nsf.activated:
                # Not yet
                return

        # No more active factories, finished downloading
        endDownload()
示例#5
0
    def deactivateClient(self, client, justThisDownloadPool = False):
        """ Deactive the specified client """
        self.activeClients.remove(client)
        
        # Reset stats if necessary
        if not len(self.activeClients):
            # XXX:
            #self.sessionReadBytes = 0
            self.activated = False

        # If we got the justThisDownloadPool, that means this serverPool is done, but
        # there are segments left in the queue for other serverPools (we're not completely
        # done)
        if justThisDownloadPool:
            return

        # Check if we're completely done
        totalActiveClients = 0
        for nsf in Hellanzb.nsfs:
            totalActiveClients += len(nsf.activeClients)
            
        if totalActiveClients == 0:
            endDownload()