[Distutils] pkg_resources: feature request
Phillip J. Eby
pje at telecommunity.com
Thu Sep 29 01:11:46 CEST 2005
At 05:16 PM 9/28/2005 -0500, Ian Bicking wrote:
>I just added a WSGI app in paste.urlparser.PkgResourceParser
>(http://svn.pythonpaste.org/Paste/branches/mainline-refactor/paste/urlparser.py)
>
>to serve static files using pkg_resources's resource API. Two new
>methods would be useful there: resource_mtime and resource_size.
>Alternately, resource_stat, which would return an os.stat-compatible
>object. But a lot of what os.stat returns doesn't apply well to a zip
>file entry, even if mtime and size do. I'm not sure if mtime should be
>the mtime of the zip file itself, or the date_time of the entry.
FYI, if you use resource_filename() and stat the file, you'll get the
datetime of the file as it was in the zip, as well as the size. If you've
opened the file for reading using resource_stream(), then you can try using
seek() and tell() to find the file size. I believe StringIO (used for zip
files) and regular file objects support that.
I'll think about adding more direct ways to query those things, but in the
meantime those are some good ways to get the information from the existing
implementation. I realize you may not want to unpack the zipfile to disk
(as resource_filename does), but it's cached on disk thereafter, and with
some servers you could potentially take advantage of static file serving
that way. And in the case of an egg that was installed unzipped (or a
project that's under development via "setup.py develop"), the file will
already be on disk and resource_filename() is just telling you where it is.
More information about the Distutils-SIG
mailing list