[misc] minor output tuning.
This commit is contained in:
@ -21,16 +21,22 @@ class ConsoleOutputPlugin(Plugin):
|
|||||||
|
|
||||||
def initialize(self):
|
def initialize(self):
|
||||||
self.prefix = ''
|
self.prefix = ''
|
||||||
|
self.counter = 0
|
||||||
|
self._append_cache = ''
|
||||||
|
|
||||||
def _write(self, graph_context, rewind):
|
def _write(self, graph_context, rewind):
|
||||||
if settings.PROFILE:
|
if settings.PROFILE:
|
||||||
append = (
|
if self.counter % 10 and self._append_cache:
|
||||||
('Memory', '{0:.2f} Mb'.format(memory_usage())),
|
append = self._append_cache
|
||||||
# ('Total time', '{0} s'.format(execution_time(harness))),
|
else:
|
||||||
)
|
self._append_cache = append = (
|
||||||
|
('Memory', '{0:.2f} Mb'.format(memory_usage())),
|
||||||
|
# ('Total time', '{0} s'.format(execution_time(harness))),
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
append = ()
|
append = ()
|
||||||
self.write(graph_context, prefix=self.prefix, append=append, rewind=rewind)
|
self.write(graph_context, prefix=self.prefix, append=append, rewind=rewind)
|
||||||
|
self.counter += 1
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
if sys.stdout.isatty():
|
if sys.stdout.isatty():
|
||||||
@ -81,7 +87,6 @@ class ConsoleOutputPlugin(Plugin):
|
|||||||
print(MOVE_CURSOR_UP(t_cnt + 2))
|
print(MOVE_CURSOR_UP(t_cnt + 2))
|
||||||
|
|
||||||
|
|
||||||
@functools.lru_cache(1)
|
|
||||||
def memory_usage():
|
def memory_usage():
|
||||||
import os, psutil
|
import os, psutil
|
||||||
process = psutil.Process(os.getpid())
|
process = psutil.Process(os.getpid())
|
||||||
|
|||||||
@ -4,6 +4,7 @@ from pprint import pprint as _pprint
|
|||||||
import itertools
|
import itertools
|
||||||
from colorama import Fore, Style
|
from colorama import Fore, Style
|
||||||
|
|
||||||
|
from bonobo import settings
|
||||||
from bonobo.config import Configurable, Option
|
from bonobo.config import Configurable, Option
|
||||||
from bonobo.config.processors import ContextProcessor
|
from bonobo.config.processors import ContextProcessor
|
||||||
from bonobo.structs.bags import Bag
|
from bonobo.structs.bags import Bag
|
||||||
@ -72,8 +73,16 @@ def _count_counter(self, context):
|
|||||||
|
|
||||||
class PrettyPrinter(Configurable):
|
class PrettyPrinter(Configurable):
|
||||||
def call(self, *args, **kwargs):
|
def call(self, *args, **kwargs):
|
||||||
|
formater = self._format_quiet if settings.QUIET else self._format_console
|
||||||
|
|
||||||
for i, (item, value) in enumerate(itertools.chain(enumerate(args), kwargs.items())):
|
for i, (item, value) in enumerate(itertools.chain(enumerate(args), kwargs.items())):
|
||||||
print(' ' if i else '•', item, '=', str(value).strip().replace('\n', '\n' + CLEAR_EOL), CLEAR_EOL)
|
print(formater(i, item, value))
|
||||||
|
|
||||||
|
def _format_quiet(self, i, item, value):
|
||||||
|
return ' '.join(((' ' if i else '-'), str(item), ':', str(value).strip()))
|
||||||
|
|
||||||
|
def _format_console(self, i, item, value):
|
||||||
|
return ' '.join(((' ' if i else '•'), str(item), '=', str(value).strip().replace('\n', '\n' + CLEAR_EOL), CLEAR_EOL))
|
||||||
|
|
||||||
|
|
||||||
pprint = Tee(_pprint)
|
pprint = Tee(_pprint)
|
||||||
|
|||||||
Reference in New Issue
Block a user