Skip to content

Commit 1a36bc0

Browse files
committed
toolchain log output cosmetic
1 parent 9a036bb commit 1a36bc0

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

pythonforandroid/toolchain.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ def pretty_log_dists(dists, log_func=info):
105105
for line in infos:
106106
log_func('\t' + line)
107107

108+
def shorten_string(string, width):
109+
if len(string) <= width:
110+
return string
111+
visible = width - 20 #expected suffix len
112+
return '{:<{width}}...(and {} more)'.format(string, len(string) - visible, width = visible)
113+
108114
def shprint(command, *args, **kwargs):
109115
'''Runs the command (which should be an sh.Command instance), while
110116
logging the output.'''
@@ -117,21 +123,18 @@ def shprint(command, *args, **kwargs):
117123
if len(logger.handlers) > 1:
118124
logger.removeHandler(logger.handlers[1])
119125
try:
120-
columns = max(25, int(os.popen('stty size', 'r').read().split()[1]))
126+
columns = max(25, int(os.popen('stty size', 'r').read().split()[1]))
121127
except:
122-
columns = 100
128+
columns = 100
123129
command_path = str(command).split('/')
124130
command_string = command_path[-1]
125131
string = ' '.join(['running', command_string] + list(args))
126132

127133
# If logging is not in DEBUG mode, trim the command if necessary
128134
if logger.level > logging.DEBUG:
129-
short_string = string
130-
if len(string) > columns:
131-
short_string = '{}...(and {} more)'.format(string[:(columns - 20)], len(string) - (columns - 20))
132-
logger.info(short_string + Style.RESET_ALL)
135+
logger.info('{}{}'.format(shorten_string(string, columns - 12), Style.RESET_ALL))
133136
else:
134-
logger.debug(string + Style.RESET_ALL)
137+
logger.debug('{}{}'.format(string, Style.RESET_ALL))
135138

136139
need_closing_newline = False
137140
try:
@@ -140,7 +143,7 @@ def shprint(command, *args, **kwargs):
140143
output = command(*args, **kwargs)
141144
for line in output:
142145
if logger.level > logging.DEBUG:
143-
msg = line.replace('\n', ' ').rstrip()
146+
msg = line.replace('\n', ' ').replace('\t', ' ').rstrip()
144147
if msg:
145148
# if len(msg) > msg_width: msg = msg[:(msg_width - 3)] + '...'
146149
sys.stdout.write('{}\r{}{:<{width}.{width}}'.format(Style.RESET_ALL, msg_hdr, msg, width=msg_width))

0 commit comments

Comments
 (0)