예제 #1
0
파일: Daemon.py 프로젝트: myusuf3/hellanzb
def forceNZB(nzbfilename, notification="Forcing download"):
    """ Interrupt the current download, if necessary, to start the specified nzb """
    if not validNZB(nzbfilename):
        return

    if not len(Hellanzb.queue.nzbs):
        # No need to actually 'force'
        from Hellanzb.NZBLeecher.NZBModel import NZB

        return parseNZB(NZB(nzbfilename))

    # postpone the current NZB download
    for nzb in Hellanzb.queue.currentNZBs():
        try:
            info("Interrupting: " + nzb.archiveName)
            nzb.postpone()

            # remove what we've forced with from the old queue, if it exists
            nzb = None
            for n in Hellanzb.nzbQueue:
                if os.path.normpath(n.nzbFileName) == os.path.normpath(nzbfilename):
                    nzb = n

            if nzb is None:
                from Hellanzb.NZBLeecher.NZBModel import NZB

                nzb = NZB(nzbfilename)
            else:
                Hellanzb.nzbQueue.remove(nzb)

            # Copy the specified NZB, unless it's already in the queue dir (move it
            # instead)
            if os.path.normpath(os.path.dirname(nzbfilename)) != os.path.normpath(Hellanzb.QUEUE_DIR):
                copy(nzbfilename, os.path.join(Hellanzb.CURRENT_DIR, os.path.basename(nzbfilename)))
            else:
                move(nzbfilename, os.path.join(Hellanzb.CURRENT_DIR, os.path.basename(nzbfilename)))
            nzbfilename = os.path.join(Hellanzb.CURRENT_DIR, os.path.basename(nzbfilename))
            nzb.nzbFileName = nzbfilename

            # delete everything from the queue. priority will be reset
            Hellanzb.queue.postpone()

            # load the new file
            reactor.callLater(0, parseNZB, nzb, notification)

        except NameError, ne:
            # GC beat us. that should mean there is either a free spot open, or the next
            # nzb in the queue needs to be interrupted????
            debug("forceNZB: NAME ERROR", ne)
            reactor.callLater(0, scanQueueDir)
예제 #2
0
def forceNZB(nzbfilename, notification='Forcing download'):
    """ Interrupt the current download, if necessary, to start the specified nzb """
    if not validNZB(nzbfilename):
        return

    if not len(Hellanzb.queue.nzbs):
        # No need to actually 'force'
        from Hellanzb.NZBLeecher.NZBModel import NZB
        return parseNZB(NZB(nzbfilename))

    # postpone the current NZB download
    for nzb in Hellanzb.queue.currentNZBs():
        try:
            info('Interrupting: ' + nzb.archiveName)
            nzb.postpone()

            # remove what we've forced with from the old queue, if it exists
            nzb = None
            for n in Hellanzb.nzbQueue:
                if os.path.normpath(n.nzbFileName) == os.path.normpath(nzbfilename):
                    nzb = n
                    
            if nzb is None:
                from Hellanzb.NZBLeecher.NZBModel import NZB
                nzb = NZB(nzbfilename)
            else:
                Hellanzb.nzbQueue.remove(nzb)
    
            # Copy the specified NZB, unless it's already in the queue dir (move it
            # instead)
            if os.path.normpath(os.path.dirname(nzbfilename)) != os.path.normpath(Hellanzb.QUEUE_DIR):
                copy(nzbfilename, os.path.join(Hellanzb.CURRENT_DIR, os.path.basename(nzbfilename)))
            else:
                move(nzbfilename, os.path.join(Hellanzb.CURRENT_DIR, os.path.basename(nzbfilename)))
            nzbfilename = os.path.join(Hellanzb.CURRENT_DIR, os.path.basename(nzbfilename))
            nzb.nzbFileName = nzbfilename

            # delete everything from the queue. priority will be reset
            Hellanzb.queue.postpone()

            # load the new file
            reactor.callLater(0, parseNZB, nzb, notification)

        except NameError, ne:
            # GC beat us. that should mean there is either a free spot open, or the next
            # nzb in the queue needs to be interrupted????
            debug('forceNZB: NAME ERROR', ne)
            reactor.callLater(0, scanQueueDir)
예제 #3
0
def enqueueNZBs(nzbFileOrFiles, next=False, writeQueue=True, category=None):
    """ add one or a list of nzb files to the end of the queue """
    if isinstance(nzbFileOrFiles, list) or isinstance(nzbFileOrFiles, tuple):
        newNzbFiles = nzbFileOrFiles
    else:
        newNzbFiles = [nzbFileOrFiles]

    if len(newNzbFiles) == 0:
        return False

    for nzbFile in newNzbFiles:
        if validNZB(nzbFile):
            if os.path.normpath(os.path.dirname(nzbFile)) != os.path.normpath(Hellanzb.QUEUE_DIR):
                copy(nzbFile, os.path.join(Hellanzb.QUEUE_DIR, os.path.basename(nzbFile)))
            nzbFile = os.path.join(Hellanzb.QUEUE_DIR, os.path.basename(nzbFile))

            found = False
            for n in Hellanzb.nzbQueue:
                if os.path.normpath(n.nzbFileName) == os.path.normpath(nzbFile):
                    found = True
                    error("Unable to add nzb file to queue: " + os.path.basename(nzbFile) + " it already exists!")
            if found:
                continue

            from Hellanzb.NZBLeecher.NZBModel import NZB

            name = os.path.basename(nzbFile)
            nzb = NZB.fromStateXML("queued", nzbFile)
            logMsg = msg = "Found new nzb"
            extraLog = []
            if not next:
                Hellanzb.nzbQueue.append(nzb)
            else:
                Hellanzb.nzbQueue.insert(0, nzb)

            if nzb.msgid is not None:
                extraLog.append("msgid: %s" % nzb.msgid)
            if category:
                nzb.category = category
                extraLog.append("category: %s" % category)
            if extraLog:
                logMsg += " (%s)" % ", ".join(extraLog)
            logMsg += ": "
            msg += ": "
            info(logMsg + nzb.archiveName)
            notify("Queue", "hellanzb " + msg, nzb.archiveName, False)

            # Determine the total bytes of the NZB if it's not already
            # known. If there's no NZBs in the queue (we're about to parse the
            # NZB and begin downloading), there's no point in parsing
            # now. Unless it's the first run of scanQueue (not writeQueue),
            # then we FIXME: probably need to scan it
            if nzb.totalBytes == 0 and (len(Hellanzb.queue.currentNZBs()) or not writeQueue):
                from Hellanzb.NZBLeecher.NZBParser import NZBTotalBytesParser

                reactor.callInThread(NZBTotalBytesParser.getBytes, nzb)

        else:
            try:
                shutil.move(nzbFile, Hellanzb.TEMP_DIR + os.sep)
            except (IOError, OSError), e:
                error("Unable to move invalid NZB: %s out of the way" % nzbFile)
                debug("Unable to move invalid NZB: %s out of the way" % nzbFile, e)
예제 #4
0
파일: NZBQueue.py 프로젝트: r0mdau/hellanzb
def enqueueNZBs(nzbFileOrFiles, next=False, writeQueue=True, category=None):
    """ add one or a list of nzb files to the end of the queue """
    if isinstance(nzbFileOrFiles, list) or isinstance(nzbFileOrFiles, tuple):
        newNzbFiles = nzbFileOrFiles
    else:
        newNzbFiles = [nzbFileOrFiles]

    if len(newNzbFiles) == 0:
        return False

    for nzbFile in newNzbFiles:
        if validNZB(nzbFile):
            if os.path.normpath(os.path.dirname(nzbFile)) != os.path.normpath(
                    Hellanzb.QUEUE_DIR):
                copy(
                    nzbFile,
                    os.path.join(Hellanzb.QUEUE_DIR,
                                 os.path.basename(nzbFile)))
            nzbFile = os.path.join(Hellanzb.QUEUE_DIR,
                                   os.path.basename(nzbFile))

            found = False
            for n in Hellanzb.nzbQueue:
                if os.path.normpath(
                        n.nzbFileName) == os.path.normpath(nzbFile):
                    found = True
                    error('Unable to add nzb file to queue: ' + os.path.basename(nzbFile) + \
                          ' it already exists!')
            if found:
                continue

            from Hellanzb.NZBLeecher.NZBModel import NZB
            name = os.path.basename(nzbFile)
            nzb = NZB.fromStateXML('queued', nzbFile)
            logMsg = msg = 'Found new nzb'
            extraLog = []
            if not next:
                Hellanzb.nzbQueue.append(nzb)
            else:
                Hellanzb.nzbQueue.insert(0, nzb)

            if nzb.msgid is not None:
                extraLog.append('msgid: %s' % nzb.msgid)
            if category:
                nzb.category = category
                extraLog.append('category: %s' % category)
            if extraLog:
                logMsg += ' (%s)' % ', '.join(extraLog)
            logMsg += ': '
            msg += ': '
            info(logMsg + nzb.archiveName)
            notify('Queue', 'hellanzb ' + msg, nzb.archiveName, False)

            # Determine the total bytes of the NZB if it's not already
            # known. If there's no NZBs in the queue (we're about to parse the
            # NZB and begin downloading), there's no point in parsing
            # now. Unless it's the first run of scanQueue (not writeQueue),
            # then we FIXME: probably need to scan it
            if nzb.totalBytes == 0 and (len(Hellanzb.queue.currentNZBs()) or \
                    not writeQueue):
                from Hellanzb.NZBLeecher.NZBParser import NZBTotalBytesParser
                reactor.callInThread(NZBTotalBytesParser.getBytes, nzb)

        else:
            try:
                shutil.move(nzbFile, Hellanzb.TEMP_DIR + os.sep)
            except (IOError, OSError), e:
                error('Unable to move invalid NZB: %s out of the way' %
                      nzbFile)
                debug(
                    'Unable to move invalid NZB: %s out of the way' % nzbFile,
                    e)