@@ 70-108 (lines=39) @@ | ||
67 | return decorate |
|
68 | ||
69 | ||
70 | def run_command( |
|
71 | commands, args, cwd=None, verbose=False, hide_stderr=False, env=None |
|
72 | ): |
|
73 | """Call the given command(s).""" |
|
74 | assert isinstance(commands, list) |
|
75 | p = None |
|
76 | for c in commands: |
|
77 | try: |
|
78 | dispcmd = str([c] + args) |
|
79 | # remember shell=False, so use git.cmd on windows, not just git |
|
80 | p = subprocess.Popen( |
|
81 | [c] + args, |
|
82 | cwd=cwd, |
|
83 | env=env, |
|
84 | stdout=subprocess.PIPE, |
|
85 | stderr=(subprocess.PIPE if hide_stderr else None) |
|
86 | ) |
|
87 | break |
|
88 | except EnvironmentError: |
|
89 | e = sys.exc_info()[1] |
|
90 | if e.errno == errno.ENOENT: |
|
91 | continue |
|
92 | if verbose: |
|
93 | print("unable to run %s" % dispcmd) |
|
94 | print(e) |
|
95 | return None, None |
|
96 | else: |
|
97 | if verbose: |
|
98 | print("unable to find command, tried %s" % (commands, )) |
|
99 | return None, None |
|
100 | stdout = p.communicate()[0].strip() |
|
101 | if sys.version_info[0] >= 3: |
|
102 | stdout = stdout.decode() |
|
103 | if p.returncode != 0: |
|
104 | if verbose: |
|
105 | print("unable to run %s (error)" % dispcmd) |
|
106 | print("stdout was %s" % stdout) |
|
107 | return None, p.returncode |
|
108 | return stdout, p.returncode |
|
109 | ||
110 | ||
111 | def versions_from_parentdir(parentdir_prefix, root, verbose): |
@@ 384-418 (lines=35) @@ | ||
381 | return decorate |
|
382 | ||
383 | ||
384 | def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, |
|
385 | env=None): |
|
386 | """Call the given command(s).""" |
|
387 | assert isinstance(commands, list) |
|
388 | p = None |
|
389 | for c in commands: |
|
390 | try: |
|
391 | dispcmd = str([c] + args) |
|
392 | # remember shell=False, so use git.cmd on windows, not just git |
|
393 | p = subprocess.Popen([c] + args, cwd=cwd, env=env, |
|
394 | stdout=subprocess.PIPE, |
|
395 | stderr=(subprocess.PIPE if hide_stderr |
|
396 | else None)) |
|
397 | break |
|
398 | except EnvironmentError: |
|
399 | e = sys.exc_info()[1] |
|
400 | if e.errno == errno.ENOENT: |
|
401 | continue |
|
402 | if verbose: |
|
403 | print("unable to run %s" % dispcmd) |
|
404 | print(e) |
|
405 | return None, None |
|
406 | else: |
|
407 | if verbose: |
|
408 | print("unable to find command, tried %s" % (commands,)) |
|
409 | return None, None |
|
410 | stdout = p.communicate()[0].strip() |
|
411 | if sys.version_info[0] >= 3: |
|
412 | stdout = stdout.decode() |
|
413 | if p.returncode != 0: |
|
414 | if verbose: |
|
415 | print("unable to run %s (error)" % dispcmd) |
|
416 | print("stdout was %s" % stdout) |
|
417 | return None, p.returncode |
|
418 | return stdout, p.returncode |
|
419 | ||
420 | ||
421 | LONG_VERSION_PY['git'] = ''' |