[Zope] - HTMLFile-like class that heeds DTML mod time

skip@calendar.com (Skip Montanaro) skip@calendar.com (Skip Montanaro)
Wed, 13 Jan 1999 21:56:29 -0500


I got tired of having to restart my ZopeHTTPServer every time I twiddled a
DTML file used by a published object, so I wrote the following simple class
that checks the mod time of the DTML file when it's called, and recreates
its HTMLFile instance if necessary.  I instantiate it instead of HTMLFile.

    class Template:
        def __init__(self, file):
            self.file = file
            self.template = DocumentTemplate.HTMLFile(self.file)
            self.ftime = os.stat(self.file)[stat.ST_MTIME]

        def __call__(self, *args, **kargs):
            ftime = os.stat(self.file)[stat.ST_MTIME]
            if self.ftime < ftime:
                self.ftime = ftime
                self.template = DocumentTemplate.HTMLFile(self.file)
            return apply(self.template.__call__, args, kargs)

I'm sure there's probably a simple way to integrate this into
DocumentTemplate.HTMLFile directly, but this seemed easier to me, what with
the mixins and such that are used in DocumentTemplates, and all I really
need are __init__ and __call__ methods.

Consider this a feature request (I also submitted it to the Zope web site.)

Skip Montanaro	   | Mojam: "Uniting the World of Music" http://www.mojam.com/
skip@calendar.com  | Musi-Cal: http://concerts.calendar.com/
518-372-5583