Пример #1
0
    def getStateAttribs(self):
        """ Return attributes to be written out to the """
        attribs = Archive.getStateAttribs(self)

        # NZBs in isParRecovery mode need the par recovery state written
        if self.isParRecovery:
            attribs['isParRecovery'] = 'True'
            for attrib in ('neededBlocks', 'parPrefix'):
                val = getattr(self, attrib)
                if isinstance(val, int):
                    val = str(val)
                attribs[attrib] = toUnicode(val)
            attribs['parType'] = getParName(self.parType)

        if self.downloadTime:
            attribs['downloadTime'] = str(self.downloadTime)
        if not self.calculatingBytes and self.totalBytes > 0:
            attribs['totalBytes'] = str(self.totalBytes)
        if self.category:
            attribs['category'] = self.category

        return attribs
Пример #2
0
    def getStateAttribs(self):
        """ Return attributes to be written out to the """
        attribs = Archive.getStateAttribs(self)

        # NZBs in isParRecovery mode need the par recovery state written
        if self.isParRecovery:
            attribs['isParRecovery'] = 'True'
            for attrib in ('neededBlocks', 'parPrefix'):
                val = getattr(self, attrib)
                if isinstance(val, int):
                    val = str(val)
                attribs[attrib] = toUnicode(val)
            attribs['parType'] = getParName(self.parType)

        if self.downloadTime:
            attribs['downloadTime'] = str(self.downloadTime)
        if not self.calculatingBytes and self.totalBytes > 0:
            attribs['totalBytes'] = str(self.totalBytes)
        if self.category:
            attribs['category'] = self.category

        return attribs
Пример #3
0
    def getStateAttribs(self):
        """ Return attributes to be written out to the """
        attribs = Archive.getStateAttribs(self)

        # NZBs in isParRecovery mode need the par recovery state written
        if self.isParRecovery:
            attribs["isParRecovery"] = "True"
            for attrib in ("neededBlocks", "parPrefix"):
                val = getattr(self, attrib)
                if isinstance(val, int):
                    val = str(val)
                attribs[attrib] = toUnicode(val)
            attribs["parType"] = getParName(self.parType)

        if self.downloadTime:
            attribs["downloadTime"] = str(self.downloadTime)
        if not self.calculatingBytes and self.totalBytes > 0:
            attribs["totalBytes"] = str(self.totalBytes)
        if self.category:
            attribs["category"] = self.category

        return attribs
Пример #4
0
def smartDequeue(segment, readOnlyQueue=False, verbose=False):
    """ This function is called after downloading the first segment of every nzbFile

    It determines whether or not the segment's parent nzbFile is part of a par archive. If
    it is and is also an 'extra' par file ('extra' pars are pars other than the first
    par. The first par nzbFile should contain only verification data and little or no
    recovery data), this function will determine whether or not the rest of the nzbFile
    segments need to be downloaded (dequeueing them from the NZBSegmentQueue when
    necessary, unless the readOnlyQueue is True) """
    if not segment.isFirstSegment():
        raise FatalError("smartDequeue on number > 1")

    if segment.nzbFile.filename is None:
        # We can't do anything 'smart' without the filename
        return

    identifyPar(segment.nzbFile)

    # NOTE: pars that aren't extra pars will need to use this block of code when we start
    # looking for requeue cases (branches/smartpar-requeue). And don't allow them to fall
    # through to the isSkippedPar block
    # if not segment.nzbFile.isPar:
    if not segment.nzbFile.isPar or not segment.nzbFile.isExtraPar:
        return

    nzb = segment.nzbFile.nzb
    isQueuedRecoveryPar = False
    if (
        nzb.isParRecovery
        and toUnicode(nzb.parPrefix) in toUnicode(segment.nzbFile.subject)
        and nzb.neededBlocks - nzb.queuedBlocks > 0
    ):
        isQueuedRecoveryPar = True
        # readOnlyQueue can be True here.
        nzb.queuedBlocks += getParSize(segment.nzbFile.filename)

    if not isQueuedRecoveryPar and len(segment.nzbFile.nzbSegments) == 1:
        # Nothing to actually dequeue (we just downloaded the only segment). If we're in
        # parRecovery mode, fall through so we print the 'queued' message as if we
        # magically intended this 'queueing' to happen
        return

    size = segment.nzbFile.totalBytes / 1024 / 1024
    parTypeName = getParName(segment.nzbFile.parType)

    if not isQueuedRecoveryPar:
        # Extra par2 -- dequeue the rest of its segments
        dequeueSegments = segment.nzbFile.todoNzbSegments.copy()
        dequeueSegments.remove(segment)

        dequeuedCount = 0
        if not readOnlyQueue:
            dequeued = Hellanzb.queue.dequeueSegments(dequeueSegments)
            dequeuedCount = len(dequeued)

            for dequeuedSegment in dequeued:
                segment.nzbFile.nzb.totalSkippedBytes += dequeuedSegment.bytes

            if dequeuedCount == 0:
                details = "(nothing in the NZBSegmentQueue to dequeue)"
                debug("smartDequeue: Would have skipped %s: %s" % (details, segment.nzbFile.filename))
        else:
            segment.nzbFile.nzb.totalSkippedBytes += segment.nzbFile.totalBytes

        # FIXME: It would be nice to take an account of how many actual bytes we just
        # skipped, for printing out at the end of the download

        # Always print the skipped message if called from segmentsNeedDownload
        # (readOnlyQueue). Don't bother printing it if we didn't actually dequeue anything
        if readOnlyQueue or not dequeuedCount == 0:
            if verbose:
                info("Skipped %s: %s (%iMB)" % (parTypeName, segment.nzbFile.filename, size))
            elif not len(segment.nzbFile.nzb.skippedParFiles):
                info("Skipping pars.. (Skipped %s: %s (%iMB))" % (parTypeName, segment.nzbFile.filename, size))

            # Only consider the nzbFile as skipped when there were actually segments
            # dequeued, or if readOnlyQueue mode
            segment.nzbFile.isSkippedPar = True
            segment.nzbFile.nzb.skippedParFiles.append(segment.nzbFile)
    else:
        info(
            "Queued %s: %s (%iMB, %i %s)"
            % (
                parTypeName,
                segment.nzbFile.filename,
                size,
                getParSize(segment.nzbFile.filename),
                getParRecoveryName(segment.nzbFile.parType),
            )
        )
Пример #5
0
def smartDequeue(segment, readOnlyQueue=False, verbose=False):
    """ This function is called after downloading the first segment of every nzbFile

    It determines whether or not the segment's parent nzbFile is part of a par archive. If
    it is and is also an 'extra' par file ('extra' pars are pars other than the first
    par. The first par nzbFile should contain only verification data and little or no
    recovery data), this function will determine whether or not the rest of the nzbFile
    segments need to be downloaded (dequeueing them from the NZBSegmentQueue when
    necessary, unless the readOnlyQueue is True) """
    if not segment.isFirstSegment():
        raise FatalError('smartDequeue on number > 1')

    if segment.nzbFile.filename is None:
        # We can't do anything 'smart' without the filename
        return

    identifyPar(segment.nzbFile)

    # NOTE: pars that aren't extra pars will need to use this block of code when we start
    # looking for requeue cases (branches/smartpar-requeue). And don't allow them to fall
    # through to the isSkippedPar block
    #if not segment.nzbFile.isPar:
    if not segment.nzbFile.isPar or not segment.nzbFile.isExtraPar:
        return

    nzb = segment.nzbFile.nzb
    isQueuedRecoveryPar = False
    if nzb.isParRecovery and \
            toUnicode(nzb.parPrefix) in toUnicode(segment.nzbFile.subject) and \
            nzb.neededBlocks - nzb.queuedBlocks > 0:
        isQueuedRecoveryPar = True
        # readOnlyQueue can be True here.
        nzb.queuedBlocks += getParSize(segment.nzbFile.filename)

    if not isQueuedRecoveryPar and len(segment.nzbFile.nzbSegments) == 1:
        # Nothing to actually dequeue (we just downloaded the only segment). If we're in
        # parRecovery mode, fall through so we print the 'queued' message as if we
        # magically intended this 'queueing' to happen
        return

    size = segment.nzbFile.totalBytes / 1024 / 1024
    parTypeName = getParName(segment.nzbFile.parType)

    if not isQueuedRecoveryPar:
        # Extra par2 -- dequeue the rest of its segments
        dequeueSegments = segment.nzbFile.todoNzbSegments.copy()
        dequeueSegments.remove(segment)

        dequeuedCount = 0
        if not readOnlyQueue:
            dequeued = Hellanzb.queue.dequeueSegments(dequeueSegments)
            dequeuedCount = len(dequeued)

            for dequeuedSegment in dequeued:
                segment.nzbFile.nzb.totalSkippedBytes += dequeuedSegment.bytes

            if dequeuedCount == 0:
                details = '(nothing in the NZBSegmentQueue to dequeue)'
                debug('smartDequeue: Would have skipped %s: %s' % \
                      (details, segment.nzbFile.filename))
        else:
            segment.nzbFile.nzb.totalSkippedBytes += segment.nzbFile.totalBytes

        # FIXME: It would be nice to take an account of how many actual bytes we just
        # skipped, for printing out at the end of the download

        # Always print the skipped message if called from segmentsNeedDownload
        # (readOnlyQueue). Don't bother printing it if we didn't actually dequeue anything
        if readOnlyQueue or not dequeuedCount == 0:
            if verbose:
                info('Skipped %s: %s (%iMB)' %
                     (parTypeName, segment.nzbFile.filename, size))
            elif not len(segment.nzbFile.nzb.skippedParFiles):
                info('Skipping pars.. (Skipped %s: %s (%iMB))' % \
                     (parTypeName, segment.nzbFile.filename, size))

            # Only consider the nzbFile as skipped when there were actually segments
            # dequeued, or if readOnlyQueue mode
            segment.nzbFile.isSkippedPar = True
            segment.nzbFile.nzb.skippedParFiles.append(segment.nzbFile)
    else:
        info('Queued %s: %s (%iMB, %i %s)' %
             (parTypeName, segment.nzbFile.filename, size,
              getParSize(segment.nzbFile.filename),
              getParRecoveryName(segment.nzbFile.parType)))