Exemple #1
0
def print_timing():
    if _dotiming:
        groups = [sorted(group, key=lambda x: x[0])
                  for _, group
                  in groupby(_timing.items(), lambda x: x[0].split('>')[0])]
        groups.sort(key=lambda x: x[0][1], reverse=True)
        table = Table(align=['<', '<'])
        for group in groups:
            for row in group:
                table.add_row(re.sub(r'\w+>', 4*' ', row[0]),
                              '{:.4f}'.format(row[1]))
        print(table, file=sys.stderr)
Exemple #2
0
Fichier : Caf.py Projet : 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)
Exemple #3
0
Fichier : CLI.py Projet : azag0/caf
 def __format__(self, fmt):
     if not fmt:
         return str(self)
     elif fmt == 'header':
         if self.header:
             return self.header
         else:
             raise ValueError('Invalid format specifier')
     elif fmt == 'usage':
         usage = """\
         Usage:
             <command> COMMAND [ARGS...]
         """.rstrip()
         return dedent(usage)
     elif fmt == 'commands':
         table = Table(align='<', indent='    ', sep='    ')
         for (trigger, *other), command in self.commands.items():
             if not other:
                 table.add_row(trigger, format(command, 'header'))
         return 'Commands:\n{}'.format(table)
     elif fmt == 'short':
         return '{self:usage}\n\n{self:commands}'.format(self=self)
     else:
         raise ValueError('Invalid format specifier')