开发者

What template systems exist suitable for writing service creation recipies

I have a requirement to build a bulk service creation daemon that can be fed a table of data and then go off and create a set of pre-canned services. However the type of services are potentially many and varied and potentially later steps will require the output of previous steps.

It seems what I need to implement in some sort of domain specific language that allow me to define a template recipe. This can then be passed through a template engine with substitutions made from the table of data before finally being run.

It would make sense to re-use an existing language infrastructure to allow the more complex recipes to use flow control and to define a restricted set of base operations. However I'd like the simple recipes to not require knowledge of the language to alter as the end users will not likely have software experience.

I would envision a simple template recipe looking something like:

# Create a service from NodeA to NodeC via NodeB
# Parameters are:
#   node a id, node a port, node b id, node c id, node c port, comment
node_a = node_a_type($1)
conn_a = node_a.create_connection($2, $7)
node_b = node_b_type($3)
conn_b = node_b.create_connection(conn_a.output_port, $7)
node_c = node_c_type($4)
con开发者_开发问答n_c = node_c.terminate_connection(conn_b.output_port, $5, $7)

I suggest python as a base language as I'm familiar with it. However the Python wiki suggests a lot of different options (http://wiki.python.org/moin/Templating) with most being aimed HTML/XML template solutions. Insight into the pros and cons of different systems would be appreciated.


I think Mako or Jinja2 both can fit the bill.

  • Both are not html/xml templates but are text based.
  • Both are popular and well documented.
  • Mako has more pythonic syntax where as BIG advantage with Jinja is, it supports sandboxing which might be useful for you.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜