Austin503 / pyglet

Automatically exported from code.google.com/p/pyglet
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

If a file in a resource path is in a directory, it isn't found. #492

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
This was reported by mdg583@gmail.com to the pyglet-users google group on 
roughly 8/31/2010, and received no response after 7 days. I have not reviewed 
it in any way (not even to check for a duplicate issue), but I'm entering it as 
an issue so it's not "lost".

===

bug:

If a file in a resource path is in a directory, it isn't found.

in resource.py, there is a line like this:
dirpath = '/'.join(os.path.split(dirpath))

Normally, this only puts forward slashes between the path elements.
However, if the directory path is only one layer (e.g. dirpath has no
'/'), then os.path.split still splits it into a list of size 2, with
the first element empty (http://docs.python.org/library/
os.path.html#os.path.split). As a result, '/'.join puts a / at the
beginning of the path, which keeps resources from being found.

I [mdg583] did this to fix it:

plist = os.path.split(dirpath)
if len(plist) == 2 and len(plist[0]) == 0:
        plist = plist[1:]
dirpath = '/'.join(plist)

Original issue reported on code.google.com by ores...@gmail.com on 6 Sep 2010 at 6:31

GoogleCodeExporter commented 8 years ago
I am monkey patching pyglet to work around this bug like this:

slash_paths = filter(lambda x: x.startswith('/'), 
pyglet.resource._default_loader._index.keys())
for path in slash_paths:
    pyglet.resource._default_loader._index[path[1:]] = pyglet.resource._default_loader._index[path]

Original comment by superjo...@gmail.com on 5 Apr 2011 at 6:43