18
18
import signal
19
19
import subprocess
20
20
21
+ from .. import log
21
22
from ..util import quote_sh_list
22
23
23
24
# Turn on to enable just printing the commands that would be run,
24
25
# without actually running them. This can break runners that are expecting
25
26
# output or if one command depends on another, so it's just for debugging.
26
- DEBUG = False
27
+ JUST_PRINT = False
27
28
28
29
29
30
class _DebugDummyPopen :
@@ -404,12 +405,13 @@ def call(self, cmd):
404
405
subprocess and get its return code, rather than
405
406
using subprocess directly, to keep accurate debug logs.
406
407
'''
407
- if DEBUG or self .debug :
408
- print (quote_sh_list (cmd ))
408
+ quoted = quote_sh_list (cmd )
409
409
410
- if DEBUG :
410
+ if JUST_PRINT :
411
+ log .inf (quoted )
411
412
return 0
412
413
414
+ log .dbg (quoted )
413
415
return subprocess .call (cmd )
414
416
415
417
def check_call (self , cmd ):
@@ -419,17 +421,16 @@ def check_call(self, cmd):
419
421
subprocess and check that it executed correctly, rather than
420
422
using subprocess directly, to keep accurate debug logs.
421
423
'''
422
- if DEBUG or self .debug :
423
- print (quote_sh_list (cmd ))
424
+ quoted = quote_sh_list (cmd )
424
425
425
- if DEBUG :
426
+ if JUST_PRINT :
427
+ log .inf (quoted )
426
428
return
427
429
430
+ log .dbg (quoted )
428
431
try :
429
432
subprocess .check_call (cmd )
430
433
except subprocess .CalledProcessError :
431
- if self .debug :
432
- print ('Error running {}' .format (quote_sh_list (cmd )))
433
434
raise
434
435
435
436
def check_output (self , cmd ):
@@ -439,17 +440,16 @@ def check_output(self, cmd):
439
440
subprocess and check that it executed correctly, rather than
440
441
using subprocess directly, to keep accurate debug logs.
441
442
'''
442
- if self .debug :
443
- print (quote_sh_list (cmd ))
443
+ quoted = quote_sh_list (cmd )
444
444
445
- if DEBUG :
445
+ if JUST_PRINT :
446
+ log .inf (quoted )
446
447
return b''
447
448
449
+ log .dbg (quoted )
448
450
try :
449
451
return subprocess .check_output (cmd )
450
452
except subprocess .CalledProcessError :
451
- if self .debug :
452
- print ('Error running {}' .format (quote_sh_list (cmd )))
453
453
raise
454
454
455
455
def popen_ignore_int (self , cmd ):
@@ -459,16 +459,16 @@ def popen_ignore_int(self, cmd):
459
459
cflags = 0
460
460
preexec = None
461
461
system = platform .system ()
462
+ quoted = quote_sh_list (cmd )
462
463
463
464
if system == 'Windows' :
464
465
cflags |= subprocess .CREATE_NEW_PROCESS_GROUP
465
466
elif system in {'Linux' , 'Darwin' }:
466
467
preexec = os .setsid
467
468
468
- if DEBUG or self .debug :
469
- print (quote_sh_list (cmd ))
470
-
471
- if DEBUG :
469
+ if JUST_PRINT :
470
+ log .inf (quoted )
472
471
return _DebugDummyPopen ()
473
472
473
+ log .dbg (quoted )
474
474
return subprocess .Popen (cmd , creationflags = cflags , preexec_fn = preexec )
0 commit comments