1818import signal
1919import subprocess
2020
21+ from .. import log
2122from ..util import quote_sh_list
2223
2324# Turn on to enable just printing the commands that would be run,
2425# without actually running them. This can break runners that are expecting
2526# output or if one command depends on another, so it's just for debugging.
26- DEBUG = False
27+ JUST_PRINT = False
2728
2829
2930class _DebugDummyPopen :
@@ -404,12 +405,13 @@ def call(self, cmd):
404405 subprocess and get its return code, rather than
405406 using subprocess directly, to keep accurate debug logs.
406407 '''
407- if DEBUG or self .debug :
408- print (quote_sh_list (cmd ))
408+ quoted = quote_sh_list (cmd )
409409
410- if DEBUG :
410+ if JUST_PRINT :
411+ log .inf (quoted )
411412 return 0
412413
414+ log .dbg (quoted )
413415 return subprocess .call (cmd )
414416
415417 def check_call (self , cmd ):
@@ -419,17 +421,16 @@ def check_call(self, cmd):
419421 subprocess and check that it executed correctly, rather than
420422 using subprocess directly, to keep accurate debug logs.
421423 '''
422- if DEBUG or self .debug :
423- print (quote_sh_list (cmd ))
424+ quoted = quote_sh_list (cmd )
424425
425- if DEBUG :
426+ if JUST_PRINT :
427+ log .inf (quoted )
426428 return
427429
430+ log .dbg (quoted )
428431 try :
429432 subprocess .check_call (cmd )
430433 except subprocess .CalledProcessError :
431- if self .debug :
432- print ('Error running {}' .format (quote_sh_list (cmd )))
433434 raise
434435
435436 def check_output (self , cmd ):
@@ -439,17 +440,16 @@ def check_output(self, cmd):
439440 subprocess and check that it executed correctly, rather than
440441 using subprocess directly, to keep accurate debug logs.
441442 '''
442- if self .debug :
443- print (quote_sh_list (cmd ))
443+ quoted = quote_sh_list (cmd )
444444
445- if DEBUG :
445+ if JUST_PRINT :
446+ log .inf (quoted )
446447 return b''
447448
449+ log .dbg (quoted )
448450 try :
449451 return subprocess .check_output (cmd )
450452 except subprocess .CalledProcessError :
451- if self .debug :
452- print ('Error running {}' .format (quote_sh_list (cmd )))
453453 raise
454454
455455 def popen_ignore_int (self , cmd ):
@@ -459,16 +459,16 @@ def popen_ignore_int(self, cmd):
459459 cflags = 0
460460 preexec = None
461461 system = platform .system ()
462+ quoted = quote_sh_list (cmd )
462463
463464 if system == 'Windows' :
464465 cflags |= subprocess .CREATE_NEW_PROCESS_GROUP
465466 elif system in {'Linux' , 'Darwin' }:
466467 preexec = os .setsid
467468
468- if DEBUG or self .debug :
469- print (quote_sh_list (cmd ))
470-
471- if DEBUG :
469+ if JUST_PRINT :
470+ log .inf (quoted )
472471 return _DebugDummyPopen ()
473472
473+ log .dbg (quoted )
474474 return subprocess .Popen (cmd , creationflags = cflags , preexec_fn = preexec )
0 commit comments