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

View File

@ -7,6 +7,14 @@ from .colors import colors
class Output: class Output:
prefixes = dict() prefixes = dict()
colors = colors 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): def color(self, code=None):
if not code: if not code:
@ -27,9 +35,7 @@ class Output:
def __call__(self, line, highlight=True, flush=True): def __call__(self, line, highlight=True, flush=True):
if self.prefix and self.prefix not in self.prefixes: if self.prefix and self.prefix not in self.prefixes:
self.prefixes[self.prefix] = ( self.prefixes[self.prefix] = self.prefix_colors[len(self.prefixes)]
self.colors[len([*self.prefixes.keys()]) - 1]
)
if len(self.prefix) > self.prefix_length: if len(self.prefix) > self.prefix_length:
self.prefix_length = len(self.prefix) self.prefix_length = len(self.prefix)
@ -44,6 +50,7 @@ class Output:
+ prefix_padding + prefix_padding
+ self.prefix + self.prefix
+ ' ' + ' '
+ self.colors['reset']
+ '| ' + '| '
if self.prefix if self.prefix
else '' else ''
@ -88,26 +95,38 @@ class Output:
return line 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): def start(self, action):
self(''.join([ if self.debug is True or 'visit' in str(self.debug):
self.colors['orangebold'], self(''.join([
'⚠ START ', self.colors['orangebold'],
self.colors['reset'], '⚠ START ',
action.colorized(), self.colors['reset'],
])) action.colorized(),
]))
def success(self, action): def success(self, action):
self(''.join([ if self.debug is True or 'visit' in str(self.debug):
self.colors['greenbold'], self(''.join([
'✔ SUCCESS ', self.colors['greenbold'],
self.colors['reset'], '✔ SUCCESS ',
action.colorized(), self.colors['reset'],
])) action.colorized(),
]))
def fail(self, action, exception=None): def fail(self, action, exception=None):
self(''.join([ if self.debug is True or 'visit' in str(self.debug):
self.colors['redbold'], self(''.join([
'✘ FAIL ', self.colors['redbold'],
self.colors['reset'], '✘ FAIL ',
action.colorized(), self.colors['reset'],
])) action.colorized(),
]))

View File

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