Source

consoleLog / src / consoleLog / __init__.py

Full commit
# -*- coding: utf-8 -*-
# 
#  __init__.py
#  consoleLog
#  
#  Created by Lars Yencken on 2008-06-12.
#  Copyright 2008-06-12 Lars Yencken. All rights reserved.
# 

__all__ = [
        'consoleLog',
        'io',
        'progressBar',
        'shell',
        'slot',
    ]

#----------------------------------------------------------------------------#

import consoleLog
import progressBar
from progressBar import withProgress
import slot

#----------------------------------------------------------------------------#

# Provide a default logging object 
default = consoleLog.ConsoleLogger()

#----------------------------------------------------------------------------#

def demo():
    import time
    sl = time.sleep
    log = consoleLog.ConsoleLogger()

    log.start('Starting logger demo')
    log.log('Performing some initialisation')
    sl(1.0)

    log.start('Serious processing with substeps')
    log.log('Substep 1')
    sl(1.0)
    log.log('Substep 2')
    sl(1.0)
    log.log('Substep 3 with progress ', newLine=False)
    for i in withProgress(xrange(100)):
        sl(0.1)
    log.start('Substep 4 with slot', nSteps=1)
    log.log('', newLine=False)
    s = slot.Slot() 
    for j in xrange(637):
        time.sleep(0.01)
        if j % 100 == 0:
            s.update(str(j))
    s.finish(str(j))
    log.finish()

    log.finish('Completed ok')

    log.log('Postprocessing step')
    sl(1.0)
    log.finish()

def extended_demo():
    import time
    log = consoleLog.ConsoleLogger()

    @log.with_log("Let's have some eggs")
    def eggs():
        log.log("eggs")
        for i in range(5):
            spam()

    @log.with_log
    def spam():
        time.sleep(0.5)
        log.log("spam")

    with log.level('Level 1'):
        log.log('message at level 1')
        with log.level('Level 2'):
            log.log('message at level 2')
            eggs()
        with log.level("progressiter demo"):
            for i in range(2):
                with log.progressiter(range(5)) as iterator:
                    for i in iterator: time.sleep(0.5)
            with log.progressiter(range(5), "with message") as iterator:
                for i in iterator: time.sleep(0.5)