Logo Search packages:      
Sourcecode: hellanzb version File versions  Download package

def Hellanzb::Logging::NZBLeecherTicker::updateLog (   self,
  logNow = False 
)

Log ticker 

Definition at line 257 of file Logging.py.

00257                                        :
        """ Log ticker """
        if Hellanzb.DAEMONIZE or Hellanzb.DISABLE_SCROLLER:
            return
        
        # Delay the actual log work -- so we don't over-log (too much CPU work in the
        # async loop)
        if not logNow:
            self.wait += 1
            if self.wait < self.delay:
                return
            else:
                self.wait = 0

        ACODE = Hellanzb.ACODE
        currentLog = self.currentLog
        if self.currentLog != None:
            # Kill previous lines,
            self.currentLog = '\r\033[%iA' % self.maxCount
        else:
            # unless we have just began logging. and in that case, explicitly log the
            # first message
            self.currentLog = ''
            logNow = True

        # Log information we want to prefix the scroll (so it stays on the screen)
        if len(self.scrollHeaders) > 0:
            scrollHeader = ''
            for message in self.scrollHeaders:
                message = NEWLINE_RE.sub(ACODE.KILL_LINE + '\n', message)
                scrollHeader = '%s%s%s\n' % (scrollHeader, message, ACODE.KILL_LINE)
                
            self.currentLog = '%s%s' % (self.currentLog, scrollHeader)

        # listing sorted via heapq
        heap = self.segments[:]
        sortedSegments = []
        colorCount = self.connectionCounts.copy()
        try:
            while True:
                p, segment, color = heapq.heappop(heap)
                colorCount[color] -= 1
                sortedSegments.append((segment, color))
        except IndexError:
            pass

        lastSegment = None
        i = 0
        for segment, color in sortedSegments:
            i += 1
            if self.maxCount > 9:
                prettyId = str(i).zfill(2)
            else:
                prettyId = str(i)
            
            # Determine when we've just found the real file name, then use that as the
            # show name
            try:
                if segment.nzbFile.showFilenameIsTemp == True and segment.nzbFile.filename != None:
                    segment.nzbFile.showFilename = segment.nzbFile.filename
                    segment.nzbFile.showFilenameIsTemp = False
            except AttributeError, ae:
                from Hellanzb.Log import debug
                debug('ATTRIBUTE ERROR: ' + str(ae) + ' num: ' + str(segment.number) + \
                      ' duh: ' + str(segment.articleData))
                pass

            connectionPrefix = color + '[' + ACODE.RESET + '%s' + \
                                color + ']' + ACODE.RESET
            prefix = connectionPrefix % prettyId
            if lastSegment != None and lastSegment.nzbFile == segment.nzbFile:
                # 57 line width -- approximately 80 - 5 (prefix) - 18 (max suffix)
                self.currentLog = '%s%s %s%s' % (self.currentLog, prefix,
                                                 rtruncate(segment.nzbFile.showFilename,
                                                           length = 57), ACODE.KILL_LINE)
            else:
                self.currentLog = '%s%s %s - %s%2d%%%s%s @ %s%s%.1fKB/s%s' % \
                    (self.currentLog, prefix, rtruncate(segment.nzbFile.showFilename,
                                                        length = 57), ACODE.F_DGREEN,
                     segment.nzbFile.downloadPercentage, ACODE.RESET, ACODE.F_DBLUE,
                     ACODE.RESET, ACODE.F_DRED, segment.nzbFile.speed, ACODE.KILL_LINE)

            self.currentLog = '%s\n\r' % self.currentLog

            lastSegment = segment

        # Fill in empty lines
        for color, fillCount in colorCount.iteritems():
            for count in range(fillCount):
                i += 1
                fill = i
                if self.maxCount > 9:
                    prettyId = str(fill).zfill(2)
                else:
                    prettyId = str(fill)
                connectionPrefix = color + '[' + ACODE.RESET + '%s' + \
                                    color + ']' + ACODE.RESET
                prefix = connectionPrefix % prettyId
                self.currentLog = '%s%s%s\n\r' % (self.currentLog, prefix, ACODE.KILL_LINE)

        paused = ''
        if Hellanzb.downloadPaused:
            paused = '%s [Paused]%s' % (ACODE.F_DCYAN, ACODE.RESET)

        totalSpeed = 0
        for nsf in Hellanzb.nsfs:
            totalSpeed += nsf.sessionSpeed

        if totalSpeed == 0:
            eta = '00:00:00'
        else:
            eta = prettyEta((Hellanzb.queue.totalQueuedBytes / 1024) / totalSpeed)

        prefix = self.connectionPrefix % 'Total'

        self.currentLog = '%s%s%s %.1fKB/s%s, %s%i MB%s queued, ETA: %s%s%s%s%s' % \
            (self.currentLog, prefix, ACODE.F_DRED, totalSpeed, ACODE.RESET,
             ACODE.F_DGREEN, Hellanzb.queue.totalQueuedBytes / 1024 / 1024, ACODE.RESET,
             ACODE.F_YELLOW, eta, ACODE.RESET, paused, ACODE.KILL_LINE)

        if logNow or self.currentLog != currentLog:
            self.logger(self.currentLog)
            self.scrollHeaders = []

def stdinEchoOff():


Generated by  Doxygen 1.6.0   Back to index