@@ -127,24 +127,41 @@ def shprint(command, *args, **kwargs):
127
127
else :
128
128
logger .debug (string + Style .RESET_ALL )
129
129
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 )
143
162
else :
144
- logger .debug ('' .join (['\t ' , line .rstrip ()]))
145
- if logger .level > logging .DEBUG and need_closing_newline :
146
- print ()
147
-
163
+ raise
164
+
148
165
return output
149
166
150
167
# shprint(sh.ls, '-lah')
@@ -2849,7 +2866,7 @@ def apk(self, args):
2849
2866
build = imp .load_source ('build' , join (dist .dist_dir , 'build.py' ))
2850
2867
with current_directory (dist .dist_dir ):
2851
2868
build .parse_args (args )
2852
- shprint (sh .ant , 'debug' )
2869
+ shprint (sh .ant , 'debug' , _tail = 20 , _critical = True )
2853
2870
2854
2871
# AND: This is very crude, needs improving. Also only works
2855
2872
# for debug for now.
0 commit comments