Patchwork D1034: codemod: use pycompat.iswindows

login
register
mail settings
Submitter phabricator
Date Oct. 13, 2017, 6:37 a.m.
Message ID <254d1f3fb8b7811914bec4dd1807a996@localhost.localdomain>
Download mbox | patch
Permalink /patch/24816/
State Not Applicable
Headers show

Comments

phabricator - Oct. 13, 2017, 6:37 a.m.
quark updated this revision to Diff 2656.
quark edited the summary of this revision.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D1034?vs=2637&id=2656

REVISION DETAIL
  https://phab.mercurial-scm.org/D1034

AFFECTED FILES
  hgext/convert/subversion.py
  hgext/largefiles/lfutil.py
  hgext/logtoprocess.py
  hgext/schemes.py
  hgext/win32mbcs.py
  mercurial/color.py
  mercurial/debugcommands.py
  mercurial/hgweb/server.py
  mercurial/i18n.py
  mercurial/pure/osutil.py
  mercurial/rcutil.py
  mercurial/scmutil.py
  mercurial/sslutil.py
  mercurial/subrepo.py
  mercurial/ui.py
  mercurial/util.py
  mercurial/vfs.py
  mercurial/worker.py

CHANGE DETAILS




To: quark, #hg-reviewers, spectral
Cc: mercurial-devel

Patch

diff --git a/mercurial/worker.py b/mercurial/worker.py
--- a/mercurial/worker.py
+++ b/mercurial/worker.py
@@ -203,7 +203,7 @@ 
     elif os.WIFSIGNALED(code):
         return -os.WTERMSIG(code)
 
-if pycompat.osname != 'nt':
+if not pycompat.iswindows:
     _platformworker = _posixworker
     _exitstatus = _posixexitstatus
 
diff --git a/mercurial/vfs.py b/mercurial/vfs.py
--- a/mercurial/vfs.py
+++ b/mercurial/vfs.py
@@ -543,7 +543,7 @@ 
 
         # Only Windows/NTFS has slow file closing. So only enable by default
         # on that platform. But allow to be enabled elsewhere for testing.
-        defaultenabled = pycompat.osname == 'nt'
+        defaultenabled = pycompat.iswindows
         enabled = ui.configbool('worker', 'backgroundclose', defaultenabled)
 
         if not enabled:
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -92,7 +92,7 @@ 
 if isatty(stdout):
     stdout = os.fdopen(stdout.fileno(), pycompat.sysstr('wb'), 1)
 
-if pycompat.osname == 'nt':
+if pycompat.iswindows:
     from . import windows as platform
     stdout = platform.winstdout(stdout)
 else:
@@ -1348,7 +1348,7 @@ 
             return _("filename ends with '%s', which is not allowed "
                      "on Windows") % t
 
-if pycompat.osname == 'nt':
+if pycompat.iswindows:
     checkosfilename = checkwinfilename
     timer = time.clock
 else:
@@ -1572,7 +1572,7 @@ 
             # pure build; use a safe default
             return True
     else:
-        return pycompat.osname == "nt" or encoding.environ.get("DISPLAY")
+        return pycompat.iswindows or encoding.environ.get("DISPLAY")
 
 def mktempcopy(name, emptyok=False, createmode=None):
     """Create a temporary file with the same contents from name
diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -1041,7 +1041,7 @@ 
         # gracefully and tell the user about their broken pager.
         shell = any(c in command for c in "|&;<>()$`\\\"' \t\n*?[#~=%")
 
-        if pycompat.osname == 'nt' and not shell:
+        if pycompat.iswindows and not shell:
             # Window's built-in `more` cannot be invoked with shell=False, but
             # its `more.com` can.  Hide this implementation detail from the
             # user so we can also get sane bad PAGER behavior.  MSYS has
diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -1347,7 +1347,7 @@ 
             if e.errno != errno.ENOENT:
                 raise error.Abort(genericerror % (
                     self._path, encoding.strtolocal(e.strerror)))
-            elif pycompat.osname == 'nt':
+            elif pycompat.iswindows:
                 try:
                     self._gitexecutable = 'git.cmd'
                     out, err = self._gitnodir(['--version'])
diff --git a/mercurial/sslutil.py b/mercurial/sslutil.py
--- a/mercurial/sslutil.py
+++ b/mercurial/sslutil.py
@@ -477,7 +477,7 @@ 
                         'for more info)\n'))
 
             elif (e.reason == 'CERTIFICATE_VERIFY_FAILED' and
-                pycompat.osname == 'nt'):
+                pycompat.iswindows):
 
                 ui.warn(_('(the full certificate chain may not be available '
                           'locally; see "hg help debugssl")\n'))
@@ -717,7 +717,7 @@ 
     # because we'll get a certificate verification error later and the lack
     # of loaded CA certificates will be the reason why.
     # Assertion: this code is only called if certificates are being verified.
-    if pycompat.osname == 'nt':
+    if pycompat.iswindows:
         if not _canloaddefaultcerts:
             ui.warn(_('(unable to load Windows CA certificates; see '
                       'https://mercurial-scm.org/wiki/SecureConnections for '
@@ -749,7 +749,7 @@ 
     # / is writable on Windows. Out of an abundance of caution make sure
     # we're not on Windows because paths from _systemcacerts could be installed
     # by non-admin users.
-    assert pycompat.osname != 'nt'
+    assert not pycompat.iswindows
 
     # Try to find CA certificates in well-known locations. We print a warning
     # when using a found file because we don't want too much silent magic
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -41,7 +41,7 @@ 
     vfs,
 )
 
-if pycompat.osname == 'nt':
+if pycompat.iswindows:
     from . import scmwindows as scmplatform
 else:
     from . import scmposix as scmplatform
@@ -291,7 +291,7 @@ 
     val = ui.config('ui', 'portablefilenames')
     lval = val.lower()
     bval = util.parsebool(val)
-    abort = pycompat.osname == 'nt' or lval == 'abort'
+    abort = pycompat.iswindows or lval == 'abort'
     warn = bval or lval == 'warn'
     if bval is None and not (warn or abort or lval == 'ignore'):
         raise error.ConfigError(
diff --git a/mercurial/rcutil.py b/mercurial/rcutil.py
--- a/mercurial/rcutil.py
+++ b/mercurial/rcutil.py
@@ -15,7 +15,7 @@ 
     util,
 )
 
-if pycompat.osname == 'nt':
+if pycompat.iswindows:
     from . import scmwindows as scmplatform
 else:
     from . import scmposix as scmplatform
diff --git a/mercurial/pure/osutil.py b/mercurial/pure/osutil.py
--- a/mercurial/pure/osutil.py
+++ b/mercurial/pure/osutil.py
@@ -64,7 +64,7 @@ 
             result.append((fn, _mode_to_kind(st.st_mode)))
     return result
 
-if pycompat.osname != 'nt':
+if not pycompat.iswindows:
     posixfile = open
 
     _SCM_RIGHTS = 0x01
diff --git a/mercurial/i18n.py b/mercurial/i18n.py
--- a/mercurial/i18n.py
+++ b/mercurial/i18n.py
@@ -29,7 +29,7 @@ 
     unicode = str
 
 _languages = None
-if (pycompat.osname == 'nt'
+if (pycompat.iswindows
     and 'LANGUAGE' not in encoding.environ
     and 'LC_ALL' not in encoding.environ
     and 'LC_MESSAGES' not in encoding.environ
diff --git a/mercurial/hgweb/server.py b/mercurial/hgweb/server.py
--- a/mercurial/hgweb/server.py
+++ b/mercurial/hgweb/server.py
@@ -266,7 +266,7 @@ 
 class MercurialHTTPServer(_mixin, httpservermod.httpserver, object):
 
     # SO_REUSEADDR has broken semantics on windows
-    if pycompat.osname == 'nt':
+    if pycompat.iswindows:
         allow_reuse_address = 0
 
     def __init__(self, ui, app, addr, handler, **kwargs):
diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -2072,7 +2072,7 @@ 
     If the update succeeds, retry the original operation.  Otherwise, the cause
     of the SSL error is likely another issue.
     '''
-    if pycompat.osname != 'nt':
+    if not pycompat.iswindows:
         raise error.Abort(_('certificate chain building is only possible on '
                             'Windows'))
 
diff --git a/mercurial/color.py b/mercurial/color.py
--- a/mercurial/color.py
+++ b/mercurial/color.py
@@ -210,7 +210,7 @@ 
         mode = ui.config('color', 'pagermode', mode)
 
     realmode = mode
-    if pycompat.osname == 'nt':
+    if pycompat.iswindows:
         from . import win32
 
         term = encoding.environ.get('TERM')
@@ -379,7 +379,7 @@ 
     return msg
 
 w32effects = None
-if pycompat.osname == 'nt':
+if pycompat.iswindows:
     import ctypes
 
     _kernel32 = ctypes.windll.kernel32
diff --git a/hgext/win32mbcs.py b/hgext/win32mbcs.py
--- a/hgext/win32mbcs.py
+++ b/hgext/win32mbcs.py
@@ -190,7 +190,7 @@ 
     if _encoding.lower() in problematic_encodings.split():
         for f in funcs.split():
             wrapname(f, wrapper)
-        if pycompat.osname == 'nt':
+        if pycompat.iswindows:
             for f in winfuncs.split():
                 wrapname(f, wrapper)
         wrapname("mercurial.util.listdir", wrapperforlistdir)
diff --git a/hgext/schemes.py b/hgext/schemes.py
--- a/hgext/schemes.py
+++ b/hgext/schemes.py
@@ -116,7 +116,7 @@ 
     schemes.update(dict(ui.configitems('schemes')))
     t = templater.engine(lambda x: x)
     for scheme, url in schemes.items():
-        if (pycompat.osname == 'nt' and len(scheme) == 1 and scheme.isalpha()
+        if (pycompat.iswindows and len(scheme) == 1 and scheme.isalpha()
             and os.path.exists('%s:\\' % scheme)):
             raise error.Abort(_('custom scheme %s:// conflicts with drive '
                                'letter %s:\\\n') % (scheme, scheme.upper()))
diff --git a/hgext/logtoprocess.py b/hgext/logtoprocess.py
--- a/hgext/logtoprocess.py
+++ b/hgext/logtoprocess.py
@@ -52,7 +52,7 @@ 
 testedwith = 'ships-with-hg-core'
 
 def uisetup(ui):
-    if pycompat.osname == 'nt':
+    if pycompat.iswindows:
         # no fork on Windows, but we can create a detached process
         # https://msdn.microsoft.com/en-us/library/windows/desktop/ms684863.aspx
         # No stdlib constant exists for this value
diff --git a/hgext/largefiles/lfutil.py b/hgext/largefiles/lfutil.py
--- a/hgext/largefiles/lfutil.py
+++ b/hgext/largefiles/lfutil.py
@@ -75,7 +75,7 @@ 
     path = ui.configpath(longname, 'usercache', None)
     if path:
         return path
-    if pycompat.osname == 'nt':
+    if pycompat.iswindows:
         appdata = encoding.environ.get('LOCALAPPDATA',\
                         encoding.environ.get('APPDATA'))
         if appdata:
diff --git a/hgext/convert/subversion.py b/hgext/convert/subversion.py
--- a/hgext/convert/subversion.py
+++ b/hgext/convert/subversion.py
@@ -103,7 +103,7 @@ 
         pass
     if os.path.isdir(path):
         path = os.path.normpath(os.path.abspath(path))
-        if pycompat.osname == 'nt':
+        if pycompat.iswindows:
             path = '/' + util.normpath(path)
         # Module URL is later compared with the repository URL returned
         # by svn API, which is UTF-8.
@@ -254,7 +254,7 @@ 
     try:
         proto, path = url.split('://', 1)
         if proto == 'file':
-            if (pycompat.osname == 'nt' and path[:1] == '/'
+            if (pycompat.iswindows and path[:1] == '/'
                   and path[1:2].isalpha() and path[2:6].lower() == '%3a/'):
                 path = path[:2] + ':/' + path[6:]
             path = urlreq.url2pathname(path)