Esempio n. 1
0
def format_exception(excinfo,
                     *,
                     prefix="",
                     fg=lightblack,
                     bg=lightblack_bg,
                     summary=True):
    formatted_exception = _format_exception(*excinfo)

    output = []
    stack_length = len(formatted_exception)
    for i, frame in enumerate(formatted_exception):
        _last = i + 1 == stack_length
        if frame.startswith("  "):
            output.append(textwrap.indent("  " + frame.strip(), fg("\u2502 ")))
        else:
            # XXX TODO change this to use valid python package regexp (plus dot).
            g = re.match("([a-zA-Z_.]+): (.*)$",
                         frame.strip(),
                         flags=re.DOTALL)
            if summary or not _last:
                if g is not None:
                    etyp, emsg = g.group(1), g.group(2)
                    output.append(
                        fg(styles.BOTTOM_LEFT if _last else styles.VERT_LEFT) +
                        bg(lightwhite(" " + etyp + " ")) + " " + lightwhite(
                            textwrap.indent(str(emsg), " " *
                                            (len(etyp) + 4)).strip()))
                else:
                    output.append(textwrap.indent(frame.strip(),
                                                  fg("\u2502 ")))

    return textwrap.indent(EOL.join(output), prefix=prefix)
Esempio n. 2
0
    def run(self, *args, **options):
        results = []
        with bonobo.parse_args(options) as options:
            services = self.get_services()
            strategy = self.get_strategy()
            graph_coll = self.get_graph(*args, **options)

            if not isinstance(graph_coll, GeneratorType):
                graph_coll = (graph_coll, )

            for i, graph in enumerate(graph_coll):
                if not isinstance(graph, bonobo.Graph):
                    raise ValueError(
                        "Expected a Graph instance, got {!r}.".format(graph))
                print(
                    term.lightwhite("{}. {}".format(
                        i + 1, graph.name or repr(graph).strip("<>"))))
                result = bonobo.run(graph,
                                    services=services,
                                    strategy=strategy)
                results.append(result)
                for node in result.nodes:
                    print(node.get_statistics_as_string(),
                          node.get_flags_as_string())
                print(term.lightblack(" ... return value: " + str(result)))

        return results
Esempio n. 3
0
    def handle(self, *args, **options):
        _stdout_backup, _stderr_backup = self.stdout, self.stderr

        self.stdout = OutputWrapper(ConsoleOutputPlugin._stdout,
                                    ending=CLEAR_EOL + '\n')
        self.stderr = OutputWrapper(ConsoleOutputPlugin._stderr,
                                    ending=CLEAR_EOL + '\n')
        self.stderr.style_func = lambda x: Fore.LIGHTRED_EX + Back.RED + '!' + Style.RESET_ALL + ' ' + x

        with bonobo.parse_args(options) as options:
            services = self.get_services()
            graph_coll = self.get_graph(*args, **options)

            if not isinstance(graph_coll, GeneratorType):
                graph_coll = (graph_coll, )

            for i, graph in enumerate(graph_coll):
                assert isinstance(graph,
                                  bonobo.Graph), 'Invalid graph provided.'
                print(term.lightwhite('{}. {}'.format(i + 1, graph.name)))
                result = bonobo.run(graph, services=services)
                print(term.lightblack(' ... return value: ' + str(result)))
                print()

        self.stdout, self.stderr = _stdout_backup, _stderr_backup
Esempio n. 4
0
 def run(self, meta):
     if self.interractive:
         os.system(self.cmd)
     else:
         child = Process(self.cmd)
         events = multiprocessing.Queue()
         parent = multiprocessing.Process(name="task", target=child.run, args=(events, True))
         parent.start()
         exit = False
         returncode = None
         while not exit:
             try:
                 msg = events.get(timeout=0.1)
             except Empty:
                 if exit:
                     break
             else:
                 if msg.type == "line":
                     print(term.lightblack("\u2502"), msg.data.decode("utf-8"), end="")
                 elif msg.type == "start":
                     print("$ " + term.lightwhite(self.cmd) + term.black("  # pid=%s" % msg.data["pid"]))
                 elif msg.type == "stop":
                     returncode = msg.data["returncode"]
                     if returncode:
                         print(term.lightblack("\u2514" + term.red(" failed (rc={}). ".format(returncode))))
                     else:
                         print(term.lightblack("\u2514" + term.green(" success. ")))
                     exit = True
         if returncode:
             raise RuntimeError(
                 '"{command}" exited with status {returncode}.'.format(command=self.cmd, returncode=returncode)
             )
     self.set_complete()
Esempio n. 5
0
    def formatException(self, excinfo):
        formatted_exception = format_exception(*excinfo)

        output = []
        stack_length = len(formatted_exception)
        for i, frame in enumerate(formatted_exception):
            if frame.startswith('  '):
                output.append(textwrap.indent('  ' + frame.strip(), lightblack('\u2502 ')))
            else:
                g = re.match('([a-zA-Z.]+): (.*)$', frame.strip(), flags=re.DOTALL)
                if g is not None:
                    etyp, emsg = g.group(1), g.group(2)
                    output.append(
                        lightblack('\u2514' if i + 1 == stack_length else '\u251c') +
                        lightblack_bg(lightwhite(' ' + etyp + ' ')) + ' ' +
                        lightwhite(textwrap.indent(str(emsg), ' ' * (len(etyp) + 4)).strip())
                    )
                else:
                    output.append(textwrap.indent(frame.strip(), lightblack('\u2502 ')))

        return EOL.join(output)
Esempio n. 6
0
    def run(self, *args, **options):
        results = []
        with bonobo.parse_args(options) as options:
            services = self.get_services()
            strategy = self.get_strategy()
            graph_coll = self.get_graph(*args, **options)

            if not isinstance(graph_coll, GeneratorType):
                graph_coll = (graph_coll, )

            for i, graph in enumerate(graph_coll):
                assert isinstance(graph, bonobo.Graph), 'Invalid graph provided.'
                print(term.lightwhite('{}. {}'.format(i + 1, graph.name)))
                result = bonobo.run(graph, services=services, strategy=strategy)
                results.append(result)
                print(term.lightblack(' ... return value: ' + str(result)))
                print()

        return results
Esempio n. 7
0
 def run(self, meta):
     if self.interractive:
         os.system(self.cmd)
     else:
         child = Process(self.cmd)
         events = multiprocessing.Queue()
         parent = multiprocessing.Process(name='task',
                                          target=child.run,
                                          args=(events, True))
         parent.start()
         exit = False
         returncode = None
         while not exit:
             try:
                 msg = events.get(timeout=0.1)
             except Empty:
                 if exit:
                     break
             else:
                 if msg.type == 'line':
                     print(term.lightblack('\u2502'),
                           msg.data.decode('utf-8'),
                           end='')
                 elif msg.type == 'start':
                     print('$ ' + term.lightwhite(self.cmd) +
                           term.black('  # pid=%s' % msg.data['pid']))
                 elif msg.type == 'stop':
                     returncode = msg.data['returncode']
                     if returncode:
                         print(
                             term.lightblack('\u2514' + term.red(
                                 ' failed (rc={}). '.format(returncode))))
                     else:
                         print(
                             term.lightblack('\u2514' +
                                             term.green(' success. ')))
                     exit = True
         if returncode:
             raise RuntimeError(
                 '"{command}" exited with status {returncode}.'.format(
                     command=self.cmd, returncode=returncode))
     self.set_complete()
Esempio n. 8
0
    def run(self, *args, **options):
        results = []
        with bonobo.parse_args(options) as options:
            services = self.get_services()
            strategy = self.get_strategy()
            graph_coll = self.get_graph(*args, **options)

            if not isinstance(graph_coll, GeneratorType):
                graph_coll = (graph_coll,)

            for i, graph in enumerate(graph_coll):
                if not isinstance(graph, bonobo.Graph):
                    raise ValueError('Expected a Graph instance, got {!r}.'.format(graph))
                print(term.lightwhite('{}. {}'.format(i + 1, graph.name)))
                result = bonobo.run(graph, services=services, strategy=strategy)
                results.append(result)
                print(term.lightblack(' ... return value: ' + str(result)))
                print()

        return results