存在哪些模板系统适合编写服务创建方法
我需要构建一个批量服务创建守护进程,该守护进程可以提供一个数据表,然后创建一组预先固定的服务。然而,服务的类型可能是多种多样的,并且后面的步骤可能需要前面步骤的输出。
看来我需要用某种特定于领域的语言来实现,这样我就可以定义模板配方。然后可以通过模板引擎传递该数据,并在最终运行之前从数据表中进行替换。
重用现有的语言基础设施以允许更复杂的配方使用流程控制并定义一组受限制的基本操作是有意义的。然而,我希望简单的食谱不需要改变语言知识,因为最终用户可能没有软件经验。
我会设想一个简单的模板配方,看起来像这样:
# 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)
conn_c = node_c.terminate_connection(conn_b.output_port, $5, $7)
我建议使用 python 作为基本语言,因为我熟悉它。然而,Python wiki 建议了很多不同的选项(http://wiki.python.org/moin/Templated< /a>),大多数都是针对 HTML/XML 模板解决方案。深入了解不同系统的优缺点将不胜感激。
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)
conn_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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为 Mako 或 Jinja2 都可以满足要求。
I think Mako or Jinja2 both can fit the bill.