casesmash.py
41 lines
| 934 B
| text/x-python
|
PythonLexer
/ contrib / casesmash.py
Pulkit Goyal
|
r28351 | from __future__ import absolute_import | ||
import __builtin__ | ||||
import os | ||||
Augie Fackler
|
r43346 | from mercurial import util | ||
Matt Mackall
|
r14730 | |||
def lowerwrap(scope, funcname): | ||||
f = getattr(scope, funcname) | ||||
Augie Fackler
|
r43346 | |||
Matt Mackall
|
r14730 | def wrap(fname, *args, **kwargs): | ||
d, base = os.path.split(fname) | ||||
try: | ||||
files = os.listdir(d or '.') | ||||
Simon Heimberg
|
r19378 | except OSError: | ||
Matt Mackall
|
r14730 | 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) | ||||
Augie Fackler
|
r43346 | |||
Matt Mackall
|
r14730 | scope.__dict__[funcname] = wrap | ||
Augie Fackler
|
r43346 | |||
Matt Mackall
|
r14730 | def normcase(path): | ||
return path.lower() | ||||
Augie Fackler
|
r43346 | |||
Matt Mackall
|
r14730 | 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') | ||||