py3: replace sys.platform with pycompat.sysplatform (part 1 of 2)
authorPulkit Goyal <7895pulkit@gmail.com>
Mon, 19 Dec 2016 02:15:24 +0530
changeset 30641 16b5df5792a8
parent 30640 7a3e67bfa417
child 30642 e995f00a9e9a
py3: replace sys.platform with pycompat.sysplatform (part 1 of 2) sys.platform returns unicode on python 3 world. Our code base has most of the things bytes because of the transformer. So we have a bytes version of this as pycompat.sysplatform. This series of 2 patches replaces occurences of sys.platform with pycompat.sysplatform.
mercurial/commands.py
mercurial/posix.py
mercurial/scmposix.py
mercurial/sslutil.py
mercurial/ui.py
--- a/mercurial/commands.py	Mon Dec 19 00:28:12 2016 +0530
+++ b/mercurial/commands.py	Mon Dec 19 02:15:24 2016 +0530
@@ -3890,15 +3890,15 @@
 
     keep = opts.get('system') or []
     if len(keep) == 0:
-        if sys.platform.startswith('win'):
+        if pycompat.sysplatform.startswith('win'):
             keep.append('windows')
-        elif sys.platform == 'OpenVMS':
+        elif pycompat.sysplatform == 'OpenVMS':
             keep.append('vms')
-        elif sys.platform == 'plan9':
+        elif pycompat.sysplatform == 'plan9':
             keep.append('plan9')
         else:
             keep.append('unix')
-            keep.append(sys.platform.lower())
+            keep.append(pycompat.sysplatform.lower())
     if ui.verbose:
         keep.append('verbose')
 
--- a/mercurial/posix.py	Mon Dec 19 00:28:12 2016 +0530
+++ b/mercurial/posix.py	Mon Dec 19 02:15:24 2016 +0530
@@ -303,7 +303,7 @@
 # fallback normcase function for non-ASCII strings
 normcasefallback = normcase
 
-if sys.platform == 'darwin':
+if pycompat.sysplatform == 'darwin':
 
     def normcase(path):
         '''
@@ -354,7 +354,7 @@
         # drop HFS+ ignored characters
         return encoding.hfsignoreclean(enc)
 
-if sys.platform == 'cygwin':
+if pycompat.sysplatform == 'cygwin':
     # workaround for cygwin, in which mount point part of path is
     # treated as case sensitive, even though underlying NTFS is case
     # insensitive.
@@ -447,7 +447,7 @@
     If command is a basename then PATH is searched for command.
     PATH isn't searched if command is an absolute or relative path.
     If command isn't found None is returned.'''
-    if sys.platform == 'OpenVMS':
+    if pycompat.sysplatform == 'OpenVMS':
         return command
 
     def findexisting(executable):
@@ -459,7 +459,7 @@
     if pycompat.ossep in command:
         return findexisting(command)
 
-    if sys.platform == 'plan9':
+    if pycompat.sysplatform == 'plan9':
         return findexisting(os.path.join('/bin', command))
 
     for path in encoding.environ.get('PATH', '').split(pycompat.ospathsep):
--- a/mercurial/scmposix.py	Mon Dec 19 00:28:12 2016 +0530
+++ b/mercurial/scmposix.py	Mon Dec 19 02:15:24 2016 +0530
@@ -25,7 +25,7 @@
 
 def systemrcpath():
     path = []
-    if sys.platform == 'plan9':
+    if pycompat.sysplatform == 'plan9':
         root = 'lib/mercurial'
     else:
         root = 'etc/mercurial'
@@ -38,7 +38,7 @@
     return path
 
 def userrcpath():
-    if sys.platform == 'plan9':
+    if pycompat.sysplatform == 'plan9':
         return [encoding.environ['home'] + '/lib/hgrc']
     else:
         return [os.path.expanduser('~/.hgrc')]
--- a/mercurial/sslutil.py	Mon Dec 19 00:28:12 2016 +0530
+++ b/mercurial/sslutil.py	Mon Dec 19 02:15:24 2016 +0530
@@ -668,7 +668,8 @@
       for using system certificate store CAs in addition to the provided
       cacerts file
     """
-    if sys.platform != 'darwin' or util.mainfrozen() or not sys.executable:
+    if (pycompat.sysplatform != 'darwin' or
+                        util.mainfrozen() or not sys.executable):
         return False
     exe = os.path.realpath(sys.executable).lower()
     return (exe.startswith('/usr/bin/python') or
@@ -725,7 +726,7 @@
 
     # The Apple OpenSSL trick isn't available to us. If Python isn't able to
     # load system certs, we're out of luck.
-    if sys.platform == 'darwin':
+    if pycompat.sysplatform == 'darwin':
         # FUTURE Consider looking for Homebrew or MacPorts installed certs
         # files. Also consider exporting the keychain certs to a file during
         # Mercurial install.
--- a/mercurial/ui.py	Mon Dec 19 00:28:12 2016 +0530
+++ b/mercurial/ui.py	Mon Dec 19 02:15:24 2016 +0530
@@ -1086,7 +1086,7 @@
 
     def geteditor(self):
         '''return editor to use'''
-        if sys.platform == 'plan9':
+        if pycompat.sysplatform == 'plan9':
             # vi is the MIPS instruction simulator on Plan 9. We
             # instead default to E to plumb commit messages to
             # avoid confusion.