@@ -105,6 +105,12 @@ def pretty_log_dists(dists, log_func=info):
105
105
for line in infos :
106
106
log_func ('\t ' + line )
107
107
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
+
108
114
def shprint (command , * args , ** kwargs ):
109
115
'''Runs the command (which should be an sh.Command instance), while
110
116
logging the output.'''
@@ -117,21 +123,18 @@ def shprint(command, *args, **kwargs):
117
123
if len (logger .handlers ) > 1 :
118
124
logger .removeHandler (logger .handlers [1 ])
119
125
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 ]))
121
127
except :
122
- columns = 100
128
+ columns = 100
123
129
command_path = str (command ).split ('/' )
124
130
command_string = command_path [- 1 ]
125
131
string = ' ' .join (['running' , command_string ] + list (args ))
126
132
127
133
# If logging is not in DEBUG mode, trim the command if necessary
128
134
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 ))
133
136
else :
134
- logger .debug (string + Style .RESET_ALL )
137
+ logger .debug ('{}{}' . format ( string , Style .RESET_ALL ) )
135
138
136
139
need_closing_newline = False
137
140
try :
@@ -140,7 +143,7 @@ def shprint(command, *args, **kwargs):
140
143
output = command (* args , ** kwargs )
141
144
for line in output :
142
145
if logger .level > logging .DEBUG :
143
- msg = line .replace ('\n ' , ' ' ).rstrip ()
146
+ msg = line .replace ('\n ' , ' ' ). replace ( ' \t ' , ' ' ).rstrip ()
144
147
if msg :
145
148
# if len(msg) > msg_width: msg = msg[:(msg_width - 3)] + '...'
146
149
sys .stdout .write ('{}\r {}{:<{width}.{width}}' .format (Style .RESET_ALL , msg_hdr , msg , width = msg_width ))
0 commit comments