py3: replace sys.platform with pycompat.sysplatform (part 2 of 2)
authorPulkit Goyal <7895pulkit@gmail.com>
Mon, 19 Dec 2016 02:26:41 +0530
changeset 35274 e995f00a9e9afda3734e7880df0fc90fd2197a88
parent 35273 16b5df5792a865d0f3b78e43c1f8801884eb9cc8
child 35275 dfb19aed409e9288cab6fc45ee2e4d9e1243b718
push id424
push usergszorc@mozilla.com
push dateThu, 22 Dec 2016 17:34:22 +0000
py3: replace sys.platform with pycompat.sysplatform (part 2 of 2)
hgext/win32mbcs.py
mercurial/posix.py
mercurial/pure/osutil.py
mercurial/util.py
--- a/hgext/win32mbcs.py
+++ b/hgext/win32mbcs.py
@@ -164,17 +164,17 @@ winfuncs = '''os.path.splitunc'''
 problematic_encodings = '''big5 big5-tw csbig5 big5hkscs big5-hkscs
  hkscs cp932 932 ms932 mskanji ms-kanji shift_jis csshiftjis shiftjis
  sjis s_jis shift_jis_2004 shiftjis2004 sjis_2004 sjis2004
  shift_jisx0213 shiftjisx0213 sjisx0213 s_jisx0213 950 cp950 ms950 '''
 
 def extsetup(ui):
     # TODO: decide use of config section for this extension
     if ((not os.path.supports_unicode_filenames) and
-        (sys.platform != 'cygwin')):
+        (pycompat.sysplatform != 'cygwin')):
         ui.warn(_("[win32mbcs] cannot activate on this platform.\n"))
         return
     # determine encoding for filename
     global _encoding
     _encoding = ui.config('win32mbcs', 'encoding', encoding.encoding)
     # fake is only for relevant environment.
     if _encoding.lower() in problematic_encodings.split():
         for f in funcs.split():
--- a/mercurial/posix.py
+++ b/mercurial/posix.py
@@ -75,17 +75,17 @@ def openhardlinks():
 
 def nlinks(name):
     '''return number of hardlinks for the given file'''
     return os.lstat(name).st_nlink
 
 def parsepatchoutput(output_line):
     """parses the output produced by patch and returns the filename"""
     pf = output_line[14:]
-    if os.sys.platform == 'OpenVMS':
+    if pycompat.sysplatform == 'OpenVMS':
         if pf[0] == '`':
             pf = pf[1:-1] # Remove the quotes
     else:
         if pf.startswith("'") and pf.endswith("'") and " " in pf:
             pf = pf[1:-1] # Remove the quotes
     return pf
 
 def sshargs(sshcmd, host, user, port):
@@ -399,17 +399,17 @@ if pycompat.sysplatform == 'cygwin':
     # Similarly, Cygwin's symlink emulation is likely to create
     # problems when Mercurial is used from both Cygwin and native
     # Windows, with other native tools, or on shared volumes
     def checklink(path):
         return False
 
 _needsshellquote = None
 def shellquote(s):
-    if os.sys.platform == 'OpenVMS':
+    if pycompat.sysplatform == 'OpenVMS':
         return '"%s"' % s
     global _needsshellquote
     if _needsshellquote is None:
         _needsshellquote = re.compile(r'[^a-zA-Z0-9._/+-]').search
     if s and not _needsshellquote(s):
         # "s" shouldn't have to be quoted
         return s
     else:
@@ -418,17 +418,17 @@ def shellquote(s):
 def quotecommand(cmd):
     return cmd
 
 def popen(command, mode='r'):
     return os.popen(command, mode)
 
 def testpid(pid):
     '''return False if pid dead, True if running or not sure'''
-    if os.sys.platform == 'OpenVMS':
+    if pycompat.sysplatform == 'OpenVMS':
         return True
     try:
         os.kill(pid, 0)
         return True
     except OSError as inst:
         return inst.errno != errno.ESRCH
 
 def explainexit(code):
--- a/mercurial/pure/osutil.py
+++ b/mercurial/pure/osutil.py
@@ -7,17 +7,16 @@
 
 from __future__ import absolute_import
 
 import ctypes
 import ctypes.util
 import os
 import socket
 import stat as statmod
-import sys
 
 from . import (
     policy,
     pycompat,
 )
 
 modulepolicy = policy.policy
 policynocffi = policy.policynocffi
@@ -65,24 +64,24 @@ def listdirpure(path, stat=False, skip=N
             return []
         if stat:
             result.append((fn, _mode_to_kind(st.st_mode), st))
         else:
             result.append((fn, _mode_to_kind(st.st_mode)))
     return result
 
 ffi = None
-if modulepolicy not in policynocffi and sys.platform == 'darwin':
+if modulepolicy not in policynocffi and pycompat.sysplatform == 'darwin':
     try:
         from _osutil_cffi import ffi, lib
     except ImportError:
         if modulepolicy == 'cffi': # strict cffi import
             raise
 
-if sys.platform == 'darwin' and ffi is not None:
+if pycompat.sysplatform == 'darwin' and ffi is not None:
     listdir_batch_size = 4096
     # tweakable number, only affects performance, which chunks
     # of bytes do we get back from getattrlistbulk
 
     attrkinds = [None] * 20 # we need the max no for enum VXXX, 20 is plenty
 
     attrkinds[lib.VREG] = statmod.S_IFREG
     attrkinds[lib.VDIR] = statmod.S_IFDIR
@@ -160,17 +159,17 @@ else:
     listdir = listdirpure
 
 if pycompat.osname != 'nt':
     posixfile = open
 
     _SCM_RIGHTS = 0x01
     _socklen_t = ctypes.c_uint
 
-    if sys.platform == 'linux2':
+    if pycompat.sysplatform.startswith('linux'):
         # socket.h says "the type should be socklen_t but the definition of
         # the kernel is incompatible with this."
         _cmsg_len_t = ctypes.c_size_t
         _msg_controllen_t = ctypes.c_size_t
         _msg_iovlen_t = ctypes.c_size_t
     else:
         _cmsg_len_t = _socklen_t
         _msg_controllen_t = _socklen_t
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -790,17 +790,17 @@ def tempfilter(s, cmd):
         fp = os.fdopen(infd, 'wb')
         fp.write(s)
         fp.close()
         outfd, outname = tempfile.mkstemp(prefix='hg-filter-out-')
         os.close(outfd)
         cmd = cmd.replace('INFILE', inname)
         cmd = cmd.replace('OUTFILE', outname)
         code = os.system(cmd)
-        if sys.platform == 'OpenVMS' and code & 1:
+        if pycompat.sysplatform == 'OpenVMS' and code & 1:
             code = 0
         if code:
             raise Abort(_("command '%s' failed: %s") %
                         (cmd, explainexit(code)))
         return readfile(outname)
     finally:
         try:
             if inname:
@@ -993,17 +993,17 @@ def system(cmd, environ=None, cwd=None, 
         'convert python object into string that is useful to shell'
         if val is None or val is False:
             return '0'
         if val is True:
             return '1'
         return str(val)
     origcmd = cmd
     cmd = quotecommand(cmd)
-    if sys.platform == 'plan9' and (sys.version_info[0] == 2
+    if pycompat.sysplatform == 'plan9' and (sys.version_info[0] == 2
                                     and sys.version_info[1] < 7):
         # subprocess kludge to work around issues in half-baked Python
         # ports, notably bichued/python:
         if not cwd is None:
             os.chdir(cwd)
         rc = os.system(cmd)
     else:
         env = dict(encoding.environ)
@@ -1015,17 +1015,17 @@ def system(cmd, environ=None, cwd=None, 
         else:
             proc = subprocess.Popen(cmd, shell=True, close_fds=closefds,
                                     env=env, cwd=cwd, stdout=subprocess.PIPE,
                                     stderr=subprocess.STDOUT)
             for line in iter(proc.stdout.readline, ''):
                 out.write(line)
             proc.wait()
             rc = proc.returncode
-        if sys.platform == 'OpenVMS' and rc & 1:
+        if pycompat.sysplatform == 'OpenVMS' and rc & 1:
             rc = 0
     if rc and onerr:
         errmsg = '%s %s' % (os.path.basename(origcmd.split(None, 1)[0]),
                             explainexit(rc)[0])
         if errprefix:
             errmsg = '%s: %s' % (errprefix, errmsg)
         raise onerr(errmsg)
     return rc
@@ -1378,17 +1378,17 @@ def splitpath(path):
     Note that this function does not use os.altsep because this is
     an alternative of simple "xxx.split(os.sep)".
     It is recommended to use os.path.normpath() before using this
     function if need.'''
     return path.split(pycompat.ossep)
 
 def gui():
     '''Are we running in a GUI?'''
-    if sys.platform == 'darwin':
+    if pycompat.sysplatform == 'darwin':
         if 'SSH_CONNECTION' in encoding.environ:
             # handle SSH access to a box where the user is logged in
             return False
         elif getattr(osutil, 'isgui', None):
             # check if a CoreGraphics session is available
             return osutil.isgui()
         else:
             # pure build; use a safe default