1 # stolen from curseforge's packager repo
7 def execute(executable
, *args
, **kwargs
):
8 ret_pipe
= kwargs
.pop('ret_pipe', False)
9 cwd
= kwargs
.pop('cwd', None)
10 input = kwargs
.pop('input', None)
11 input_pipe
= kwargs
.pop('input_pipe', subprocess
.PIPE
)
12 if kwargs
.pop('stderr', False):
13 stderr
= subprocess
.STDOUT
15 stderr
= subprocess
.PIPE
16 _env
= kwargs
.pop('env', None)
18 env
= dict(os
.environ
)
22 process
= subprocess
.Popen(args
=(executable
,) + args
, shell
=False,
23 stdout
=subprocess
.PIPE
, stderr
=stderr
,
24 stdin
=input_pipe
, cwd
=cwd
, env
=env
)
26 process
.stdin
.write(input)
29 if process
.stdin
: # 'None' if input_pipe was set
31 output
= process
.stdout
.read()
33 # sys.stdout.write("(Done)\n")
35 if stderr
== subprocess
.STDOUT
:
36 errors
= output
# not really much we can do here
38 errors
= process
.stderr
.read()
39 if process
.returncode
!= 0:
40 sys
.stdout
.write("ERROR %d with %r: %s\n%s\n"
41 % (process
.returncode
, (executable
,)+args
, output
, errors
))
43 return errors
, process
.returncode
or 1
46 def git(*args
, **kwargs
):
47 return execute('git', '--no-pager', *args
, **kwargs
)