[Python-Dev] Easy way to detect filesystem case-sensitivity?
MRAB
google at mrabarnett.plus.com
Fri May 8 19:01:55 CEST 2009
Brett Cannon wrote:
>
>
> On Thu, May 7, 2009 at 18:56, John Arbash Meinel
> <john.arbash.meinel at gmail.com <mailto:john.arbash.meinel at gmail.com>> wrote:
>
> Andrew Bennetts wrote:
> > Antoine Pitrou wrote:
> >> Robert Kern <robert.kern <at> gmail.com <http://gmail.com>> writes:
> >>> Since one may have more than one filesystem side-by-side, this
> can't be just
> >> be
> >>> a system-wide boolean somewhere. One would have to query the
> target directory
> >>> for this information. I am not aware of the existence of code
> that does such
> >> a
> >>> query, though.
> >> Or you can just be practical and test for it. Create a file
> "foobar" and see if
> >> you can open "FOOBAR" in read mode...
> >
> > Agreed. That is how Bazaar's test suite detects this, and it
> works well.
> >
> > -Andrew.
>
>
> Actually, I believe we do:
>
> open('format', 'wb').close()
> try:
> os.lstat('FoRmAt')
> except IOError, e:
> if e.errno == errno.ENOENT:
> ...
>
> I don't know that it really matters, just wanted to indicate we use
> 'lstat' rather than 'open()' to check. I could be wrong about the test
> suite, but I know that is what we do for 'live' files. (We always create
> a format file, so we know it is there to 'stat' it via a different
> name.)
>
>
> Thanks for the help to everyone. I ended up simply taking __file__,
> making it all uppercase (or lowercase if it is already uppercase) and
> then doing os.path.exists() on the modified name. Seems to work.
>
Alternatively, use swapcase() and then os.path.exists().
More information about the Python-Dev
mailing list