@@ -127,24 +127,41 @@ def shprint(command, *args, **kwargs):
127127 else :
128128 logger .debug (string + Style .RESET_ALL )
129129
130- output = command (* args , ** kwargs )
131- need_closing_newline = False
132- for line in output :
133- if logger .level > logging .DEBUG :
134- string = '' .join ([Style .RESET_ALL , '\r ' , ' ' * 11 , 'working ... ' ,
135- line [:100 ].replace ('\n ' , '' ).rstrip (), ' ...' ])
136- if len (string ) < 20 :
137- continue
138- if len (string ) < 120 :
139- string = string + ' ' * (120 - len (string ))
140- sys .stdout .write (string )
141- sys .stdout .flush ()
142- need_closing_newline = True
130+ try :
131+ output = command (* args , ** kwargs )
132+ need_closing_newline = False
133+ for line in output :
134+ if logger .level > logging .DEBUG :
135+ string = '' .join ([Style .RESET_ALL , '\r ' , ' ' * 11 , 'working ... ' ,
136+ line [:100 ].replace ('\n ' , '' ).rstrip (), ' ...' ])
137+ if len (string ) < 20 :
138+ continue
139+ if len (string ) < 120 :
140+ string = string + ' ' * (120 - len (string ))
141+ sys .stdout .write (string )
142+ sys .stdout .flush ()
143+ need_closing_newline = True
144+ else :
145+ logger .debug ('' .join (['\t ' , line .rstrip ()]))
146+ if logger .level > logging .DEBUG and need_closing_newline :
147+ print ()
148+ except sh .ErrorReturnCode_1 , err :
149+ N = kwargs .get ('_tail' , 0 )
150+ if N :
151+ warning ("Error: {} failed" .format (command ))
152+ lines = err .stdout .splitlines ()
153+ if len (lines ) <= N :
154+ info ('STDOUT:\n {}\t {}{}' .format (Fore .YELLOW , '\t \n ' .join (lines ), Fore .RESET ))
155+ else :
156+ info ('STDOUT (last {} lines of {}):\n {}\t {}{}' .format (N , len (lines ), Fore .YELLOW , '\t \n ' .join (lines [- N :]), Fore .RESET ))
157+ lines = err .stderr .splitlines ()
158+ if len (lines ):
159+ warning ('STDERR:\n {}\t {}{}' .format (Fore .RED , '\t \n ' .join (lines ), Fore .RESET ))
160+ if kwargs .get ('_critical' , False ):
161+ exit (1 )
143162 else :
144- logger .debug ('' .join (['\t ' , line .rstrip ()]))
145- if logger .level > logging .DEBUG and need_closing_newline :
146- print ()
147-
163+ raise
164+
148165 return output
149166
150167# shprint(sh.ls, '-lah')
@@ -2849,7 +2866,7 @@ def apk(self, args):
28492866 build = imp .load_source ('build' , join (dist .dist_dir , 'build.py' ))
28502867 with current_directory (dist .dist_dir ):
28512868 build .parse_args (args )
2852- shprint (sh .ant , 'debug' )
2869+ shprint (sh .ant , 'debug' , _tail = 20 , _critical = True )
28532870
28542871 # AND: This is very crude, needs improving. Also only works
28552872 # for debug for now.
0 commit comments