我应该如何调试 Trac 插件?

发布于 2024-07-22 17:37:36 字数 239 浏览 7 评论 0原文

我即将开始大量工作来扩展 Trac 以满足我们的业务需求。 到目前为止,我已经使用 pythonWin 和 Netbeans 6.5 作为开发环境 - 这些似乎都没有提供任何调试我正在开发的插件的方法。

我对 Python 完全陌生,所以可能还没有设置开发环境,如何配置它以进行调试。

我错过了一些明显的东西吗? 必须诉诸于将调试消息打印到 Trac 日志似乎有点过时,这就是我目前调试的方式。

I'm about to start a fair amount of work extending Trac to fit our business requirements.
So far I've used pythonWin and now Netbeans 6.5 as the development environments - neither of these seem to provide any way of debugging the plugin I am working on.

I'm totally new to Python so probably have not set up the development environment how it could be congfigured to get it debugging.

Am I missing something obvious? It seems a bit archaic to have to resort to printing debug messages to the Trac log, which is how I'm debugging at the moment.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

长亭外,古道边 2024-07-29 17:37:36

您可以创建包装器 wsgi 脚本并在调试器中运行它。 例如:

import os
import trac.web.main

os.environ['TRAC_ENV'] = '/path/to/your/trac/env'

application = trac.web.main.dispatch_request

from flup.server.fcgi import WSGIServer
server = WSGIServer(application, bindAddress=("127.0.0.1", 9000), )
server.run()

您可以在调试器中运行此脚本,并且可以使用lighttpd作为Web应用程序的前端,并通过如下简单配置:

server.document-root = "/path/to/your/trac/env"
server.port = 1234
server.modules = ( "mod_fastcgi" )
server.pid-file = "/path/to/your/trac/env/httpd.pid"
server.errorlog = "/path/to/your/trac/env/error.log"
fastcgi.server = ( "/" =>
  (( "host" => "127.0.0.1",
     "port" => 9000,
     "docroot" => "/",
     "check-local" => "disable",
  ))
)

只需在调试器中运行fcgi wsgi包装器,在插件中设置断点,然后打开网页。

You can create a wrapper wsgi script and run it in a debugger. For example:

import os
import trac.web.main

os.environ['TRAC_ENV'] = '/path/to/your/trac/env'

application = trac.web.main.dispatch_request

from flup.server.fcgi import WSGIServer
server = WSGIServer(application, bindAddress=("127.0.0.1", 9000), )
server.run()

You would run this script in the debugger, and you can use lighttpd as a frontend for the web application with a trivial config like this one:

server.document-root = "/path/to/your/trac/env"
server.port = 1234
server.modules = ( "mod_fastcgi" )
server.pid-file = "/path/to/your/trac/env/httpd.pid"
server.errorlog = "/path/to/your/trac/env/error.log"
fastcgi.server = ( "/" =>
  (( "host" => "127.0.0.1",
     "port" => 9000,
     "docroot" => "/",
     "check-local" => "disable",
  ))
)

Just run the fcgi wsgi wrapper in the debugger, set the breakpoints in your plugin, and open the web page.

鲸落 2024-07-29 17:37:36

通常,我们首先进行单元测试。

然后,我们编写日志消息来诊断问题。

我们通常不会严重依赖调试,因为在 Python 脚本嵌入到较大产品中的情况下通常很难做到这一点。

Usually, we unit test first.

Then, we write log messages to diagnose problems.

We generally don't depend heavily on debugging because it's often hard to do in situations where Python scripts are embedded in a larger product.

乱了心跳 2024-07-29 17:37:36

我发现 Winpdb 是一个不错的 python 调试器。

但正如 S.Lott 指出的那样,当您的项目嵌入到较大的项目中时,调试器可能对您没有多大用处。

I've found that Winpdb is a decent python debugger.

But as S.Lott points out, debuggers may not be very useful to you when your project is embedded within a larger one.

ぽ尐不点ル 2024-07-29 17:37:36

Trac 包含很好的 Python 代码示例,使用它作为指南将有助于避免错误。 只要确保测试你的代码,并且经常这样做,因为你是 Python 新手......你会发现你不需要调试器。

对于单元测试,请查看 PyUnit

Trac contains good examples of Python code, using it as a guideline will help avoid bugs. Just be sure to test your code, and do it often since you are new to Python... You'll find you don't need a debugger.

For unit testing, check out PyUnit.

定格我的天空 2024-07-29 17:37:36

我发现在运行时添加那些奇特的 Trac 消息框作为调试帮助或跟踪是最有用的,就像这样:

from trac.web.chrome import add_notice
...
def any_function_somewhere(self, req, ...anyother args...):
    ...
    var = ...some value...
    add_notice(req, "my variable value I am tracing %s" % var)

有时它比事后阅读日志记录更舒服。 尽管它仅在您运行的函数具有该 req 参数时才有效。

I found it most useful to add those fancy Trac messageboxes at runtime as debugging help or tracing, just like this:

from trac.web.chrome import add_notice
...
def any_function_somewhere(self, req, ...anyother args...):
    ...
    var = ...some value...
    add_notice(req, "my variable value I am tracing %s" % var)

Sometimes it's more comfortable than reading logging afterwards. Though it only works if the function you're running has that req arg.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文