Greetings. I'm developing a Python-based product that needs to serve up a variety of XML files out of the product's directory. That is, certain URLs handled by instances of a product-defined type need to return an XML file that's on disk along with the product's DTML views and the like. Let's say that the URL http://localhost/foo/bar resolves to an object my product class defines. Then I'd like http://localhst/foo/bar/static/a to serve a file named 'a' in a directory named 'xml_files' in my product's directory. Similarly, http://localhst/foo/bar/static/b/c should serve a file named 'c' within a directory named 'b' within 'xml_files' in my product's directory. I'd rather not hard-code every single file in the Python module, since there will be many, and they'll be changing a lot during development. I've been messing around with DTMLFile and ClassicHTMLFile and the like, haven't been able to figure out how to get it to work for arbitrary paths. They also require all my file names end in '.dtml', which is quite a pain. Any suggestions? Thanks, ..Ian -- --- -- --- -- --- -- --- -- --- -- --- -- --- -- --- -- --- -- Dr. Ian Beatty beatty@physics.umass.edu Physics Education Research Group voice: 413.545.9483 Department of Physics fax: 413.545.4884 Univ. of Massachusetts AIM: (available upon request) Amherst, MA 01003-4525 USA http://umperg.physics.umass.edu/ -- --- -- --- -- --- -- --- -- --- -- --- -- --- -- --- -- --- --
I serve static content with FileSystemSite (http://www.zope.org/Members/k_vertigo/Products/FileSystemSite). Sandor
-----Original Message----- From: zope-dev-bounces@zope.org [mailto:zope-dev-bounces@zope.org] On Behalf Of Ian Beatty Sent: Tuesday, March 09, 2004 12:13 PM To: zope-dev@zope.org Subject: [Zope-dev] Product Access to Files
Greetings.
I'm developing a Python-based product that needs to serve up a variety of XML files out of the product's directory. That is, certain URLs handled by instances of a product-defined type need to return an XML file that's on disk along with the product's DTML views and the like. Let's say that the URL
http://localhost/foo/bar resolves to an object my product class defines. Then I'd like http://localhst/foo/bar/static/a to serve a file named 'a' in a directory named 'xml_files' in my product's directory. Similarly, http://localhst/foo/bar/static/b/c should serve a file named 'c' within a directory named 'b' within 'xml_files' in my product's directory. I'd rather not hard-code every single file in the Python module, since there will be many, and they'll be changing a lot during development. I've been messing around with DTMLFile and ClassicHTMLFile and the like, haven't been able to figure out how to get it to work for arbitrary paths. They also require all my file names end in '.dtml', which is quite a pain. Any suggestions? Thanks, ..Ian -- --- -- --- -- --- -- --- -- --- -- --- -- --- -- --- -- --- -- Dr. Ian Beatty beatty@physics.umass.edu Physics Education Research Group voice: 413.545.9483 Department of Physics fax: 413.545.4884 Univ. of Massachusetts AIM: (available upon request) Amherst, MA 01003-4525 USA http://umperg.physics.umass.edu/ -- --- -- --- -- --- -- --- -- --- -- --- -- --- -- --- -- --- -- _______________________________________________ Zope-Dev maillist - Zope-Dev@zope.org http://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope )
Ian Beatty wrote:
I've been messing around with DTMLFile and ClassicHTMLFile and the like, haven't been able to figure out how to get it to work for arbitrary paths. They also require all my file names end in '.dtml', which is quite a pain.
Any suggestions?
Local FS? What Sandor said? Apache and rewrite rules? cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
On 2004-03-10 10:14 AM, Chris Withers is reputed to have said:
Ian Beatty wrote:
I've been messing around with DTMLFile and ClassicHTMLFile and the like, haven't been able to figure out how to get it to work for arbitrary paths. They also require all my file names end in '.dtml', which is quite a pain.
Any suggestions?
Local FS? What Sandor said? Apache and rewrite rules?
I'm overriding '__getitem__' and using Python's "os" package to directly access the local file system. I just sniff the file name extension and set the response content-type, then return the contents of the named file. Simple and stupid. I actually delegate the file-serving to a helper class, and use recursion to handle arbitrary-length paths for arbitrary-depth file system hierarchies. Simple, stupid, and inelegant, but it seems to work. FileSystemSite seemed geared towards providing ZMI access to static files. I just want my product to be able to dish out preset files that are part of the product. (If anyone's curious, I'm using a Zope product for a back-end to a Mozilla/XUL front-end. This static file stuff allows the product to provide the XUL, JavaScript, and CSS files needed to define the Mozilla-based interface.) Thanks for all the suggestions. Cheers, ..Ian -- --- -- --- -- --- -- --- -- --- -- --- -- --- -- --- -- --- -- Dr. Ian Beatty beatty@physics.umass.edu Physics Education Research Group voice: 413.545.9483 Department of Physics fax: 413.545.4884 Univ. of Massachusetts AIM: (available upon request) Amherst, MA 01003-4525 USA http://umperg.physics.umass.edu/ -- --- -- --- -- --- -- --- -- --- -- --- -- --- -- --- -- --- --
I'm overriding '__getitem__' and using Python's "os" package to directly access the local file system. I just sniff the file name extension and set the response content-type, then return the contents of the named file. Simple and stupid.
Ooo... I hope you're confident in what you're doing :-S Should be vaguely okay, provided you're not writing to those files with the os module. Mindyou, Apache could serve 'em a LOT faster...
(If anyone's curious, I'm using a Zope product for a back-end to a Mozilla/XUL front-end. This static file stuff allows the product to provide the XUL, JavaScript, and CSS files needed to define the Mozilla-based interface.)
Cool :-) Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
On 2004-03-11 7:04 AM, Chris Withers is reputed to have said:
I'm overriding '__getitem__' and using Python's "os" package to directly access the local file system. I just sniff the file name extension and set the response content-type, then return the contents of the named file. Simple and stupid.
Ooo... I hope you're confident in what you're doing :-S
Not in the least! =8-0 I've never mucked around this deep within Zope before. What's the danger... threading issues?
Should be vaguely okay, provided you're not writing to those files with the os module.
No writing, only reading.
Mindyou, Apache could serve 'em a LOT faster...
It's a whole lot easier to have those files nicely packaged inside my product, so that all someone needs to do is install the product and be done with it. No separate directory of files to put somewhere, no Apache configuration to do, no URL issues. I'm wide open to suggestions for a better way to do this!
(If anyone's curious, I'm using a Zope product for a back-end to a Mozilla/XUL front-end. This static file stuff allows the product to provide the XUL, JavaScript, and CSS files needed to define the Mozilla-based interface.)
Cool :-)
I think so! ;-P In the long run, I may set up the XUL/etc. to be installed into the user's Mozilla "Chrome", and then it would be permanently resident. So it would only be downloaded once per user, which makes efficiency less important and Apache (hopefully) unnecessary. Cheers, ..Ian -- --- -- --- -- --- -- --- -- --- -- --- -- --- -- --- -- --- -- Dr. Ian Beatty beatty@physics.umass.edu Physics Education Research Group voice: 413.545.9483 Department of Physics fax: 413.545.4884 Univ. of Massachusetts AIM: (available upon request) Amherst, MA 01003-4525 USA http://umperg.physics.umass.edu/ -- --- -- --- -- --- -- --- -- --- -- --- -- --- -- --- -- --- --
Ian Beatty wrote:
Not in the least! =8-0 I've never mucked around this deep within Zope before. What's the danger... threading issues?
Yeah, but should be okay as you're only reading...
It's a whole lot easier to have those files nicely packaged inside my product, so that all someone needs to do is install the product and be done with it. No separate directory of files to put somewhere, no Apache configuration to do, no URL issues.
I'm wide open to suggestions for a better way to do this!
For your stated needs, I think your solution is getting close to optimal :-) cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
participants (3)
-
Chris Withers -
Ian Beatty -
zope-dev@netchan.cotse.net