Ejemplo n.º 1
0
def decode(segment):
    """ Decode the NZBSegment's articleData to it's destination. Toggle the NZBSegment
    instance as having been decoded, then assemble all the segments together if all their
    decoded segment filenames exist """
    if Hellanzb.SHUTDOWN:
        return

    encoding = UNKNOWN
    try:
        segment.loadArticleData()
        encoding, encodingMessage = decodeArticleData(segment)
        
    except OutOfDiskSpace:
        # Ran out of disk space and the download was paused! Easiest way out of this
        # sticky situation is to requeue the segment
        nuke(segment.getDestination())
        segment.nzbFile.totalReadBytes -= segment.readBytes
        if not segment.cachedToDisk:
            segment.nzbFile.nzb.cachedArticleDataBytes -= segment.readBytes
        segment.nzbFile.nzb.totalReadBytes -= segment.readBytes
        reactor.callFromThread(segment.fromQueue.put, (segment.priority, segment))
        return
    except Exception, e:
        if handleCanceledSegment(segment):
            # Cancelled NZBs could potentially cause IOErrors during writes -- just handle
            # cleanup and return
            return

        error(segment.nzbFile.showFilename + ' segment: ' + str(segment.number) + \
              ' a problem occurred during decoding', e)
        del segment.articleData
        segment.articleData = ''
        if not segment.cachedToDisk:
            segment.nzbFile.nzb.cachedArticleDataBytes -= segment.readBytes
        touch(segment.getDestination())
Ejemplo n.º 2
0
def decode(segment):
    """ Decode the NZBSegment's articleData to it's destination. Toggle the NZBSegment
    instance as having been decoded, then assemble all the segments together if all their
    decoded segment filenames exist """
    if Hellanzb.SHUTDOWN:
        return

    encoding = UNKNOWN
    try:
        segment.loadArticleData()
        encoding, encodingMessage = decodeArticleData(segment)
        
    except OutOfDiskSpace:
        # Ran out of disk space and the download was paused! Easiest way out of this
        # sticky situation is to requeue the segment
        nuke(segment.getDestination())
        segment.nzbFile.totalReadBytes -= segment.readBytes
        if not segment.cachedToDisk:
            segment.nzbFile.nzb.cachedArticleDataBytes -= segment.readBytes
        segment.nzbFile.nzb.totalReadBytes -= segment.readBytes
        reactor.callFromThread(segment.fromQueue.put, (segment.priority, segment))
        return
    except Exception, e:
        if handleCanceledSegment(segment):
            # Cancelled NZBs could potentially cause IOErrors during writes -- just handle
            # cleanup and return
            return

        error(segment.nzbFile.showFilename + ' segment: ' + str(segment.number) + \
              ' a problem occurred during decoding', e)
        del segment.articleData
        segment.articleData = ''
        if not segment.cachedToDisk:
            segment.nzbFile.nzb.cachedArticleDataBytes -= segment.readBytes
        touch(segment.getDestination())
Ejemplo n.º 3
0
    def testDupeName(self):
        """ Test the dupeName functionality. """ + dupeName.__doc__
        testFile = os.path.join(self.tempDir, 'file')
        testFile0 = os.path.join(self.tempDir, 'file_hellanzb_dupe0')
        testFile1 = os.path.join(self.tempDir, 'file_hellanzb_dupe1')
        testFile2 = os.path.join(self.tempDir, 'file_hellanzb_dupe2')
        
        self.assertEqual(dupeName(testFile), testFile)
        self.assertEqual(dupeName(testFile, eschewNames = (testFile)), testFile0)

        touch(testFile)
        touch(testFile0)

        self.assertEqual(dupeName(testFile), testFile1)
        self.assertEqual(dupeName(testFile, eschewNames = (testFile1)), testFile2)

        # checkOnDisk = False, minIteration = 0 should do nothing
        self.assertEqual(dupeName(testFile, checkOnDisk = False, minIteration = 0),
                         testFile)
Ejemplo n.º 4
0
    def testDupeName(self):
        """ Test the dupeName functionality. """ + dupeName.__doc__
        testFile = os.path.join(self.tempDir, 'file')
        testFile0 = os.path.join(self.tempDir, 'file_hellanzb_dupe0')
        testFile1 = os.path.join(self.tempDir, 'file_hellanzb_dupe1')
        testFile2 = os.path.join(self.tempDir, 'file_hellanzb_dupe2')

        self.assertEqual(dupeName(testFile), testFile)
        self.assertEqual(dupeName(testFile, eschewNames=(testFile)), testFile0)

        touch(testFile)
        touch(testFile0)

        self.assertEqual(dupeName(testFile), testFile1)
        self.assertEqual(dupeName(testFile, eschewNames=(testFile1)),
                         testFile2)

        # checkOnDisk = False, minIteration = 0 should do nothing
        self.assertEqual(dupeName(testFile, checkOnDisk=False, minIteration=0),
                         testFile)
Ejemplo n.º 5
0
            return UUENCODE, None
        
        # Write the decoded segment to disk
        writeLines(segment.getDestination(), decodedLines)

        return UUENCODE, None

    elif segment.articleData == '':
        if Hellanzb.DEBUG_MODE_ENABLED:
            debug('NO articleData, touching file: ' + segment.getDestination())

        handleDupeNZBSegment(segment)
        if handleCanceledSegment(segment):
            return UNKNOWN, None

        touch(segment.getDestination())

    else:
        # FIXME: should this be an info instead of debug? Should probably change the
        # above: articleData == '' check to articleData.strip() == ''. that block would
        # cover all null articleData and would be safer to always info() about
        if Hellanzb.DEBUG_MODE_ENABLED:
            debug('Mysterious data, did not YY/UDecode!! Touching file: ' + \
                  segment.getDestination())

        handleDupeNZBSegment(segment)
        if handleCanceledSegment(segment):
            return UNKNOWN, None

        touch(segment.getDestination())
Ejemplo n.º 6
0
            return UUENCODE, None
        
        # Write the decoded segment to disk
        writeLines(segment.getDestination(), decodedLines)

        return UUENCODE, None

    elif segment.articleData == '':
        if Hellanzb.DEBUG_MODE_ENABLED:
            debug('NO articleData, touching file: ' + segment.getDestination())

        handleDupeNZBSegment(segment)
        if handleCanceledSegment(segment):
            return UNKNOWN, None

        touch(segment.getDestination())

    else:
        # FIXME: should this be an info instead of debug? Should probably change the
        # above: articleData == '' check to articleData.strip() == ''. that block would
        # cover all null articleData and would be safer to always info() about
        if Hellanzb.DEBUG_MODE_ENABLED:
            debug('Mysterious data, did not YY/UDecode!! Touching file: ' + \
                  segment.getDestination())

        handleDupeNZBSegment(segment)
        if handleCanceledSegment(segment):
            return UNKNOWN, None

        touch(segment.getDestination())