#include directive and search paths
Maciej BliziĆski <[email protected]> Fri, 22 Apr 2011 15:43:09 +0100
| Newsgroups | gmane.comp.python.cheetah |
|---|---|
| Message-ID | <[email protected]> |
I have a question about using the #include directive. For example,
the following example works as expected:
echo "foo" > foo.tmpl
echo "#include \"foo.tmpl\"" > bar.tmpl
python -c "from Cheetah.Template import Template; \
t = Template(file='bar.tmpl'); \
print unicode(t)"
However, if the template files are moved to a subdirectory, an
exception is thrown:
mkdir -p subdir
mv *.tmpl subdir
python -c "from Cheetah.Template import Template; \
t = Template(file='subdir/bar.tmpl'); \
print unicode(t)"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/pymodules/python2.6/Cheetah/Template.py", line 981, in __str__
def __str__(self): return getattr(self, mainMethName)()
File "_home_maciej_src_cheetah_test_subdir_bar_tmpl.py", line 86, in respond
File "/usr/lib/pymodules/python2.6/Cheetah/Template.py", line 1511,
in _handleCheetahInclude
nestedTemplateClass = compiler.compile(source=source,file=file)
File "/usr/lib/pymodules/python2.6/Cheetah/Template.py", line 692, in compile
fileHash = str(hash(file))+str(os.path.getmtime(file))
File "/usr/lib/python2.6/genericpath.py", line 54, in getmtime
return os.stat(filename).st_mtime
OSError: [Errno 2] No such file or directory:
'/home/maciej/src/cheetah-test/foo.tmpl'
It looks like Cheetah looks for the template to include in the
process' cwd, instead of the directory containing the original
template. If the template were created from a string or a unicode
object, that would understandable. But Cheetah does know the path to
the template ("subdir") and it's reasonable to assume that this is the
place to look for other templates too.
If there a workaround for this problem?
Maciej
------------------------------------------------------------------------------
Fulfilling the Lean Software Promise
Lean software platforms are now widely adopted and the benefits have been
demonstrated beyond question. Learn why your peers are replacing JEE
containers with lightweight application servers - and what you can gain
from the move. http://p.sf.net/sfu/vmware-sfemails