def status(resources, *args, **kwargs):
    """
    Print status report for zero or more resources.
    """
    template = '{:<50}{:>10}'
    client = redis.Redis(decode_responses=True, **kwargs)

    # resource details
    for loop, resource in enumerate(resources):
        # blank between resources
        if loop:
            print()

        # strings needed
        keys = Keys(resource)
        wildcard = keys.key('*')

        # header
        template = '{:<50}{:>10}'
        indicator = client.get(keys.indicator)
        if indicator is None:
            continue
        print(template.format(resource, indicator))
        print(SEPARATOR)

        # body
        numbers = sorted([keys.number(key)
                          for key in client.scan_iter(wildcard)])
        for number in numbers:
            label = client.get(keys.key(number))
            print(template.format(label, number))

    if resources:
        return

    # show a more general status report for all available queues
    resources = find_resources(client)
    if resources:
        dispensers = (Keys.DISPENSER.format(r) for r in resources)
        indicators = (Keys.INDICATOR.format(r) for r in resources)
        combinations = zip(client.mget(dispensers), client.mget(indicators))
        sizes = (int(dispenser) - int(indicator) + 1
                 for dispenser, indicator in combinations)

        # print sorted results
        print(template.format('Resource', 'Queue size'))
        print(SEPARATOR)
        for size, resource in sorted(zip(sizes, resources), reverse=True):
            print(template.format(resource, size))
def status ( resources , * args , ** kwargs ) : template = '{:<50}{:>10}' client = redis . Redis ( decode_responses = True , ** kwargs ) for loop , resource in enumerate ( resources ) : if loop : print ( ) keys = Keys ( resource ) wildcard = keys . key ( '*' ) template = '{:<50}{:>10}' indicator = client . get ( keys . indicator ) if indicator is None : continue print ( template . format ( resource , indicator ) ) print ( SEPARATOR ) numbers = sorted ( [ keys . number ( key ) for key in client . scan_iter ( wildcard ) ] ) for number in numbers : label = client . get ( keys . key ( number ) ) print ( template . format ( label , number ) ) if resources : return resources = find_resources ( client ) if resources : dispensers = ( Keys . DISPENSER . format ( r ) for r in resources ) indicators = ( Keys . INDICATOR . format ( r ) for r in resources ) combinations = zip ( client . mget ( dispensers ) , client . mget ( indicators ) ) sizes = ( int ( dispenser ) - int ( indicator ) + 1 for dispenser , indicator in combinations ) print ( template . format ( 'Resource' , 'Queue size' ) ) print ( SEPARATOR ) for size , resource in sorted ( zip ( sizes , resources ) , reverse = True ) : print ( template . format ( resource , size ) )
Print status report for zero or more resources.