When I use the following code to programatically append to the model-path in my Panda program, Panda doesn’t understand the lower-case path. This only seems to crash on another computer - not mine. (Which is why I can’t provide the traceback.)
ynjh_jo’s suggestion is a fine one, though you should also understand the underlying issue here.
On your friend’s computer, the tempfile module is returning a filename which has the wrong case. This probably means his environment has the wrong-case definition for $TEMP or $TMP. Normally Windows doesn’t care about that and will open the file anyway, but Panda has code which insists on following the proper case by default (and this code can be disabled using ynjh_jo’s suggestion).
Another way to fix it is to get the right-case filename:
The key function call here is Filename.makeTrueCase().
Note also the preferred use of fromOsSpecific() instead of replace(’\’, ‘/’), and the preferred use of getModelPath().appendDirectory() instead of loadPrcFileData().
I haven’t ran it on the computer with the problem yet, but it doesn’t seem to have changed the case. I suppose there’s a chance the removal of the “c:” will fix things anyhow.
On another note, thank you for showing me getModelPath()…that’s clean
It shouldn’t change the case on the computer that doesn’t have the problem, because on that computer, the case was correct in the first place! Because, you know, that computer doesn’t have the problem.
But the path “c:/users/USERNAME/appdata/etc” is incorrect on any copy of Windows Vista/7 (since it’s all lowercase), so it should be corrected on every single machine IMO.
Anyhow, I ran the code on the problem computer and it gave a texture loading error - basically the path wasn’t found.
Btw the output I gave in my previous post was from the computer without a problem. And it’s still lowercase…even though on disk the path uses uppercase letters. I don’t know if that makes any difference to your last post.
Well, you should perhaps check the return value of makeTrueCase(). If it returns false, then the filename in question didn’t exist, in either uppercase or lowercase, and there’s no correct way to change the filename. So maybe you’ve got no such temp directory, or maybe you’ve got an incorrect username there for some reason?
For the record, I have seen Windows installations where, for whatever reason, c:/Users/fooby/AppData was instead actually stored as c:/users/fooby/appdata on disk. So you can’t rely on the filename case always being the same across all Windows computers.
On my machine, this happens:
>>> f = Filename('/c/users/DROSE/appdata/local/temp')
>>> f
/c/users/DROSE/appdata/local/temp
>>> f.makeTrueCase()
True
>>> f
/c/Users/drose/AppData/Local/Temp
Okay, thanks for your time. Nothing seems to have solved the problem, but it’s been fine running with the short hack for quite a while, and at least for my setup it doesn’t seem like there’s an easy fix.
Can’t use, since the Panda GUI sits on top of a pure Python module that shouldn’t import Filename. Also, the Panda code can’t tell the pure file what temp dir to use, since the pure file would have already been using the path it got from the tempfile module.
p.s. Yes, makeTrueCase returns True.
p.p.s For the fun of it, I printed out Filename.getTempDirectory()…it gave yet another incorrectly-cased path! Most of the string is correct, but supposedly my username is all caps. So actually fix #3 is shot too
Hmm, if setting “vfs-case-sensitive 0” doesn’t allow you to load the file, either you didn’t set it correctly, or the file doesn’t exist in the first place. Are you still seeing the error message about “file is incorrect case” with this config variable setting? If you are, then your config setting didn’t stick. If you’re not, then there’s some other reason you can’t load the file.
#2:
Same as above. Are you still seeing the “file is incorrect case” error message? If not, then it’s not the filename case that’s causing your texture loading error.
#3:
I don’t understand what you’re talking about here, since all of these require some Panda interfaces. But maybe you mean you want to read the same temp directory in two different places, one in the Panda world, and one in the pure Python world? All right. I bet you could find some way to communicate the directory name between them, but there’s no need to get outrageous. The tempfile module ought to work.
p.s.
What version of Panda are you using? Does it behave the same way in 1.8.0?
p.p.s.
Since Filename.getTempDirectory() is just a thin call into Windows’ GetTempPath(), if getTempDirectory() is returning the wrong case, it follows that GetTempPath() is also returning the wrong case for you. Probably due to a bad $TEMP definition, again, or something like that. Again, makeTrueCase() is supposed to fix this.
Ah yes, okay my TEMP and TMP environment variables are set incorrectly (incidentally exactly what Filename.getTempDirectory() returns, as you suggested). Since the vfs-case-sensitive setting isn’t working for whatever reason, I’ll think about option #3 some more, thanks.