[Grok-dev] Relative filesystem path?
Jim Washington
jwashin at vt.edu
Sun Sep 16 11:08:19 EDT 2007
Hi, all
I'm working on something like zif.xtemplate in grok.
lxml 2.0 alpha has made huge strides in HTML usefulness, making most of
the zif.xtemplate code redundant, so I am refactoring it for grok.
One thing I need is a location for pure-html templates. The idea is
that the structure of a page (or many pages) may be done as a framework
in an HTML template, and locations for dynamic stuff would be
identified by id attributes. After the page is parsed, the locations
are obtained by lxml.html.get_element_by_id('id') and other lxml.etree
and lxml.html functions can be used to fill out the page. Ultimately
we use lxml's fast serialization to create the page. It's
zope-page-template-less, but existing pagetemplate code can of course be
inserted as the results of viewPageTemplate().
What I have currently in the library package to find the current source
directory relative to the instance is
loc = os.path.abspath(os.curdir)
z = os.path.split(loc)
localpackage = z[-1].lower()
localpath = os.path.join(loc,'src',localpackage)
So
os.path.join(localpath,'html')
should refer to a sibling folder of app_templates in the same directory
as app.py.
It works now on Sample/src/sample as in the tutorial, but changing
directory names so that "sample" is not the lowercase of "Sample", for
example, would break things in the current implementation. I realize
that Grok is about convention over configuration, but is the current
directory structure convention something I can rely on?
Is there a good alternative? Does grok have a hook I can use for this
that would not be so susceptible to breakage? I've looked, but it seems
that the path I need is consumed and made unimportant by martian.
-Jim Washington
More information about the Grok-dev
mailing list