Fix prefix and bugfix CLI args landing in Output constructor
This commit is contained in:
parent
f2bad27eb7
commit
baf295f145
@ -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
|
||||||
|
|
||||||
|
|||||||
@ -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,7 +95,17 @@ 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):
|
||||||
|
if self.debug is True or 'visit' in str(self.debug):
|
||||||
self(''.join([
|
self(''.join([
|
||||||
self.colors['orangebold'],
|
self.colors['orangebold'],
|
||||||
'⚠ START ',
|
'⚠ START ',
|
||||||
@ -97,6 +114,7 @@ class Output:
|
|||||||
]))
|
]))
|
||||||
|
|
||||||
def success(self, action):
|
def success(self, action):
|
||||||
|
if self.debug is True or 'visit' in str(self.debug):
|
||||||
self(''.join([
|
self(''.join([
|
||||||
self.colors['greenbold'],
|
self.colors['greenbold'],
|
||||||
'✔ SUCCESS ',
|
'✔ SUCCESS ',
|
||||||
@ -105,6 +123,7 @@ class Output:
|
|||||||
]))
|
]))
|
||||||
|
|
||||||
def fail(self, action, exception=None):
|
def fail(self, action, exception=None):
|
||||||
|
if self.debug is True or 'visit' in str(self.debug):
|
||||||
self(''.join([
|
self(''.join([
|
||||||
self.colors['redbold'],
|
self.colors['redbold'],
|
||||||
'✘ FAIL ',
|
'✘ FAIL ',
|
||||||
|
|||||||
@ -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)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user