##// END OF EJS Templates
py3: replace os.environ with encoding.environ (part 4 of 5)
Pulkit Goyal -
r30637:344e6888 default
parent child Browse files
Show More
@@ -3,6 +3,7 from __future__ import absolute_import
3 import os
3 import os
4
4
5 from . import (
5 from . import (
6 encoding,
6 osutil,
7 osutil,
7 pycompat,
8 pycompat,
8 util,
9 util,
@@ -48,7 +49,7 def userrcpath():
48 home = os.path.expanduser('~')
49 home = os.path.expanduser('~')
49 path = [os.path.join(home, 'mercurial.ini'),
50 path = [os.path.join(home, 'mercurial.ini'),
50 os.path.join(home, '.hgrc')]
51 os.path.join(home, '.hgrc')]
51 userprofile = os.environ.get('USERPROFILE')
52 userprofile = encoding.environ.get('USERPROFILE')
52 if userprofile and userprofile != home:
53 if userprofile and userprofile != home:
53 path.append(os.path.join(userprofile, 'mercurial.ini'))
54 path.append(os.path.join(userprofile, 'mercurial.ini'))
54 path.append(os.path.join(userprofile, '.hgrc'))
55 path.append(os.path.join(userprofile, '.hgrc'))
@@ -117,6 +117,7 import threading
117 import time
117 import time
118
118
119 from . import (
119 from . import (
120 encoding,
120 pycompat,
121 pycompat,
121 )
122 )
122
123
@@ -324,7 +325,7 def stop():
324
325
325 state.accumulate_time(clock())
326 state.accumulate_time(clock())
326 state.last_start_time = None
327 state.last_start_time = None
327 statprofpath = os.environ.get('STATPROF_DEST')
328 statprofpath = encoding.environ.get('STATPROF_DEST')
328 if statprofpath:
329 if statprofpath:
329 save_data(statprofpath)
330 save_data(statprofpath)
330
331
@@ -680,7 +681,7 def display_hotpath(data, fp, limit=0.05
680
681
681 def write_to_flame(data, fp, scriptpath=None, outputfile=None, **kwargs):
682 def write_to_flame(data, fp, scriptpath=None, outputfile=None, **kwargs):
682 if scriptpath is None:
683 if scriptpath is None:
683 scriptpath = os.environ['HOME'] + '/flamegraph.pl'
684 scriptpath = encoding.environ['HOME'] + '/flamegraph.pl'
684 if not os.path.exists(scriptpath):
685 if not os.path.exists(scriptpath):
685 print("error: missing %s" % scriptpath, file=fp)
686 print("error: missing %s" % scriptpath, file=fp)
686 print("get it here: https://github.com/brendangregg/FlameGraph",
687 print("get it here: https://github.com/brendangregg/FlameGraph",
@@ -143,7 +143,7 class ui(object):
143 self.fin = util.stdin
143 self.fin = util.stdin
144
144
145 # shared read-only environment
145 # shared read-only environment
146 self.environ = os.environ
146 self.environ = encoding.environ
147
147
148 self.httppasswordmgrdb = urlreq.httppasswordmgrwithdefaultrealm()
148 self.httppasswordmgrdb = urlreq.httppasswordmgrwithdefaultrealm()
149
149
@@ -948,14 +948,14 def hgexecutable():
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':
@@ -1006,7 +1006,7 def system(cmd, environ=None, cwd=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):
@@ -1384,7 +1384,7 def splitpath(path):
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):
@@ -1394,7 +1394,7 def gui():
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
@@ -2297,7 +2297,7 def hgcmd():
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()
@@ -14,6 +14,8 import os
14 import random
14 import random
15 import subprocess
15 import subprocess
16
16
17 from . import encoding
18
17 _kernel32 = ctypes.windll.kernel32
19 _kernel32 = ctypes.windll.kernel32
18 _advapi32 = ctypes.windll.advapi32
20 _advapi32 = ctypes.windll.advapi32
19 _user32 = ctypes.windll.user32
21 _user32 = ctypes.windll.user32
@@ -424,8 +426,8 def spawndetached(args):
424 pi = _PROCESS_INFORMATION()
426 pi = _PROCESS_INFORMATION()
425
427
426 env = ''
428 env = ''
427 for k in os.environ:
429 for k in encoding.environ:
428 env += "%s=%s\0" % (k, os.environ[k])
430 env += "%s=%s\0" % (k, encoding.environ[k])
429 if not env:
431 if not env:
430 env = '\0'
432 env = '\0'
431 env += '\0'
433 env += '\0'
@@ -433,7 +435,7 def spawndetached(args):
433 args = subprocess.list2cmdline(args)
435 args = subprocess.list2cmdline(args)
434 # Not running the command in shell mode makes Python 2.6 hang when
436 # Not running the command in shell mode makes Python 2.6 hang when
435 # writing to hgweb output socket.
437 # writing to hgweb output socket.
436 comspec = os.environ.get("COMSPEC", "cmd.exe")
438 comspec = encoding.environ.get("COMSPEC", "cmd.exe")
437 args = comspec + " /c " + args
439 args = comspec + " /c " + args
438
440
439 res = _kernel32.CreateProcessA(
441 res = _kernel32.CreateProcessA(
General Comments 0
You need to be logged in to leave comments. Login now