MCPcopy Create free account
hub / github.com/deepdrive/deepdrive / run_command

Function run_command

install.py:19–41  ·  view source on GitHub ↗
(cmd, cwd=None, env=None, throw=True, verbose=False, print_errors=True)

Source from the content-addressed store, hash-verified

17
18
19def run_command(cmd, cwd=None, env=None, throw=True, verbose=False, print_errors=True):
20 def say(*args):
21 if verbose:
22 print(*args)
23
24 say('running command: ' + cmd)
25 if not isinstance(cmd, list):
26 cmd = cmd.split()
27 process = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, cwd=cwd, env=env)
28 result, err = process.communicate()
29 if not isinstance(result, str):
30 result = ''.join(map(chr, result))
31 result = result.strip()
32 say(result)
33 if process.returncode != 0:
34 if not isinstance(err, str):
35 err = ''.join(map(chr, err))
36 err_msg = ' '.join(cmd) + ' finished with error ' + err.strip()
37 if throw:
38 raise RuntimeError(err_msg)
39 elif print_errors:
40 say(err_msg)
41 return result, process.returncode
42
43
44def check_py_version():

Callers 1

mainFunction · 0.70

Calls 1

sayFunction · 0.70

Tested by

no test coverage detected