On 4/16/08, David Eyk <[EMAIL PROTECTED]> wrote: > > On Apr 15, 10:12 am, David Eyk <[EMAIL PROTECTED]> wrote: > > This seems like a more pythonic route for the module to take. I've > > been looking at the Loader implementation. Changing the index handle > > shouldn't be hard at all. I still dream of recursive indexing, but I > > haven't quite figured out how the current reindex method could be bent > > toward that end. > > > Putting my money where my mouth is, here's a patch for resource.py, to > handle data namespaces. I've tested this a little, but not > thoroughly. It does *not* handle names inside a zipfile, as I don't > quite understand what's going on in that section yet. Anything > indexed inside a zipfile *should* demonstrate the old, flat namespace > behavior. > > Index: pyglet/resource.py > =================================================================== > --- pyglet/resource.py (revision 2013) > +++ pyglet/resource.py (working copy) > @@ -328,7 +328,12 @@ > # Filesystem directory > location = FileLocation(path) > for name in os.listdir(path): > - self._index_file(name, location) > + try: > + fullname = > os.path.normpath(os.path.join(path, name)) > + relative_name = > fullname.split(self._script_home)[1][1:] > + except IndexError: > + relative_name = name > + self._index_file(relative_name, location) > else: > # Find path component that is the ZIP file. > dir = '' > @@ -366,7 +371,7 @@ > ''' > try: > location = self._index[name] > - return location.open(name, mode) > + return location.open(os.path.basename(name), mode) > except KeyError: > raise ResourceNotFoundException(name)
>From what I can tell this patch still requires each leaf path to specified explicitly, which doesn't solve the problem from your original post. It also indexes everything relative to the script_home, which makes it impossible to override an asset from some other location. I have a rough idea of how I'd like to implement it: walk over each specified path component and index everything relative to that path. So, with a filesystem that looks like (assume relative to script_home): res/water.png res/tiles/water.png res/animations/water.png override/water.png override/tiles/water.png and a path of ['override', 'res'], the resulting index will be water.png -> override/water.png tiles/water.png -> override/tiles/water.png animations/water.png -> res/animations/water.png (whereas currently you'll only get 'water.png' indexed -- backward compatibility is maintained, incidentally). Alex. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pyglet-users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/pyglet-users?hl=en -~----------~----~----~----~------~----~------~--~---
