Call the given command(s).
(commands, args, cwd=None, verbose=False, hide_stderr=False,
env=None)
| 68 | |
| 69 | |
| 70 | def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, |
| 71 | env=None): |
| 72 | """Call the given command(s).""" |
| 73 | assert isinstance(commands, list) |
| 74 | p = None |
| 75 | for c in commands: |
| 76 | try: |
| 77 | dispcmd = str([c] + args) |
| 78 | # remember shell=False, so use git.cmd on windows, not just git |
| 79 | p = subprocess.Popen([c] + args, cwd=cwd, env=env, |
| 80 | stdout=subprocess.PIPE, |
| 81 | stderr=(subprocess.PIPE if hide_stderr |
| 82 | else None)) |
| 83 | break |
| 84 | except EnvironmentError: |
| 85 | e = sys.exc_info()[1] |
| 86 | if e.errno == errno.ENOENT: |
| 87 | continue |
| 88 | if verbose: |
| 89 | print("unable to run %s" % dispcmd) |
| 90 | print(e) |
| 91 | return None, None |
| 92 | else: |
| 93 | if verbose: |
| 94 | print("unable to find command, tried %s" % (commands,)) |
| 95 | return None, None |
| 96 | stdout = p.communicate()[0].strip() |
| 97 | if sys.version_info[0] >= 3: |
| 98 | stdout = stdout.decode() |
| 99 | if p.returncode != 0: |
| 100 | if verbose: |
| 101 | print("unable to run %s (error)" % dispcmd) |
| 102 | print("stdout was %s" % stdout) |
| 103 | return None, p.returncode |
| 104 | return stdout, p.returncode |
| 105 | |
| 106 | |
| 107 | def versions_from_parentdir(parentdir_prefix, root, verbose): |
no test coverage detected
searching dependent graphs…