Exemplo n.º 1
0
Arquivo: Caf.py Projeto: azag0/caf
def status(caf, targets: 'TARGET'):
    """
    Print number of initialized, running and finished tasks.

    Usage:
        caf status [TARGET...]
    """
    def colored(stat):
        colors = 'blue green cyan red yellow normal'.split()
        return [colstr(s, color) if s else colstr(s, 'normal')
                for s, color in zip(stat, colors)]

    dirs = []
    if not targets:
        dirs.append((caf.brewery/latest, (caf.brewery/latest).glob('*')))
    targets = [caf.out/t for t in targets] \
        if targets else (caf.out).glob('*')
    for target in targets:
        if not target.is_dir() or str(target).startswith('.'):
            continue
        if target.is_symlink():
            dirs.append((target, [target]))
        else:
            dirs.append((target, target.glob('*')))
    print('number of {} tasks:'
          .format('/'.join(colored('running finished marked error prepared all'.split()))))
    table = Table(align=['<', *6*['>']], sep=[' ', *5*['/']])
    for directory, paths in sorted(dirs):
        stats = []
        locked = []
        for p in paths:
            stats.append(((p/'.lock').is_dir(), (p/'.caf/seal').is_file(),
                          (p/'.caf/mark').is_file(),
                          (p/'.caf/error').is_file(), (p/'.caf/lock').is_file(),
                          (p/'.caf').is_dir()))
            if (p/'.lock').is_dir():
                locked.append(p)
        stats = colored([stat.count(True) for stat in zip(*stats)])
        table.add_row(str(directory) + ':', *stats)
        if directory.parts[1] != 'Brewery':
            for path in locked:
                table.add_row('{} {}'.format(colstr('>>', 'blue'), path), free=True)
    print(table)
Exemplo n.º 2
0
Arquivo: Caf.py Projeto: azag0/caf
 def colored(stat):
     colors = 'blue green cyan red yellow normal'.split()
     return [colstr(s, color) if s else colstr(s, 'normal')
             for s, color in zip(stat, colors)]