mercurial/windows.py
changeset 45942 89a2afe31e82
parent 45158 ed58ecd59030
child 46819 d4ba4d51f85f
equal deleted inserted replaced
45941:346af7687c6f 45942:89a2afe31e82
   193     except AttributeError:
   193     except AttributeError:
   194         return False
   194         return False
   195 
   195 
   196 
   196 
   197 class winstdout(object):
   197 class winstdout(object):
   198     '''Some files on Windows misbehave.
   198     """Some files on Windows misbehave.
   199 
   199 
   200     When writing to a broken pipe, EINVAL instead of EPIPE may be raised.
   200     When writing to a broken pipe, EINVAL instead of EPIPE may be raised.
   201 
   201 
   202     When writing too many bytes to a console at the same, a "Not enough space"
   202     When writing too many bytes to a console at the same, a "Not enough space"
   203     error may happen. Python 3 already works around that.
   203     error may happen. Python 3 already works around that.
   204     '''
   204     """
   205 
   205 
   206     def __init__(self, fp):
   206     def __init__(self, fp):
   207         self.fp = fp
   207         self.fp = fp
   208         self.throttle = not pycompat.ispy3 and _isatty(fp)
   208         self.throttle = not pycompat.ispy3 and _isatty(fp)
   209 
   209 
   495 def isowner(st):
   495 def isowner(st):
   496     return True
   496     return True
   497 
   497 
   498 
   498 
   499 def findexe(command):
   499 def findexe(command):
   500     '''Find executable for command searching like cmd.exe does.
   500     """Find executable for command searching like cmd.exe does.
   501     If command is a basename then PATH is searched for command.
   501     If command is a basename then PATH is searched for command.
   502     PATH isn't searched if command is an absolute or relative path.
   502     PATH isn't searched if command is an absolute or relative path.
   503     An extension from PATHEXT is found and added if not present.
   503     An extension from PATHEXT is found and added if not present.
   504     If command isn't found None is returned.'''
   504     If command isn't found None is returned."""
   505     pathext = encoding.environ.get(b'PATHEXT', b'.COM;.EXE;.BAT;.CMD')
   505     pathext = encoding.environ.get(b'PATHEXT', b'.COM;.EXE;.BAT;.CMD')
   506     pathexts = [ext for ext in pathext.lower().split(pycompat.ospathsep)]
   506     pathexts = [ext for ext in pathext.lower().split(pycompat.ospathsep)]
   507     if os.path.splitext(command)[1].lower() in pathexts:
   507     if os.path.splitext(command)[1].lower() in pathexts:
   508         pathexts = [b'']
   508         pathexts = [b'']
   509 
   509 
   527 
   527 
   528 _wantedkinds = {stat.S_IFREG, stat.S_IFLNK}
   528 _wantedkinds = {stat.S_IFREG, stat.S_IFLNK}
   529 
   529 
   530 
   530 
   531 def statfiles(files):
   531 def statfiles(files):
   532     '''Stat each file in files. Yield each stat, or None if a file
   532     """Stat each file in files. Yield each stat, or None if a file
   533     does not exist or has a type we don't care about.
   533     does not exist or has a type we don't care about.
   534 
   534 
   535     Cluster and cache stat per directory to minimize number of OS stat calls.'''
   535     Cluster and cache stat per directory to minimize number of OS stat calls."""
   536     dircache = {}  # dirname -> filename -> status | None if file does not exist
   536     dircache = {}  # dirname -> filename -> status | None if file does not exist
   537     getkind = stat.S_IFMT
   537     getkind = stat.S_IFMT
   538     for nf in files:
   538     for nf in files:
   539         nf = normcase(nf)
   539         nf = normcase(nf)
   540         dir, base = os.path.split(nf)
   540         dir, base = os.path.split(nf)
   628     def cacheable(self):
   628     def cacheable(self):
   629         return False
   629         return False
   630 
   630 
   631 
   631 
   632 def lookupreg(key, valname=None, scope=None):
   632 def lookupreg(key, valname=None, scope=None):
   633     ''' Look up a key/value name in the Windows registry.
   633     """Look up a key/value name in the Windows registry.
   634 
   634 
   635     valname: value name. If unspecified, the default value for the key
   635     valname: value name. If unspecified, the default value for the key
   636     is used.
   636     is used.
   637     scope: optionally specify scope for registry lookup, this can be
   637     scope: optionally specify scope for registry lookup, this can be
   638     a sequence of scopes to look up in order. Default (CURRENT_USER,
   638     a sequence of scopes to look up in order. Default (CURRENT_USER,
   639     LOCAL_MACHINE).
   639     LOCAL_MACHINE).
   640     '''
   640     """
   641     if scope is None:
   641     if scope is None:
   642         scope = (winreg.HKEY_CURRENT_USER, winreg.HKEY_LOCAL_MACHINE)
   642         scope = (winreg.HKEY_CURRENT_USER, winreg.HKEY_LOCAL_MACHINE)
   643     elif not isinstance(scope, (list, tuple)):
   643     elif not isinstance(scope, (list, tuple)):
   644         scope = (scope,)
   644         scope = (scope,)
   645     for s in scope:
   645     for s in scope: