Mercurial > hg
comparison mercurial/util.py @ 30637:344e68882cd3
py3: replace os.environ with encoding.environ (part 4 of 5)
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Sun, 18 Dec 2016 02:06:00 +0530 |
parents | bcf4a975f93d |
children | d524c88511a7 |
comparison
equal
deleted
inserted
replaced
30636:f1c9fafcbf46 | 30637:344e68882cd3 |
---|---|
946 """return location of the 'hg' executable. | 946 """return location of the 'hg' executable. |
947 | 947 |
948 Defaults to $HG or 'hg' in the search path. | 948 Defaults to $HG or 'hg' in the search path. |
949 """ | 949 """ |
950 if _hgexecutable is None: | 950 if _hgexecutable is None: |
951 hg = os.environ.get('HG') | 951 hg = encoding.environ.get('HG') |
952 mainmod = sys.modules['__main__'] | 952 mainmod = sys.modules['__main__'] |
953 if hg: | 953 if hg: |
954 _sethgexecutable(hg) | 954 _sethgexecutable(hg) |
955 elif mainfrozen(): | 955 elif mainfrozen(): |
956 if getattr(sys, 'frozen', None) == 'macosx_app': | 956 if getattr(sys, 'frozen', None) == 'macosx_app': |
957 # Env variable set by py2app | 957 # Env variable set by py2app |
958 _sethgexecutable(os.environ['EXECUTABLEPATH']) | 958 _sethgexecutable(encoding.environ['EXECUTABLEPATH']) |
959 else: | 959 else: |
960 _sethgexecutable(sys.executable) | 960 _sethgexecutable(sys.executable) |
961 elif os.path.basename(getattr(mainmod, '__file__', '')) == 'hg': | 961 elif os.path.basename(getattr(mainmod, '__file__', '')) == 'hg': |
962 _sethgexecutable(mainmod.__file__) | 962 _sethgexecutable(mainmod.__file__) |
963 else: | 963 else: |
1004 # ports, notably bichued/python: | 1004 # ports, notably bichued/python: |
1005 if not cwd is None: | 1005 if not cwd is None: |
1006 os.chdir(cwd) | 1006 os.chdir(cwd) |
1007 rc = os.system(cmd) | 1007 rc = os.system(cmd) |
1008 else: | 1008 else: |
1009 env = dict(os.environ) | 1009 env = dict(encoding.environ) |
1010 env.update((k, py2shell(v)) for k, v in environ.iteritems()) | 1010 env.update((k, py2shell(v)) for k, v in environ.iteritems()) |
1011 env['HG'] = hgexecutable() | 1011 env['HG'] = hgexecutable() |
1012 if out is None or _isstdout(out): | 1012 if out is None or _isstdout(out): |
1013 rc = subprocess.call(cmd, shell=True, close_fds=closefds, | 1013 rc = subprocess.call(cmd, shell=True, close_fds=closefds, |
1014 env=env, cwd=cwd) | 1014 env=env, cwd=cwd) |
1382 return path.split(pycompat.ossep) | 1382 return path.split(pycompat.ossep) |
1383 | 1383 |
1384 def gui(): | 1384 def gui(): |
1385 '''Are we running in a GUI?''' | 1385 '''Are we running in a GUI?''' |
1386 if sys.platform == 'darwin': | 1386 if sys.platform == 'darwin': |
1387 if 'SSH_CONNECTION' in os.environ: | 1387 if 'SSH_CONNECTION' in encoding.environ: |
1388 # handle SSH access to a box where the user is logged in | 1388 # handle SSH access to a box where the user is logged in |
1389 return False | 1389 return False |
1390 elif getattr(osutil, 'isgui', None): | 1390 elif getattr(osutil, 'isgui', None): |
1391 # check if a CoreGraphics session is available | 1391 # check if a CoreGraphics session is available |
1392 return osutil.isgui() | 1392 return osutil.isgui() |
1393 else: | 1393 else: |
1394 # pure build; use a safe default | 1394 # pure build; use a safe default |
1395 return True | 1395 return True |
1396 else: | 1396 else: |
1397 return os.name == "nt" or os.environ.get("DISPLAY") | 1397 return os.name == "nt" or encoding.environ.get("DISPLAY") |
1398 | 1398 |
1399 def mktempcopy(name, emptyok=False, createmode=None): | 1399 def mktempcopy(name, emptyok=False, createmode=None): |
1400 """Create a temporary file with the same contents from name | 1400 """Create a temporary file with the same contents from name |
1401 | 1401 |
1402 The permission bits are copied from the original file. | 1402 The permission bits are copied from the original file. |
2295 get either the python call or current executable. | 2295 get either the python call or current executable. |
2296 """ | 2296 """ |
2297 if mainfrozen(): | 2297 if mainfrozen(): |
2298 if getattr(sys, 'frozen', None) == 'macosx_app': | 2298 if getattr(sys, 'frozen', None) == 'macosx_app': |
2299 # Env variable set by py2app | 2299 # Env variable set by py2app |
2300 return [os.environ['EXECUTABLEPATH']] | 2300 return [encoding.environ['EXECUTABLEPATH']] |
2301 else: | 2301 else: |
2302 return [sys.executable] | 2302 return [sys.executable] |
2303 return gethgcmd() | 2303 return gethgcmd() |
2304 | 2304 |
2305 def rundetached(args, condfn): | 2305 def rundetached(args, condfn): |