view contrib/casesmash.py @ 28336:a5a13eeffc59

tests: Solaris sed does not support "\n" meaning newline in the RHS of s/// The blackbox test rewrites a copy of test-dispatch.py on the fly, and adds a couple of lines with the s/// command. GNU sed supports the use of the \n escape to represent a newline, but not Solaris sed. Using a literal newline, prefixed by a backslash, works with both versions of the utility.
author Danek Duvall <danek.duvall@oracle.com>
date Wed, 02 Mar 2016 14:55:13 -0800
parents 9de689d20230
children 42a7301fb4d5
line wrap: on
line source

import os, __builtin__
from mercurial import util

def lowerwrap(scope, funcname):
    f = getattr(scope, funcname)
    def wrap(fname, *args, **kwargs):
        d, base = os.path.split(fname)
        try:
            files = os.listdir(d or '.')
        except OSError:
            files = []
        if base in files:
            return f(fname, *args, **kwargs)
        for fn in files:
            if fn.lower() == base.lower():
                return f(os.path.join(d, fn), *args, **kwargs)
        return f(fname, *args, **kwargs)
    scope.__dict__[funcname] = wrap

def normcase(path):
    return path.lower()

os.path.normcase = normcase

for f in 'file open'.split():
    lowerwrap(__builtin__, f)

for f in "chmod chown open lstat stat remove unlink".split():
    lowerwrap(os, f)

for f in "exists lexists".split():
    lowerwrap(os.path, f)

lowerwrap(util, 'posixfile')