Run a scan as a plain subprocess. Return rc, stdout, stderr.
(
options,
cwd=None,
test_mode=True,
expected_rc=0,
env=None,
retry=True,
)
| 21 | |
| 22 | |
| 23 | def run_scan_plain( |
| 24 | options, |
| 25 | cwd=None, |
| 26 | test_mode=True, |
| 27 | expected_rc=0, |
| 28 | env=None, |
| 29 | retry=True, |
| 30 | ): |
| 31 | """ |
| 32 | Run a scan as a plain subprocess. Return rc, stdout, stderr. |
| 33 | """ |
| 34 | |
| 35 | from commoncode.command import execute |
| 36 | |
| 37 | options = add_windows_extra_timeout(options) |
| 38 | |
| 39 | if test_mode and '--test-mode' not in options: |
| 40 | options.append('--test-mode') |
| 41 | |
| 42 | if not env: |
| 43 | env = dict(os.environ) |
| 44 | |
| 45 | scmd = 'scancode' |
| 46 | scan_cmd = os.path.join(scancode_root_dir, scmd) |
| 47 | rc, stdout, stderr = execute( |
| 48 | cmd_loc=scan_cmd, |
| 49 | args=options, |
| 50 | cwd=cwd, |
| 51 | env=env, |
| 52 | ) |
| 53 | |
| 54 | if retry and rc != expected_rc: |
| 55 | # wait and rerun in verbose mode to get more in the output |
| 56 | time.sleep(1) |
| 57 | if '--verbose' not in options: |
| 58 | options.append('--verbose') |
| 59 | result = rc, stdout, stderr = execute( |
| 60 | cmd_loc=scan_cmd, |
| 61 | args=options, |
| 62 | cwd=cwd, |
| 63 | env=env, |
| 64 | ) |
| 65 | |
| 66 | if rc != expected_rc: |
| 67 | opts = get_opts(options) |
| 68 | error = f''' |
| 69 | Failure to run: |
| 70 | rc: {rc} |
| 71 | scancode {opts} |
| 72 | stdout: |
| 73 | {stdout} |
| 74 | |
| 75 | stderr: |
| 76 | {stderr} |
| 77 | ''' % locals() |
| 78 | assert rc == expected_rc, error |
| 79 | |
| 80 | return rc, stdout, stderr |
no test coverage detected