Beispiel #1
0
def beginDownload(nzb=None):
    """ Initialize the download. Notify the downloaders to begin their work, etc """
    # BEGIN
    Hellanzb.loggedIdleMessage = False
    writeStateXML()
    now = time.time()
    if nzb:
        nzb.downloadStartTime = now

    # The scroll level will flood the console with constantly updating
    # statistics -- the logging system can interrupt this scroll
    # temporarily (after scrollBegin)
    scrollBegin()

    # Scan the queue dir intermittently during downloading. Reset the scanner delayed call
    # if it's already going
    if (
        Hellanzb.downloadScannerID is not None
        and not Hellanzb.downloadScannerID.cancelled
        and not Hellanzb.downloadScannerID.called
    ):
        Hellanzb.downloadScannerID.cancel()
    Hellanzb.downloadScannerID = reactor.callLater(5, scanQueueDir, False, True)

    for nsf in Hellanzb.nsfs:
        nsf.beginDownload()

    Hellanzb.downloading = True
Beispiel #2
0
def endDownload():
    """ Finished downloading """
    sessionStartTime = None
    sessionReadBytes = 0
    for nsf in Hellanzb.nsfs:
        sessionReadBytes += nsf.sessionReadBytes
        if nsf.fillServerPriority == 0:
            sessionStartTime = nsf.sessionStartTime
        nsf.endDownload()

    Hellanzb.downloading = False
    Hellanzb.totalSpeed = 0
    Hellanzb.scroller.currentLog = None

    scrollEnd()

    Hellanzb.downloadScannerID.cancel()
    Hellanzb.totalArchivesDownloaded += 1
    writeStateXML()

    if not len(Hellanzb.queue.currentNZBs()):
        # END
        return

    currentNZB = Hellanzb.queue.currentNZBs()[0]
    downloadTime = time.time() - currentNZB.downloadStartTime
    speed = sessionReadBytes / 1024.0 / downloadTime
    info(
        "Transferred %s in %s at %.1fKB/s (%s)"
        % (prettySize(sessionReadBytes), prettyElapsed(downloadTime), speed, currentNZB.archiveName)
    )
    if not currentNZB.isParRecovery:
        currentNZB.downloadTime = downloadTime
    else:
        currentNZB.downloadTime += downloadTime
Beispiel #3
0
def endDownload():
    """ Finished downloading """
    Hellanzb.ht.rate = 0
    sessionStartTime = None
    sessionReadBytes = 0
    for nsf in Hellanzb.nsfs:
        sessionReadBytes += nsf.sessionReadBytes
        if nsf.fillServerPriority == 0:
            sessionStartTime = nsf.sessionStartTime
        nsf.endDownload()

    Hellanzb.downloading = False
    Hellanzb.totalSpeed = 0
    Hellanzb.scroller.currentLog = None

    scrollEnd()

    Hellanzb.downloadScannerID.cancel()
    Hellanzb.totalArchivesDownloaded += 1
    writeStateXML()

    if not len(Hellanzb.queue.currentNZBs()):
        # END
        return

    currentNZB = Hellanzb.queue.currentNZBs()[0]
    downloadTime = time.time() - currentNZB.downloadStartTime
    speed = sessionReadBytes / 1024.0 / downloadTime
    info('Transferred %s in %s at %.1fKB/s (%s)' % \
         (prettySize(sessionReadBytes), prettyElapsed(downloadTime), speed,
          currentNZB.archiveName))
    if not currentNZB.isParRecovery:
        currentNZB.downloadTime = downloadTime
    else:
        currentNZB.downloadTime += downloadTime
Beispiel #4
0
def beginDownload(nzb=None):
    """ Initialize the download. Notify the downloaders to begin their work, etc """
    # BEGIN
    Hellanzb.loggedIdleMessage = False
    writeStateXML()
    now = time.time()
    if nzb:
        nzb.downloadStartTime = now
    
    # The scroll level will flood the console with constantly updating
    # statistics -- the logging system can interrupt this scroll
    # temporarily (after scrollBegin)
    scrollBegin()

    # Scan the queue dir intermittently during downloading. Reset the scanner delayed call
    # if it's already going
    if Hellanzb.downloadScannerID is not None and \
            not Hellanzb.downloadScannerID.cancelled and \
            not Hellanzb.downloadScannerID.called:
        Hellanzb.downloadScannerID.cancel()
    Hellanzb.downloadScannerID = reactor.callLater(5, scanQueueDir, False, True)
    
    for nsf in Hellanzb.nsfs:
        nsf.beginDownload()

    Hellanzb.downloading = True
Beispiel #5
0
    def postpone(self):
        """ Postpone an active NZB """
        assert self in Hellanzb.queue.currentNZBs(), \
            'Attempting to postpone an NZB not actively being downloaded: %s' % self.archiveName
        postponed = os.path.join(Hellanzb.POSTPONED_DIR, self.archiveName)
        hellaRename(postponed)
        os.mkdir(postponed)

        self.assembleLock.acquire()
        try:
            self.destDir = postponed

            move(
                self.nzbFileName,
                os.path.join(Hellanzb.QUEUE_DIR,
                             os.path.basename(self.nzbFileName)))
            self.nzbFileName = os.path.join(Hellanzb.QUEUE_DIR,
                                            os.path.basename(self.nzbFileName))
            Hellanzb.nzbQueue.insert(0, self)
            writeStateXML()

            # Move the postponed files to the new postponed dir
            for file in os.listdir(Hellanzb.WORKING_DIR):
                move(os.path.join(Hellanzb.WORKING_DIR, file),
                     os.path.join(postponed, file))
        finally:
            self.assembleLock.release()
Beispiel #6
0
def setRarPassword(nzbId, rarPassword):
    """ Set the rarPassword on the specified NZB or NZB archive """
    try:
        nzbId = int(nzbId)
    except:
        debug("Invalid ID: " + str(nzbId))
        return False

    # Find the nzbId in the queued list, processing list, or currently downloading nzb
    found = None
    for collection in (Hellanzb.queue.currentNZBs(), Hellanzb.postProcessors, Hellanzb.nzbQueue):
        for nzbOrArchive in collection:
            if nzbOrArchive.id == nzbId:
                found = nzbOrArchive
                break

    if found:
        found.rarPassword = rarPassword
        writeStateXML()
        return True

    return False
Beispiel #7
0
def setRarPassword(nzbId, rarPassword):
    """ Set the rarPassword on the specified NZB or NZB archive """
    try:
        nzbId = int(nzbId)
    except:
        debug('Invalid ID: ' + str(nzbId))
        return False
    
    # Find the nzbId in the queued list, processing list, or currently downloading nzb
    found = None
    for collection in (Hellanzb.queue.currentNZBs(), Hellanzb.postProcessors,
                       Hellanzb.nzbQueue):
        for nzbOrArchive in collection:
            if nzbOrArchive.id == nzbId:
                found = nzbOrArchive
                break

    if found:
        found.rarPassword = rarPassword
        writeStateXML()
        return True
    
    return False
Beispiel #8
0
    def postpone(self):
        """ Postpone an active NZB """
        assert self in Hellanzb.queue.currentNZBs(), (
            "Attempting to postpone an NZB not actively being downloaded: %s" % self.archiveName
        )
        postponed = os.path.join(Hellanzb.POSTPONED_DIR, self.archiveName)
        hellaRename(postponed)
        os.mkdir(postponed)

        self.assembleLock.acquire()
        try:
            self.destDir = postponed

            move(self.nzbFileName, os.path.join(Hellanzb.QUEUE_DIR, os.path.basename(self.nzbFileName)))
            self.nzbFileName = os.path.join(Hellanzb.QUEUE_DIR, os.path.basename(self.nzbFileName))
            Hellanzb.nzbQueue.insert(0, self)
            writeStateXML()

            # Move the postponed files to the new postponed dir
            for file in os.listdir(Hellanzb.WORKING_DIR):
                move(os.path.join(Hellanzb.WORKING_DIR, file), os.path.join(postponed, file))
        finally:
            self.assembleLock.release()
Beispiel #9
0
        debug("ERROR: isActive was True but canceled nothing (no active nzbs!??)")

    for nsf in Hellanzb.nsfs:
        clients = nsf.activeClients.copy()
        for client in clients:
            client.transport.loseConnection()

            # NOTE: WEIRD: after pool-coop branch, I have to force this to prevent
            # fetchNextNZBSegment from re-calling the fetch loop (it gets called
            # twice. the parseNZB->beginDownload->fetchNext call is made before the client
            # gets to call connectionLost). or has this problem always existed??? See r403
            client.isLoggedIn = False

            client.deactivate()

    writeStateXML()
    reactor.callLater(0, scanQueueDir)

    return canceled


def pauseCurrent():
    """ Pause the current download """
    Hellanzb.downloadPaused = True

    for nsf in Hellanzb.nsfs:
        for client in nsf.clients:
            client.transport.stopReading()

    info("Pausing downloader")
    return True
Beispiel #10
0
        debug('ERROR: isActive was True but canceled nothing (no active nzbs!??)')

    for nsf in Hellanzb.nsfs:
        clients = nsf.activeClients.copy()
        for client in clients:
            client.transport.loseConnection()
            
            # NOTE: WEIRD: after pool-coop branch, I have to force this to prevent
            # fetchNextNZBSegment from re-calling the fetch loop (it gets called
            # twice. the parseNZB->beginDownload->fetchNext call is made before the client
            # gets to call connectionLost). or has this problem always existed??? See r403
            client.isLoggedIn = False
            
            client.deactivate()
            
    writeStateXML()
    reactor.callLater(0, scanQueueDir)
    
    return canceled

def pauseCurrent():
    """ Pause the current download """
    Hellanzb.downloadPaused = True

    for nsf in Hellanzb.nsfs:
        for client in nsf.clients:
            client.transport.stopReading()

    info('Pausing downloader')
    return True