使用 Eclipse Pydev 调试 GreenOdoo for Windows

參考

http://buke.github.io/blog/2013/06/27/using-eclipse-pydev-to-debug-green-openerp-for-windows/

安裝Pydev

打开eclipse 后,点击菜单 “help” -> “Install New Software”, 

输入 “http://pydev.org/updates” 刷新后选择 pydev 安装即可。)

下载并解压GreenOdoo

扫描二维码关注公众号,回复: 621870 查看本文章

下载地址: https://github.com/buke/GreenOdoo/archive/master-win32.zip

解壓位置: D:\python_workspace\GreenOdoo-win32

环境配置

增加文件.project:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
	<name>GreenOdoo-win32</name>
	<comment></comment>
	<projects>
	</projects>
	<buildSpec>
		<buildCommand>
			<name>org.python.pydev.PyDevBuilder</name>
			<arguments>
			</arguments>
		</buildCommand>
	</buildSpec>
	<natures>
		<nature>org.python.pydev.pythonNature</nature>
	</natures>
</projectDescription>

增加文件start-pg.bat:

title GreenOdoo - www.GreenOpenERP.com
COLOR 0A
SET PATH=%CD%\runtime\pgsql\bin;%CD%\runtime\python;%CD%\runtime\win32\wkhtmltopdf;%PATH%.
%CD%\runtime\pgsql\bin\pg_ctl -D %CD%\runtime\pgsql\data -l %CD%\runtime\pgsql\logfile start

增加文件stop-pg.bat:

title GreenOdoo - www.GreenOpenERP.com
COLOR 0A
%CD%\runtime\pgsql\bin\pg_ctl -D %CD%\runtime\pgsql\data -l %CD%\runtime\pgsql\logfile --silent --mode fast
%CD%\runtime\bin\pv.exe -f -k postgres.exe -q

配置 pydev

打开 eclipse , 选择菜单 “Window” -> “Preferences”

点击 pydev,选择 Interpreter - Python , 如有旧的Interpreter 请先删除。

点击 New ,在弹出的窗口中 Browse 到下载解压的 D:\python_workspace\GreenOdoo-win32\runtime\python\python.exe

选择 Select All, 然后点击 OK

回到刚才窗口, python interpreters 的相关参数应已配好。点击 Apply 后,点 Ok

选择 pydev 开发界面

Eclipse 默认是 java 开发界面,点击右上角的小图表,在弹出的窗口选择 pydev

导入 GreenOdoo Project

在 Package Explorer 界面内点击右键,在弹出的菜单里选择 Import

选择 Existing Project into Workspace 后,点 Next

点击 Browse 后,选择解压后的 GreenOdoo 文件夹, 随后点击 Finish

正常运行(非调试)和关闭 GreenOpenERP

运行 start.bat 和 stop.bat .

调试启动 Postgresql

运行 GreenOdoo 文件夹的 start-pg.bat 启动 pg 数据库。(关闭pg 数据库则运行 stop-pg.bat)

启动调试odoo

在相应文件设置好断点后(也可不设置断点),

在 eclipse 的 Package Explorer 界面右键点击 source\odoo.py,在弹出菜单选择 Debug As -> Python Run

2014-06-13 16:36:13,878 2212 INFO ? openerp: OpenERP version 8.0alpha1
2014-06-13 16:36:13,878 2212 INFO ? openerp: addons paths: [u'C:\\Users\\whz\\AppData\\Local\\OpenERP S.A.\\OpenERP\\addons\\8.0', u'D:\\python_workspace\\GreenOdoo-win32\\source\\openerp\\addons', u'D:\\python_workspace\\GreenOdoo-win32\\source\\addons']
2014-06-13 16:36:13,878 2212 INFO ? openerp: database hostname: localhost
2014-06-13 16:36:13,878 2212 INFO ? openerp: database port: 5432
2014-06-13 16:36:13,878 2212 INFO ? openerp: database user: whz
2014-06-13 16:36:14,233 2212 INFO ? openerp.service.server: HTTP service (werkzeug) running on 0.0.0.0:8069
2014-06-13 16:37:30,673 2212 INFO ? openerp.addons.report.models.report: You need wkhtmltopdf to print a pdf version of the reports.
2014-06-13 16:37:30,976 2212 WARNING ? openerp.addons.website_event.controllers.main: Please install GeoIP python module to use events localisation.
2014-06-13 16:37:31,141 2212 INFO ? openerp.http: HTTP Configuring static files
2014-06-13 16:37:33,200 2212 ERROR None openerp.sql_db: Connection to the database failed
Traceback (most recent call last):
  File "D:\python_workspace\GreenOdoo-win32\source\openerp\sql_db.py", line 502, in borrow
    result = psycopg2.connect(dsn=dsn, connection_factory=PsycoConnection)
  File "D:\python_workspace\GreenOdoo-win32\runtime\python\lib\site-packages\psycopg2\__init__.py", line 178, in connect
    return _connect(dsn, connection_factory=connection_factory, async=async)
OperationalError: could not connect to server: Connection refused (0x0000274D/10061)
	Is the server running on host "localhost" (::1) and accepting
	TCP/IP connections on port 5432?
could not connect to server: Connection refused (0x0000274D/10061)
	Is the server running on host "localhost" (127.0.0.1) and accepting
	TCP/IP connections on port 5432?

2014-06-13 16:37:33,220 2212 ERROR None openerp.http: could not connect to server: Connection refused (0x0000274D/10061)
	Is the server running on host "localhost" (::1) and accepting
	TCP/IP connections on port 5432?
could not connect to server: Connection refused (0x0000274D/10061)
	Is the server running on host "localhost" (127.0.0.1) and accepting
	TCP/IP connections on port 5432?
Traceback (most recent call last):
  File "D:\python_workspace\GreenOdoo-win32\source\openerp\http.py", line 92, in dispatch_rpc
    result = dispatch(method, params)
  File "D:\python_workspace\GreenOdoo-win32\source\openerp\service\db.py", line 79, in dispatch
    return fn(*params)
  File "D:\python_workspace\GreenOdoo-win32\source\openerp\service\db.py", line 362, in exp_list
    with closing(db.cursor()) as cr:
  File "D:\python_workspace\GreenOdoo-win32\source\openerp\sql_db.py", line 546, in cursor
    return Cursor(self.__pool, self.dbname, serialized=serialized)
  File "D:\python_workspace\GreenOdoo-win32\source\openerp\sql_db.py", line 177, in __init__
    self._cnx = pool.borrow(dsn(dbname))
  File "D:\python_workspace\GreenOdoo-win32\source\openerp\sql_db.py", line 439, in _locked
    return fun(self, *args, **kwargs)
  File "D:\python_workspace\GreenOdoo-win32\source\openerp\sql_db.py", line 502, in borrow
    result = psycopg2.connect(dsn=dsn, connection_factory=PsycoConnection)
  File "D:\python_workspace\GreenOdoo-win32\runtime\python\lib\site-packages\psycopg2\__init__.py", line 178, in connect
    return _connect(dsn, connection_factory=connection_factory, async=async)
OperationalError: could not connect to server: Connection refused (0x0000274D/10061)
	Is the server running on host "localhost" (::1) and accepting
	TCP/IP connections on port 5432?
could not connect to server: Connection refused (0x0000274D/10061)
	Is the server running on host "localhost" (127.0.0.1) and accepting
	TCP/IP connections on port 5432?

问题解决

将openerp-server.conf文件拷贝到source目录下,修改参数root_path、addons_path如下:

pg_path = ../runtime/pgsql/bin
addons_path = addons

注意事项

调试前需运行 start-pg.bat 启动数据库。

如需关闭数据库,请运行 stop-pg.bat 关闭。切勿直接关闭cmd窗口。

猜你喜欢

转载自wuhuizhong.iteye.com/blog/2079541