我该如何调试Trac插件?

时间:2021-08-18 03:49:09

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.

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

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

我是Python的新手,所以可能没有设置开发环境如何将其配置为调试。

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.

我错过了一些明显的东西吗似乎有点过时了,必须使用打印调试消息到Trac日志,这就是我现在调试的方式。

5 个解决方案

#1


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

您可以创建一个包装器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()

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:

您可以在调试器中运行此脚本,并且可以使用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",
  ))
)

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

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

#2


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.

我们通常不太依赖于调试,因为在Python脚本嵌入较大产品的情况下通常很难做到。

#3


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

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

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

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

#4


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.

Trac包含很好的Python代码示例,使用它作为指导将有助于避免错误。一定要测试你的代码,并且经常这样做,因为你不熟悉Python ......你会发现你不需要调试器。

For unit testing, check out PyUnit.

对于单元测试,请查看PyUnit。

#5


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

我发现在运行时添加那些花哨的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)

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

有时它比之后阅读记录更舒服。虽然它只在您运行的功能具有该req arg时才有效。

#1


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

您可以创建一个包装器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()

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:

您可以在调试器中运行此脚本,并且可以使用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",
  ))
)

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

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

#2


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.

我们通常不太依赖于调试,因为在Python脚本嵌入较大产品的情况下通常很难做到。

#3


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

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

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

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

#4


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.

Trac包含很好的Python代码示例,使用它作为指导将有助于避免错误。一定要测试你的代码,并且经常这样做,因为你不熟悉Python ......你会发现你不需要调试器。

For unit testing, check out PyUnit.

对于单元测试,请查看PyUnit。

#5


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

我发现在运行时添加那些花哨的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)

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

有时它比之后阅读记录更舒服。虽然它只在您运行的功能具有该req arg时才有效。