Show More
@@ -974,6 +974,21 b' def _isstdout(f):' | |||
|
974 | 974 | fileno = getattr(f, 'fileno', None) |
|
975 | 975 | return fileno and fileno() == sys.__stdout__.fileno() |
|
976 | 976 | |
|
977 | def shellenviron(environ=None): | |
|
978 | """return environ with optional override, useful for shelling out""" | |
|
979 | def py2shell(val): | |
|
980 | 'convert python object into string that is useful to shell' | |
|
981 | if val is None or val is False: | |
|
982 | return '0' | |
|
983 | if val is True: | |
|
984 | return '1' | |
|
985 | return str(val) | |
|
986 | env = dict(encoding.environ) | |
|
987 | if environ: | |
|
988 | env.update((k, py2shell(v)) for k, v in environ.iteritems()) | |
|
989 | env['HG'] = hgexecutable() | |
|
990 | return env | |
|
991 | ||
|
977 | 992 | def system(cmd, environ=None, cwd=None, onerr=None, errprefix=None, out=None): |
|
978 | 993 | '''enhanced shell command execution. |
|
979 | 994 | run with environment maybe modified, maybe in different dir. |
@@ -983,19 +998,10 b' def system(cmd, environ=None, cwd=None, ' | |||
|
983 | 998 | |
|
984 | 999 | if out is specified, it is assumed to be a file-like object that has a |
|
985 | 1000 | write() method. stdout and stderr will be redirected to out.''' |
|
986 | if environ is None: | |
|
987 | environ = {} | |
|
988 | 1001 | try: |
|
989 | 1002 | stdout.flush() |
|
990 | 1003 | except Exception: |
|
991 | 1004 | pass |
|
992 | def py2shell(val): | |
|
993 | 'convert python object into string that is useful to shell' | |
|
994 | if val is None or val is False: | |
|
995 | return '0' | |
|
996 | if val is True: | |
|
997 | return '1' | |
|
998 | return str(val) | |
|
999 | 1005 | origcmd = cmd |
|
1000 | 1006 | cmd = quotecommand(cmd) |
|
1001 | 1007 | if pycompat.sysplatform == 'plan9' and (sys.version_info[0] == 2 |
@@ -1006,9 +1012,7 b' def system(cmd, environ=None, cwd=None, ' | |||
|
1006 | 1012 | os.chdir(cwd) |
|
1007 | 1013 | rc = os.system(cmd) |
|
1008 | 1014 | else: |
|
1009 |
env = |
|
|
1010 | env.update((k, py2shell(v)) for k, v in environ.iteritems()) | |
|
1011 | env['HG'] = hgexecutable() | |
|
1015 | env = shellenviron(environ) | |
|
1012 | 1016 | if out is None or _isstdout(out): |
|
1013 | 1017 | rc = subprocess.call(cmd, shell=True, close_fds=closefds, |
|
1014 | 1018 | env=env, cwd=cwd) |
General Comments 0
You need to be logged in to leave comments.
Login now