Fix prefix and bugfix CLI args landing in Output constructor

This commit is contained in:
jpic 2020-02-15 22:38:07 +01:00
parent f2bad27eb7
commit baf295f145
3 changed files with 45 additions and 25 deletions

View File

@ -101,7 +101,7 @@ class Action:
def output_factory(self, *args, **kwargs):
kwargs.setdefault('regexps', self.regexps)
return Output(*args, **kwargs)
return Output(**kwargs)
async def __call__(self, *args, **kwargs):
self.call_args = args
@ -126,6 +126,7 @@ class Action:
finally:
clean = getattr(self, 'clean', None)
if clean:
self.output.clean(self)
await clean(*args, **kwargs)
return result

View File

@ -7,6 +7,14 @@ from .colors import colors
class Output:
prefixes = dict()
colors = colors
prefix_colors = (
'\x1b[1;36;45m',
'\x1b[1;36;41m',
'\x1b[1;36;40m',
'\x1b[1;37;45m',
'\x1b[1;32m',
'\x1b[1;37;44m',
)
def color(self, code=None):
if not code:
@ -27,9 +35,7 @@ class Output:
def __call__(self, line, highlight=True, flush=True):
if self.prefix and self.prefix not in self.prefixes:
self.prefixes[self.prefix] = (
self.colors[len([*self.prefixes.keys()]) - 1]
)
self.prefixes[self.prefix] = self.prefix_colors[len(self.prefixes)]
if len(self.prefix) > self.prefix_length:
self.prefix_length = len(self.prefix)
@ -44,6 +50,7 @@ class Output:
+ prefix_padding
+ self.prefix
+ ' '
+ self.colors['reset']
+ '| '
if self.prefix
else ''
@ -88,7 +95,17 @@ class Output:
return line
def clean(self, action):
if self.debug is True or 'visit' in str(self.debug):
self(''.join([
self.colors['bluebold'],
'+ CLEAN ',
self.colors['reset'],
action.colorized(),
]))
def start(self, action):
if self.debug is True or 'visit' in str(self.debug):
self(''.join([
self.colors['orangebold'],
'⚠ START ',
@ -97,6 +114,7 @@ class Output:
]))
def success(self, action):
if self.debug is True or 'visit' in str(self.debug):
self(''.join([
self.colors['greenbold'],
'✔ SUCCESS ',
@ -105,6 +123,7 @@ class Output:
]))
def fail(self, action, exception=None):
if self.debug is True or 'visit' in str(self.debug):
self(''.join([
self.colors['redbold'],
'✘ FAIL ',

View File

@ -22,9 +22,9 @@ class PrefixStreamProtocol(asyncio.subprocess.SubprocessStreamProtocol):
super().__init__(*args, **kwargs)
def pipe_data_received(self, fd, data):
if (self.output.debug is True or 'out' in str(self.output.debug)) and fd in (1, 2):
self.output(data, flush=False)
sys.stdout.flush()
if self.output.debug is True or 'out' in str(self.output.debug):
if fd in (1, 2):
self.output(data)
super().pipe_data_received(fd, data)