Exemplo n.º 1
0
    def _show_warnings(self):
        if self._warnings:
            from itertools import chain
            from accelerator.compat import terminal_size
            max_width = max(34, terminal_size().columns - 6)

            def reflow(line):
                indent = ''
                for c in line:
                    if c.isspace():
                        indent += c
                    else:
                        break
                width = max(max_width - len(indent), 25)
                current = ''
                between = ''
                for word in line[len(indent):].split(' '):
                    if len(current + word) >= width:
                        if len(word) > width / 2 and word.startswith(
                                '"/') and (word.endswith('"')
                                           or word.endswith('",')):
                            for pe in word.split('/'):
                                if len(current + pe) >= width:
                                    if current:
                                        yield indent + current
                                        current = ('/' if between == '/' else
                                                   '') + pe
                                    else:
                                        yield indent + between + pe
                                else:
                                    current += between + pe
                                between = '/'
                        else:
                            if current:
                                yield indent + current
                                current = word
                            else:
                                yield indent + word
                    else:
                        current += between + word
                    between = ' '
                if current:
                    yield indent + current

            warnings = list(
                chain.from_iterable(reflow(w) for w in self._warnings))
            print()
            width = max(len(line) for line in warnings)
            print('\x1b[35m' + ('#' * (width + 6)) + '\x1b[m')
            for line in warnings:
                print('\x1b[35m##\x1b[m', line.ljust(width),
                      '\x1b[35m##\x1b[m')
            print('\x1b[35m' + ('#' * (width + 6)) + '\x1b[m')
            self._warnings = []
Exemplo n.º 2
0
def main(argv, cfg):
    descr = "lists and describes build scripts"
    parser = ArgumentParser(
        prog=argv.pop(0),
        description=descr,
    )
    parser.add_argument('-s',
                        '--short',
                        action='store_true',
                        help='short listing')
    parser.add_argument('-p',
                        '--path',
                        action='store_true',
                        help='show package paths')
    parser.add_argument('match',
                        nargs='*',
                        default=[],
                        help='substring used for matching')
    args = parser.parse_intermixed_args(argv)
    columns = terminal_size().columns

    if not args.match:
        # no args => list everything in short format
        args.match = ['']
        args.short = True

    packages = []
    for package in cfg.method_directories:
        path = dirname(import_module(package).__file__)
        scripts = []
        packages.append((package, path, scripts))
        for item in sorted(
                glob(path + '/build.py') + glob(path + '/build_*.py')):
            name = basename(item[:-3])
            modname = '.'.join((package, name))
            if any(m in modname for m in args.match):
                try:
                    module = import_module(modname)
                except Exception as e:
                    print('%s%s: %s%s' % (colour.RED, item, e, colour.RESET),
                          file=sys.stderr)
                    continue
                scripts.append((name, getattr(module, 'description', '')))

    for package, path, scripts in sorted(packages):
        if scripts:
            if args.path:
                print(path + '/')
            else:
                print(package)
            printdesc(sorted(scripts), columns, full=not args.short)
Exemplo n.º 3
0
def main(argv, cfg):
    prog = argv.pop(0)
    if '--help' in argv or '-h' in argv:
        print('usage: %s [method]' % (prog, ))
        print('gives description and options for method,')
        print('or lists methods with no method specified.')
        return
    methods = call(cfg.url + '/methods')
    columns = terminal_size().columns
    if argv:
        for name in argv:
            if name in methods:
                data = methods[name]
                print('%s.%s:' % (
                    data.package,
                    name,
                ))
                if data.description.text:
                    for line in data.description.text.split('\n'):
                        if line:
                            print(' ', line)
                        else:
                            print()
                    print()
                if cfg.get('interpreters'):
                    print('Runs on <%s> %s' % (
                        data.version,
                        data.description.interpreter,
                    ))
                    print()
                for k in (
                        'datasets',
                        'jobs',
                ):
                    if data.description.get(k):
                        print('%s:' % (k, ))
                        klen = max(len(k) for k in data.description[k])
                        template = '  %%-%ds # %%s' % (klen, )
                        for k, v in data.description[k].items():
                            if v:
                                print(template % (
                                    k,
                                    v[0],
                                ))
                                for cmt in v[1:]:
                                    print(template % (
                                        '',
                                        cmt,
                                    ))
                            else:
                                print(' ', k)
                if data.description.get('options'):
                    print('options:')
                    klen = max(len(k) for k in data.description.options)
                    vlens = [
                        len(v[0]) for v in data.description.options.values()
                        if len(v) > 1
                    ]
                    vlen = max(vlens or [0])
                    firstlen = klen + vlen + 5
                    template = '  %%-%ds = %%s' % (klen, )
                    template_cmt = '%%-%ds  # %%s' % (firstlen, )
                    for k, v in data.description.options.items():
                        first = template % (
                            k,
                            v[0],
                        )
                        if len(v) > 1:
                            afterlen = max(len(cmt)
                                           for cmt in v[1:]) + firstlen + 4
                            if afterlen <= columns:
                                print(template_cmt % (
                                    first,
                                    v[1],
                                ))
                                for cmt in v[2:]:
                                    print(template_cmt % (
                                        '',
                                        cmt,
                                    ))
                            else:
                                for cmt in v[1:]:
                                    print('  #', cmt)
                                print(first)
                        else:
                            print(first)
            else:
                print('Method %r not found' % (name, ))
    else:
        by_package = defaultdict(list)
        for name, data in sorted(methods.items()):
            by_package[data.package].append(name)
        by_package.pop('accelerator.test_methods', None)
        for package, names in sorted(by_package.items()):
            print('%s:' % (package, ))
            items = [(name, methods[name].description.text) for name in names]
            printdesc(items, columns)
Exemplo n.º 4
0
from __future__ import division, print_function

import sys
import locale
from datetime import datetime, time, date
from math import ceil, floor, log10, isinf, isnan

from accelerator.compat import ArgumentParser
from accelerator.compat import terminal_size
from .parser import name2ds, name2job
from accelerator.colourwrapper import colour
from accelerator.error import NoSuchWhateverError
from accelerator.extras import quote

MINMAXWIDTH = 13  # minimum number of characters reserved for min/max values
COLUMNS, LINES = terminal_size()


def colwidth(rows):
    # find max string len per column
    return [max(len(s) for s in col) for col in zip(*rows)]


def printcolwise(data, template, printfunc, minrows=8, indent=4):
    if not data:
        return
    cols = (COLUMNS - indent) // (len(template.format(*printfunc(data[0]))) +
                                  2)
    n = int(ceil(len(data) / cols))
    n = max(n, minrows)
    for r in range(n):