如何在Trac中运行自己的python脚本
问题描述:
我想定制项目页面(trac/templates/index.html)。如何在Trac中运行自己的python脚本
我想用表格来显示更多的项目特定信息。例如每个项目的管理列表,每个项目的构建状态。这些信息存储在trac的数据库中。
恐怕默认模板引擎不能给我提供信息。至少我从它的文件中找不到任何有价值的东西。
所以我决定写一个python脚本(在服务器端)生成这些信息作为JSON字符串。我还注入了一个块javascript以通过使用Ajax从此python脚本获取JSON。
但我不知道如何让我的python脚本通过trac解释。
任何人都可以帮助我吗?
答
我已经通过在所有trac项目页面的顶部添加iframe
来以更简单的方式定制trac。您可以通过转至trac环境目录中的templates
目录并添加site.html
文件来完成此操作。
我有类似:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:py="http://genshi.edgewall.org/" py:strip="">
<!--! Custom match templates go here -->
<head py:match="head" py:attrs="select('@*')">
${select('*|comment()|text()[local-name()!="script"]')}
<link rel="stylesheet" type="text/css" href="http://mysite.com/nav.css" />
</head>
<body py:match="body" py:attrs="select('@*')">
<iframe src ="http://mysite.com/nav.html"
width="100%"
id="navbar-iframe"
height="30px"
frameborder="0"
marginheight="0"
scrolling="no"
marginwidth="0">
</iframe>
<div id="tdtracbody">
${select('*|text()')}
</div>
</body>
</html>
答
Trac的扩展API允许你任意截取网页和插入新的数据。例如,BatchModifyPlugin拦截请求并将内容添加到自定义查询页面。在http://trac-hacks.org/browser/batchmodifyplugin/0.11/trunk/batchmod/web_ui.py查看ITemplateStreamFilter方法查看Trac Hacks网站了解更多示例。