コード例 #1
0
ファイル: NZBModel.py プロジェクト: r0mdau/hellanzb
    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()
コード例 #2
0
def handleNZBDone(nzb):
    """ Hand-off from the downloader -- make a dir for the NZB with its contents, then post
    process it in a separate thread"""
    disconnectUnAntiIdleFactories()

    if nzb.downloadStartTime:
        downloadAndDecodeTime = time.time() - nzb.downloadStartTime
        if not nzb.isParRecovery:
            nzb.downloadAndDecodeTime = downloadAndDecodeTime
        else:
            nzb.downloadAndDecodeTime += downloadAndDecodeTime
    
    # Make our new directory, minus the .nzb
    processingDir = os.path.join(Hellanzb.PROCESSING_DIR, nzb.archiveName)
    
    # Move our nzb contents to their new location for post processing
    hellaRename(processingDir)
        
    move(Hellanzb.WORKING_DIR, processingDir)
    nzb.destDir = processingDir
    nzb.archiveDir = processingDir

    nzbFileName = os.path.join(processingDir, os.path.basename(nzb.nzbFileName))
    # We may have downloaded an NZB file of the same name:
    # http://hellanzb.com/trac/hellanzb/ticket/425
    hellaRename(nzbFileName)
    move(nzb.nzbFileName, nzbFileName)
    nzb.nzbFileName = nzbFileName

    os.mkdir(Hellanzb.WORKING_DIR)

    # The list of skipped pars is maintained in the state XML as only the subjects of the
    # nzbFiles. PostProcessor only knows to look at the NZB.skippedParSubjects list,
    # created here
    nzb.skippedParSubjects = nzb.getSkippedParSubjects()

    # Finally unarchive/process the directory in another thread, and continue
    # nzbing
    troll = PostProcessor.PostProcessor(nzb)

    # Give NZBLeecher some time (another reactor loop) to killHistory() & scrollEnd()
    # without any logging interference from PostProcessor
    reactor.callLater(0, troll.start)
    reactor.callLater(0, writeStateXML)
    reactor.callLater(0, scanQueueDir)
コード例 #3
0
ファイル: NZBQueue.py プロジェクト: r0mdau/hellanzb
def findAndLoadPostponedDir(nzb):
    """ Move a postponed working directory for the specified nzb, if one is found, to the
    WORKING_DIR """
    def fixNZBFileName(nzb):
        if os.path.normpath(os.path.dirname(nzb.destDir)) == os.path.normpath(
                Hellanzb.POSTPONED_DIR):
            nzb.destDir = Hellanzb.WORKING_DIR

    nzbfilename = nzb.nzbFileName
    d = os.path.join(Hellanzb.POSTPONED_DIR, archiveName(nzbfilename))
    if os.path.isdir(d):
        try:
            os.rmdir(Hellanzb.WORKING_DIR)
        except OSError:
            files = os.listdir(Hellanzb.WORKING_DIR)[0]
            if len(files):
                name = files[0]
                ext = getFileExtension(name)
                if ext != None:
                    name = name.replace(ext, '')
                move(Hellanzb.WORKING_DIR,
                     os.path.join(Hellanzb.TEMP_DIR, name))

            else:
                debug('ERROR Stray WORKING_DIR!: ' +
                      str(os.listdir(Hellanzb.WORKING_DIR)))
                name = os.path.join(Hellanzb.TEMP_DIR, 'stray_WORKING_DIR')
                hellaRename(name)
                move(Hellanzb.WORKING_DIR, name)

        move(d, Hellanzb.WORKING_DIR)
        Hellanzb.queue.unpostpone(nzb)
        ensureSafePostponedLoad(nzb.nzbFileName)

        info('Loaded postponed directory: ' + archiveName(nzbfilename))

        fixNZBFileName(nzb)
        return True
    else:
        fixNZBFileName(nzb)
        return False
コード例 #4
0
ファイル: Daemon.py プロジェクト: myusuf3/hellanzb
def cancelCurrent():
    """ Cancel the current d/l, remove the nzb. return False if there was nothing to cancel
    """
    if not isActive():
        return True

    canceled = False
    for nzb in Hellanzb.queue.currentNZBs():
        # FIXME: should GC here
        canceled = True
        nzb.cancel()
        os.remove(nzb.nzbFileName)
        info("Canceling download: " + nzb.archiveName)
    Hellanzb.queue.cancel()
    try:
        hellaRename(os.path.join(Hellanzb.TEMP_DIR, "canceled_WORKING_DIR"))
        move(Hellanzb.WORKING_DIR, os.path.join(Hellanzb.TEMP_DIR, "canceled_WORKING_DIR"))
        os.mkdir(Hellanzb.WORKING_DIR)
        rmtree(os.path.join(Hellanzb.TEMP_DIR, "canceled_WORKING_DIR"))
    except Exception, e:
        error("Problem while canceling WORKING_DIR", e)
コード例 #5
0
def cancelCurrent():
    """ Cancel the current d/l, remove the nzb. return False if there was nothing to cancel
    """
    if not isActive():
        return True
    
    canceled = False
    for nzb in Hellanzb.queue.currentNZBs():
        # FIXME: should GC here
        canceled = True
        nzb.cancel()
        os.remove(nzb.nzbFileName)
        info('Canceling download: ' + nzb.archiveName)
    Hellanzb.queue.cancel()
    try:
        hellaRename(os.path.join(Hellanzb.TEMP_DIR, 'canceled_WORKING_DIR'))
        move(Hellanzb.WORKING_DIR, os.path.join(Hellanzb.TEMP_DIR, 'canceled_WORKING_DIR'))
        os.mkdir(Hellanzb.WORKING_DIR)
        rmtree(os.path.join(Hellanzb.TEMP_DIR, 'canceled_WORKING_DIR'))
    except Exception, e:
        error('Problem while canceling WORKING_DIR', e)
コード例 #6
0
ファイル: NZBQueue.py プロジェクト: ShaneMcC/hellanzb
def findAndLoadPostponedDir(nzb):
    """ Move a postponed working directory for the specified nzb, if one is found, to the
    WORKING_DIR """

    def fixNZBFileName(nzb):
        if os.path.normpath(os.path.dirname(nzb.destDir)) == os.path.normpath(Hellanzb.POSTPONED_DIR):
            nzb.destDir = Hellanzb.WORKING_DIR

    nzbfilename = nzb.nzbFileName
    d = os.path.join(Hellanzb.POSTPONED_DIR, archiveName(nzbfilename))
    if os.path.isdir(d):
        try:
            os.rmdir(Hellanzb.WORKING_DIR)
        except OSError:
            files = os.listdir(Hellanzb.WORKING_DIR)[0]
            if len(files):
                name = files[0]
                ext = getFileExtension(name)
                if ext != None:
                    name = name.replace(ext, "")
                move(Hellanzb.WORKING_DIR, os.path.join(Hellanzb.TEMP_DIR, name))

            else:
                debug("ERROR Stray WORKING_DIR!: " + str(os.listdir(Hellanzb.WORKING_DIR)))
                name = os.path.join(Hellanzb.TEMP_DIR, "stray_WORKING_DIR")
                hellaRename(name)
                move(Hellanzb.WORKING_DIR, name)

        move(d, Hellanzb.WORKING_DIR)
        Hellanzb.queue.unpostpone(nzb)
        ensureSafePostponedLoad(nzb.nzbFileName)

        info("Loaded postponed directory: " + archiveName(nzbfilename))

        fixNZBFileName(nzb)
        return True
    else:
        fixNZBFileName(nzb)
        return False
コード例 #7
0
ファイル: NZBModel.py プロジェクト: pjenvey/hellanzb
    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()