Dear mobiledreamers, Please stop spamming! If you have a genuine question, post it *only* in the right mailing list. Don't post to so many unrelated mailing lists. If you want to cite a webpage giving a link is sufficient. you don't have to copy and paste the whole content.
Thanks, Anand 2009/6/7 <[email protected]>: > http://stackoverflow.com/questions/919539/how-do-we-precompile-base-templates-in-cheetah-so-that-include-extends-and-im/963546#963546 > > Maybe compile automagically on as needed basis: > > import sys > > import os > > from os import path > > import logging > > from Cheetah.Template import Template > > from Cheetah.Compiler import Compiler > > > log = logging.getLogger(__name__) > > > _import_save = __import__ > > def cheetah_import(name, *args, **kw): > > """Import function which search for Cheetah templates. > > > When template ``*.tmpl`` is found in ``sys.path`` matching module > name (and corresponding generated Python module is outdated or > not existent) it will be compiled prior to actual import. > """ > > name_parts = name.split('.') > > for p in sys.path: > > basename = path.join(p, *name_parts) > > tmpl_path = basename+'.tmpl' > > py_path = basename+'.py' > > if path.exists(tmpl_path): > > log.debug("%s found in %r", name, tmpl_path) > > if not path.exists(py_path) or newer(tmpl_path, py_path): > > log.info("cheetah compile %r -> %r", tmpl_path, py_path) > > output = Compiler( > > file=tmpl_path, > > moduleName=name, > > mainClassName=name_parts[-1], > > ) > > open(py_path, 'wb').write(str(output)) > > break > > return _import_save(name, *args, **kw) > > > def newer(new, old): > > """Whether file with path ``new`` is newer then at ``old``.""" > > return os.stat(new).st_mtime > os.stat(old).st_mtime > > > import __builtin__ > > __builtin__.__import__ = cheetah_import > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web.py" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/webpy?hl=en -~----------~----~----~----~------~----~------~--~---
