pombreda / pgreloaded

Automatically exported from code.google.com/p/pgreloaded
Other
0 stars 0 forks source link

resources.Resources(__file__) #13

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.Resources constructor is too verbose
apppath = os.path.dirname(os.path.abspath(__file__))
appresources = Resources(os.path.join(apppath, "data"))
appresources.get_path('image.png')

What is the expected output? What do you see instead?
appresources = Resources(__file__)
appresources.get_path('data/image.png')

This is an optional behavior that can be added easily.

Original issue reported on code.google.com by techtonik@gmail.com on 16 Jul 2012 at 7:57

GoogleCodeExporter commented 9 years ago
A notation for sub-paths has been omitted in the Resources class to avoid 
confusion with path delimiter expectations of users. Hence accessing a resource 
file via "<prefix><somedelim><resourcename>" should be avoided.

Enhancing Resources.scan() to consider non-directory paths as argument (and 
using the directory part of them as entry point for scanning) will be 
implemented:

appresources = Resources(__file__)
appresources.get_path("image.png")
...

Original comment by marcusvonappen@googlemail.com on 16 Jul 2012 at 9:22

GoogleCodeExporter commented 9 years ago
There is another more common user story to consider. When resources dir is 
located in project subdirectory.

Resources(__file__, subdir="data")

Original comment by techtonik@gmail.com on 16 Jul 2012 at 7:04

GoogleCodeExporter commented 9 years ago
And another story when directory layout is:

checkout/
    game.py
    game.conf
    data/
        audio/
            click.wav
        fonts/
            ter-u12b.bdf
            ter-u12n.bdf
        images/
            background.jpg
            button1.jpg
            button2.jpg
        info.dat

Original comment by techtonik@gmail.com on 16 Jul 2012 at 7:20

GoogleCodeExporter commented 9 years ago
PLease clarify what user story you mean with #c3.

Original comment by marcusvonappen@googlemail.com on 16 Jul 2012 at 8:11

GoogleCodeExporter commented 9 years ago
Non-directory paths and subdir arguments have been implemented in revision 
d2fa3f4e547a - thanks!

Original comment by marcusvonappen@googlemail.com on 17 Jul 2012 at 5:55

GoogleCodeExporter commented 9 years ago
Nice. =) In #c3 I wondered how do I load the audio if get_path() doesn't 
support subdirs. Looks like the only way through API is to provide separate 
Reources() instance for each subdir.

audioresources = Resources(__file__, 'data/audio')
audioresources.get_path("click.wav")

fontresources = Resources(__file__, 'data/fonts')
fontresources.get_path("ter-u12n.bdf")

Original comment by techtonik@gmail.com on 17 Jul 2012 at 1:28

GoogleCodeExporter commented 9 years ago
Resources.scan() walks recursively through all subdirectories (if not excluded 
by the excludepattern arguemnt). If you create (based on comment 3) a Resource 
instance on the data
directory, you also will have access to the contents of audio, fonts, images, 
...:

appresources = Resources(__file__, subdir="data")
appresources.get_path("click.wav")

Original comment by marcusvonappen@googlemail.com on 17 Jul 2012 at 3:39

GoogleCodeExporter commented 9 years ago
I see. 
http://wiki.pgreloaded.googlecode.com/hg/documentation/modules/resources.html 
says a lot, but doesn't mention this use case.

Original comment by techtonik@gmail.com on 17 Jul 2012 at 4:50

GoogleCodeExporter commented 9 years ago
A note about subdirectory scanning (and a file indexing limitation) has been 
added. Thanks for pointing it out.

Original comment by marcusvonappen@googlemail.com on 18 Jul 2012 at 5:58