better windows console output

This commit is contained in:
Parthiv20
2017-07-15 17:27:34 +02:00
parent e26a94423f
commit abde68108b
2 changed files with 21 additions and 13 deletions

View File

@ -4,6 +4,8 @@ from bonobo.nodes import CsvReader, CsvWriter, FileReader, FileWriter, Filter, J
from bonobo.strategies import create_strategy from bonobo.strategies import create_strategy
from bonobo.util.objects import get_name from bonobo.util.objects import get_name
__all__ = [] __all__ = []
@ -21,17 +23,17 @@ def register_api_group(*args):
def run(graph, strategy=None, plugins=None, services=None): def run(graph, strategy=None, plugins=None, services=None):
""" """
Main entry point of bonobo. It takes a graph and creates all the necessary plumbery around to execute it. Main entry point of bonobo. It takes a graph and creates all the necessary plumbery around to execute it.
The only necessary argument is a :class:`Graph` instance, containing the logic you actually want to execute. The only necessary argument is a :class:`Graph` instance, containing the logic you actually want to execute.
By default, this graph will be executed using the "threadpool" strategy: each graph node will be wrapped in a By default, this graph will be executed using the "threadpool" strategy: each graph node will be wrapped in a
thread, and executed in a loop until there is no more input to this node. thread, and executed in a loop until there is no more input to this node.
You can provide plugins factory objects in the plugins list, this function will add the necessary plugins for You can provide plugins factory objects in the plugins list, this function will add the necessary plugins for
interactive console execution and jupyter notebook execution if it detects correctly that it runs in this context. interactive console execution and jupyter notebook execution if it detects correctly that it runs in this context.
You'll probably want to provide a services dictionary mapping service names to service instances. You'll probably want to provide a services dictionary mapping service names to service instances.
:param Graph graph: The :class:`Graph` to execute. :param Graph graph: The :class:`Graph` to execute.
:param str strategy: The :class:`bonobo.strategies.base.Strategy` to use. :param str strategy: The :class:`bonobo.strategies.base.Strategy` to use.
:param list plugins: The list of plugins to enhance execution. :param list plugins: The list of plugins to enhance execution.
@ -71,7 +73,7 @@ register_api(create_strategy)
def open_fs(fs_url=None, *args, **kwargs): def open_fs(fs_url=None, *args, **kwargs):
""" """
Wraps :func:`fs.open_fs` function with a few candies. Wraps :func:`fs.open_fs` function with a few candies.
:param str fs_url: A filesystem URL :param str fs_url: A filesystem URL
:param parse_result: A parsed filesystem URL. :param parse_result: A parsed filesystem URL.
:type parse_result: :class:`ParseResult` :type parse_result: :class:`ParseResult`

View File

@ -2,7 +2,9 @@ import io
import sys import sys
from contextlib import redirect_stdout from contextlib import redirect_stdout
from colorama import Style, Fore from colorama import Style, Fore, init
init(wrap=True)
from bonobo import settings from bonobo import settings
from bonobo.plugins import Plugin from bonobo.plugins import Plugin
@ -23,7 +25,6 @@ class IOBuffer():
finally: finally:
previous.close() previous.close()
class ConsoleOutputPlugin(Plugin): class ConsoleOutputPlugin(Plugin):
""" """
Outputs status information to the connected stdout. Can be a TTY, with or without support for colors/cursor Outputs status information to the connected stdout. Can be a TTY, with or without support for colors/cursor
@ -43,11 +44,11 @@ class ConsoleOutputPlugin(Plugin):
self._stdout = sys.stdout self._stdout = sys.stdout
self.stdout = IOBuffer() self.stdout = IOBuffer()
self.redirect_stdout = redirect_stdout(self.stdout) self.redirect_stdout = redirect_stdout(self.stdout if sys.platform != 'win32' else self._stdout)
self.redirect_stdout.__enter__() self.redirect_stdout.__enter__()
def run(self): def run(self):
if self.isatty: if self.isatty and sys.platform != 'win32':
self._write(self.context.parent, rewind=True) self._write(self.context.parent, rewind=True)
else: else:
pass # not a tty pass # not a tty
@ -60,8 +61,13 @@ class ConsoleOutputPlugin(Plugin):
t_cnt = len(context) t_cnt = len(context)
buffered = self.stdout.switch() buffered = self.stdout.switch()
for line in buffered.split('\n')[:-1]:
print(line + CLEAR_EOL, file=sys.stderr) if sys.platform == 'win32':
for line in buffered.split('\n')[:-1]:
print(line, file=sys.stderr)
else:
for line in buffered.split('\n')[:-1]:
print(line + CLEAR_EOL, file=sys.stderr)
for i in context.graph.topologically_sorted_indexes: for i in context.graph.topologically_sorted_indexes:
node = context[i] node = context[i]
@ -76,7 +82,7 @@ class ConsoleOutputPlugin(Plugin):
else: else:
_line = ''.join( _line = ''.join(
( (
' ', Fore.BLACK, '-', ' ', node.name, name_suffix, ' ', node.get_statistics_as_string(), ' ', Style.BRIGHT+Fore.BLACK, '-', ' ', node.name, name_suffix, ' ', node.get_statistics_as_string(),
Style.RESET_ALL, ' ', Style.RESET_ALL, ' ',
) )
) )