On Thu, Mar 26, 2009 at 4:48 PM, Barry Warsaw <ba...@python.org> wrote: > On Mar 26, 2009, at 3:07 PM, Olemis Lang wrote: >> On Thu, Mar 26, 2009 at 2:52 PM, Barry Warsaw <ba...@python.org> wrote: >>> On Mar 26, 2009, at 2:43 PM, Olemis Lang wrote: >>>>>>> >>>>>>> One thing that /would/ be helpful though is the ability to list all >>>>>>> the >>>>>>> resources under a specific package path. This is (I think) one use >>>>>>> case >>>>>>> that pkg_resource fails to support and it's the one place that I've >>>>>>> had >>>>>>> to >>>>>>> drop down to file system introspection. >>>>>>> >>>> >>>> Really ... ? What are all these for ? >>> >>> E.g. find all the doctests under foo.bar.docs >> >> Could you explain this a little more pls ? You mean ... using doctest >> finders in a module (even inside a zip file ;) that's already loaded ? >> >> Sure ... else I dont understand ... > > Here's a concrete example. I have a bunch of .sql files inside the > mailman.database package. Their file names encode a sort order. I want to > load each one in order and apply them to my database. I'd like to be able > to find all these .sql files (which are intermixed with .py files in the > same package) without having to use os.listdir() because that forces the > package to live on the file system. >
Ok ... I will assume the following scenario : - You have many .py together ... so you distribute them in a mailman.database package (not module ... but it should be almost the same thing ...) and provide setup.py for this ... therefore you should have something like this in the later file {{{ #!python try: from setuptools import setup except ImportError: from distutils.core import setup # Many incredibly useful statements ... setup( name='mailman.database', package_dir = { 'mailman.database' : './db', }, packages= ['mailman.database'], package_data={ 'mailman.database': ['sql/*', 'messages/es/LC_MESSAGES/*'] }, **many_incredibly_useful_args ) }}} - Provided you have done this ... I will assume that u need to execute such scripts at run-time, and not at install-time ... else setup.py is more than enough ... ;) {{{ #!python from pkg_resources import * for fnm in sorted(resource_listdir('mailman.database', 'sql'), \ my_own_cmp ): # Only if needed ... ;) exec_script(resource_string('mailman.database', 'sql/' + fnm)) }}} ... perhaps your specific example is a little bit more complex than that ... but the procedure should be similar to the one ci-dessus ... :) ResourceManager instances handle all the details involved disregarding whether the pkg is in a zip file, an egg file or FS ... ;) CMIIW anyway ... ;) -- Regards, Olemis. Blog ES: http://simelo-es.blogspot.com/ Blog EN: http://simelo-en.blogspot.com/ Featured article: Comandos : Pipe Viewer ... ¿Qué está pasando por esta tubería? _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com