예제 #1
0
파일: Log.py 프로젝트: r0mdau/hellanzb
def logStateXML(logFunction, showHeader=True):
    """ Print hellanzb's state xml via the specified log function """
    buf = StringIO()
    Hellanzb._writeStateXML(buf)
    header = ''
    if showHeader:
        header = 'hellanzb state xml:\n'
    logFunction('%s%s' % (header, buf.getvalue()))
예제 #2
0
파일: Log.py 프로젝트: myusuf3/hellanzb
def logStateXML(logFunction, showHeader = True):
    """ Print hellanzb's state xml via the specified log function """
    buf = StringIO()
    Hellanzb._writeStateXML(buf)
    header = ''
    if showHeader:
        header = 'hellanzb state xml:\n'
    logFunction('%s%s' % (header, buf.getvalue()))
예제 #3
0
 def getETA(self):
     """ Return the amount of time needed to finish downloadling this NZB at the current rate
     """
     # FIXME: this isn't used anywhere. could be broken
     currentRate = Hellanzb.getCurrentRate()
     if self.totalBytes == 0 or currentRate == 0:
         return 0
     else:
         return int(((self.totalBytes - self.totalReadBytes - self.totalSkippedBytes) / 1024) / currentRate * 1024)
예제 #4
0
파일: NZBModel.py 프로젝트: r0mdau/hellanzb
 def getETA(self):
     """ Return the amount of time needed to finish downloadling this NZB at the current rate
     """
     # FIXME: this isn't used anywhere. could be broken
     currentRate = Hellanzb.getCurrentRate()
     if self.totalBytes == 0 or currentRate == 0:
         return 0
     else:
         return int(((self.totalBytes - self.totalReadBytes - self.totalSkippedBytes) \
                    / 1024) / currentRate * 1024)
예제 #5
0
파일: __init__.py 프로젝트: r0mdau/hellanzb
    def xmlrpc_status(self):
        """ Return hellanzb's current status text """
        from Hellanzb.NZBQueue import listQueue
        s = {}

        totalSpeed = Hellanzb.getCurrentRate()

        s['time'] = DateTime()
        s['uptime'] = secondsToUptime(time.time() - Hellanzb.BEGIN_TIME)
        s['is_paused'] = Hellanzb.downloadPaused
        s['rate'] = totalSpeed
        s['queued_mb'] = Hellanzb.queue.totalQueuedBytes / 1024 / 1024

        if totalSpeed == 0:
            s['eta'] = 0
        else:
            s['eta'] = int(
                (Hellanzb.queue.totalQueuedBytes / 1024) / totalSpeed)

        s['percent_complete'] = 0
        currentNZBs = Hellanzb.queue.currentNZBs()
        if len(currentNZBs):
            currentNZB = currentNZBs[0]
            s['percent_complete'] = currentNZB.getPercentDownloaded()

        if Hellanzb.ht.readLimit == None or Hellanzb.ht.readLimit == 0:
            s['maxrate'] = 0
        else:
            s['maxrate'] = Hellanzb.ht.readLimit / 1024

        s['total_dl_nzbs'] = Hellanzb.totalArchivesDownloaded
        s['total_dl_files'] = Hellanzb.totalFilesDownloaded
        s['total_dl_segments'] = Hellanzb.totalSegmentsDownloaded
        s['total_dl_mb'] = Hellanzb.totalBytesDownloaded / 1024 / 1024
        s['config_file'] = Hellanzb.CONFIG_FILENAME
        s['hostname'] = Hellanzb.HOSTNAME
        s['version'] = Hellanzb.version

        s['currently_downloading'] = [
            self.makeNZBStruct(nzb) for nzb in currentNZBs
        ]

        Hellanzb.postProcessorLock.acquire()
        s['currently_processing'] = [self.makeNZBStruct(processor) for processor in \
                                     Hellanzb.postProcessors]

        Hellanzb.postProcessorLock.release()
        s['queued'] = listQueue()
        s['log_entries'] = [{getLevelName(entry[0]): self.cleanLog(entry[1])} \
                            for entry in Hellanzb.recentLogs]

        return s
예제 #6
0
    def xmlrpc_status(self):
        """ Return hellanzb's current status text """
        from Hellanzb.NZBQueue import listQueue
        s = {}

        if Hellanzb.downloadPaused:
            totalSpeed = 0
        else:
            totalSpeed = Hellanzb.getCurrentRate()

        s['time'] = DateTime()
        s['uptime'] = secondsToUptime(time.time() - Hellanzb.BEGIN_TIME)
        s['is_paused'] = Hellanzb.downloadPaused
        s['rate'] = totalSpeed
        s['queued_mb'] = Hellanzb.queue.totalQueuedBytes / 1024 / 1024
        
        if totalSpeed == 0:
            s['eta'] = 0
        else:
            s['eta'] = int((Hellanzb.queue.totalQueuedBytes / 1024) / totalSpeed)

        s['percent_complete'] = 0
        currentNZBs = Hellanzb.queue.currentNZBs()
        if len(currentNZBs):
            currentNZB = currentNZBs[0]
            s['percent_complete'] = currentNZB.getPercentDownloaded()
            
        if Hellanzb.ht.readLimit == None or Hellanzb.ht.readLimit == 0:
            s['maxrate'] = 0
        else:
            s['maxrate'] = Hellanzb.ht.readLimit / 1024
            
        s['total_dl_nzbs'] = Hellanzb.totalArchivesDownloaded
        s['total_dl_files'] = Hellanzb.totalFilesDownloaded
        s['total_dl_segments'] = Hellanzb.totalSegmentsDownloaded
        s['total_dl_mb'] = Hellanzb.totalBytesDownloaded / 1024 / 1024
        s['config_file'] = Hellanzb.CONFIG_FILENAME
        s['hostname'] = Hellanzb.HOSTNAME
        s['version'] = Hellanzb.version

        s['currently_downloading'] = [self.makeNZBStruct(nzb) for nzb in currentNZBs]

        Hellanzb.postProcessorLock.acquire()
        s['currently_processing'] = [self.makeNZBStruct(processor) for processor in \
                                     Hellanzb.postProcessors]

        Hellanzb.postProcessorLock.release()
        s['queued'] = listQueue()
        s['log_entries'] = [{getLevelName(entry[0]): self.cleanLog(entry[1])} \
                            for entry in Hellanzb.recentLogs]
        
        return s
예제 #7
0
    def stop(self):
        """ Perform any cleanup and remove ourself from the pool before exiting """
        moveBackSamples(self)

        if not self.forcedRecovery:
            cleanUp(self.dirName)

        if not self.isSubDir:
            Hellanzb.postProcessorLock.acquire()
            Hellanzb.postProcessors.remove(self)
            self.archive.postProcessor = None
            Hellanzb.postProcessorLock.release()

            # Write the queue to disk unless we've been stopped by a killed Topen (via
            # CTRL-C)
            if not self.killed and not self.isSubDir and self.background:
                Hellanzb.writeStateXML()

        # When a Post Processor fails, we end up moving the destDir here
        self.moveDestDir()

        # FIXME: This isn't the best place to GC. The best place would be when a download
        # is finished (idle NZBLeecher) but with smartpar, finding an idle NZBLeecher is
        # tricky
        if not self.isSubDir and self.isNZBArchive():
            self.archive.finalize(self.forcedRecovery)
            if not self.forcedRecovery:
                del self.archive
            gc.collect()

            if self.forcedRecovery:
                self.callback()
                return

        if not self.background and not self.isSubDir:
            # We're not running in the background of a downloader -- we're post processing
            # and then immeidately exiting (-Lp)
            from twisted.internet import reactor
            reactor.callFromThread(reactor.stop)
예제 #8
0
    def stop(self):
        """ Perform any cleanup and remove ourself from the pool before exiting """
        moveBackSamples(self)
        
        if not self.forcedRecovery:
            cleanUp(self.dirName)

        if not self.isSubDir:
            Hellanzb.postProcessorLock.acquire()
            Hellanzb.postProcessors.remove(self)
            self.archive.postProcessor = None
            Hellanzb.postProcessorLock.release()

            # Write the queue to disk unless we've been stopped by a killed Topen (via
            # CTRL-C)
            if not self.killed and not self.isSubDir and self.background:
                Hellanzb.writeStateXML()

        # When a Post Processor fails, we end up moving the destDir here
        self.moveDestDir() 

        # FIXME: This isn't the best place to GC. The best place would be when a download
        # is finished (idle NZBLeecher) but with smartpar, finding an idle NZBLeecher is
        # tricky
        if not self.isSubDir and self.isNZBArchive():
            self.archive.finalize(self.forcedRecovery)
            if not self.forcedRecovery:
                del self.archive
            gc.collect()

            if self.forcedRecovery:
                self.callback()
                return
            
        if not self.background and not self.isSubDir:
            # We're not running in the background of a downloader -- we're post processing
            # and then immeidately exiting (-Lp)
            from twisted.internet import reactor
            reactor.callFromThread(reactor.stop)
예제 #9
0
    def run(self):
        """ do the work """
        if not self.isSubDir:
            Hellanzb.postProcessorLock.acquire()
            # FIXME: could block if there are too many processors going
            Hellanzb.postProcessors.append(self)
            Hellanzb.postProcessorLock.release()

            if not self.isSubDir and self.background:
                Hellanzb.writeStateXML()

        try:
            self.postProcess()

        except SystemExit, se:
            # REACTOR STOPPED IF NOT BACKGROUND/SUBIDR
            self.stop()

            if self.isSubDir:
                # Propagate up to the original Post Processor
                raise

            return
예제 #10
0
    def run(self):
        """ do the work """
        if not self.isSubDir:
            Hellanzb.postProcessorLock.acquire()
            # FIXME: could block if there are too many processors going
            Hellanzb.postProcessors.append(self)
            Hellanzb.postProcessorLock.release()

            if not self.isSubDir and self.background:
                Hellanzb.writeStateXML()
        
        try:
            self.postProcess()
            
        except SystemExit, se:
            # REACTOR STOPPED IF NOT BACKGROUND/SUBIDR
            self.stop()
            
            if self.isSubDir:
                # Propagate up to the original Post Processor
                raise

            return