mirror of
https://github.com/OCA/server-backend.git
synced 2025-02-18 09:52:42 +02:00
[IMP] Update to v7 menu structure and dos2unix conversion
(../ext rev 366)
This commit is contained in:
committed by
bilbonet
parent
cc52c175f2
commit
058e19d716
2
base_external_dbsource/__init__.py
Executable file → Normal file
2
base_external_dbsource/__init__.py
Executable file → Normal file
@@ -19,6 +19,6 @@
|
|||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
import base_external_dbsource
|
from . import base_external_dbsource
|
||||||
|
|
||||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
# Daniel Reis, 2011
|
# Daniel Reis, 2011
|
||||||
# Additional contributions by Maxime Chambreuil, Savoir-faire Linux
|
# Additional contributions by Maxime Chambreuil, Savoir-faire Linux
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
@@ -21,20 +21,25 @@
|
|||||||
|
|
||||||
{
|
{
|
||||||
'name': 'External Database Sources',
|
'name': 'External Database Sources',
|
||||||
'version': '61.3',
|
'version': '1.3',
|
||||||
'category': 'Tools',
|
'category': 'Tools',
|
||||||
'description': """
|
'description': """
|
||||||
This module allows you to define connections to foreign databases using ODBC,
|
This module allows you to define connections to foreign databases using ODBC,
|
||||||
Oracle Client or SQLAlchemy.
|
Oracle Client or SQLAlchemy.
|
||||||
|
|
||||||
Databases sources can be configured in Settings > Configuration -> Data sources.
|
Database sources can be configured in Settings > Configuration -> Data sources.
|
||||||
|
|
||||||
Depending on the database, you need:
|
Depending on the database, you need:
|
||||||
* to install unixodbc and python-pyodbc packages to use ODBC connections.
|
* to install unixodbc and python-pyodbc packages to use ODBC connections.
|
||||||
* to install FreeTDS driver (tdsodbc package) and configure it through ODBC to
|
* to install FreeTDS driver (tdsodbc package) and configure it through ODBC to
|
||||||
connect to Microsoft SQL Server.
|
connect to Microsoft SQL Server.
|
||||||
* to install and configure Oracle Instant Client and cx_Oracle python library
|
* to install and configure Oracle Instant Client and cx_Oracle python library
|
||||||
to connect to Oracle.
|
to connect to Oracle.
|
||||||
|
|
||||||
|
Contributors
|
||||||
|
============
|
||||||
|
|
||||||
|
* Maxime Chambreuil <maxime.chambreuil@savoirfairelinux.com>
|
||||||
""",
|
""",
|
||||||
'author': 'Daniel Reis',
|
'author': 'Daniel Reis',
|
||||||
'website': 'http://launchpad.net/addons-tko',
|
'website': 'http://launchpad.net/addons-tko',
|
||||||
@@ -44,7 +49,6 @@ Depending on the database, you need:
|
|||||||
'depends': [
|
'depends': [
|
||||||
'base',
|
'base',
|
||||||
],
|
],
|
||||||
'init': [],
|
|
||||||
'data': [
|
'data': [
|
||||||
'base_external_dbsource_view.xml',
|
'base_external_dbsource_view.xml',
|
||||||
'security/ir.model.access.csv',
|
'security/ir.model.access.csv',
|
||||||
@@ -54,7 +58,7 @@ Depending on the database, you need:
|
|||||||
],
|
],
|
||||||
'test': [
|
'test': [
|
||||||
'dbsource_connect.yml',
|
'dbsource_connect.yml',
|
||||||
],
|
],
|
||||||
'installable': True,
|
'installable': True,
|
||||||
'active': False,
|
'active': False,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,67 +20,73 @@
|
|||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from osv import fields, osv
|
import logging
|
||||||
|
from openerp.osv import orm, fields
|
||||||
from openerp.tools.translate import _
|
from openerp.tools.translate import _
|
||||||
import openerp.tools as tools
|
import openerp.tools as tools
|
||||||
import logging
|
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
CONNECTORS = []
|
CONNECTORS = []
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import sqlalchemy
|
import sqlalchemy
|
||||||
import pymssql
|
CONNECTORS.append(('sqlite', 'SQLite'))
|
||||||
CONNECTORS.append( ('mssql', 'Microsoft SQL Server') )
|
try:
|
||||||
|
import pymssql
|
||||||
|
CONNECTORS.append(('mssql', 'Microsoft SQL Server'))
|
||||||
|
except:
|
||||||
|
_logger.info('MS SQL Server not available. Please install "pymssql"\
|
||||||
|
python package.')
|
||||||
|
try:
|
||||||
|
import MySQLdb
|
||||||
|
CONNECTORS.append(('mysql', 'MySQL'))
|
||||||
|
except:
|
||||||
|
_logger.info('MySQL not available. Please install "mysqldb"\
|
||||||
|
python package.')
|
||||||
except:
|
except:
|
||||||
_logger.info('MS SQL Server not available. Please install "slqalchemy" and "pymssql" python package.')
|
_logger.info('SQL Alchemy not available. Please install "slqalchemy"\
|
||||||
|
python package.')
|
||||||
try:
|
|
||||||
import sqlalchemy
|
|
||||||
import MySQLdb
|
|
||||||
CONNECTORS.append( ('mysql', 'MySQL') )
|
|
||||||
except:
|
|
||||||
_logger.info('MySQL not available. Please install "slqalchemy" and "mysqldb" python package.')
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import pyodbc
|
import pyodbc
|
||||||
CONNECTORS.append( ('pyodbc', 'ODBC') )
|
CONNECTORS.append(('pyodbc', 'ODBC'))
|
||||||
except:
|
except:
|
||||||
_logger.info('ODBC libraries not available. Please install "unixodbc" and "python-pyodbc" packages.')
|
_logger.info('ODBC libraries not available. Please install "unixodbc"\
|
||||||
|
and "python-pyodbc" packages.')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import cx_Oracle
|
import cx_Oracle
|
||||||
CONNECTORS.append( ('cx_Oracle', 'Oracle') )
|
CONNECTORS.append(('cx_Oracle', 'Oracle'))
|
||||||
except:
|
except:
|
||||||
_logger.info('Oracle libraries not available. Please install "cx_Oracle" python package.')
|
_logger.info('Oracle libraries not available. Please install "cx_Oracle"\
|
||||||
|
python package.')
|
||||||
|
|
||||||
import psycopg2
|
import psycopg2
|
||||||
CONNECTORS.append( ('postgresql', 'PostgreSQL') )
|
CONNECTORS.append(('postgresql', 'PostgreSQL'))
|
||||||
|
|
||||||
try:
|
|
||||||
import sqlalchemy
|
class base_external_dbsource(orm.Model):
|
||||||
CONNECTORS.append( ('sqlite', 'SQLite') )
|
|
||||||
except:
|
|
||||||
_logger.info('SQLAlchemy not available. Please install "slqalchemy" python package.')
|
|
||||||
|
|
||||||
class base_external_dbsource(osv.osv):
|
|
||||||
_name = "base.external.dbsource"
|
_name = "base.external.dbsource"
|
||||||
_description = 'External Database Sources'
|
_description = 'External Database Sources'
|
||||||
_columns = {
|
_columns = {
|
||||||
'name': fields.char('Datasource name', required=True, size=64),
|
'name': fields.char('Datasource name', required=True, size=64),
|
||||||
'conn_string': fields.text('Connection string', help="""\
|
'conn_string': fields.text('Connection string', help="""
|
||||||
Sample connection strings:
|
Sample connection strings:
|
||||||
- Microsoft SQL Server: mssql+pymssql://username:%s@server:port/dbname?charset=utf8
|
- Microsoft SQL Server:
|
||||||
|
mssql+pymssql://username:%s@server:port/dbname?charset=utf8
|
||||||
- MySQL: mysql://user:%s@server:port/dbname
|
- MySQL: mysql://user:%s@server:port/dbname
|
||||||
- ODBC: DRIVER={FreeTDS};SERVER=server.address;Database=mydb;UID=sa
|
- ODBC: DRIVER={FreeTDS};SERVER=server.address;Database=mydb;UID=sa
|
||||||
- ORACLE: username/%s@//server.address:port/instance
|
- ORACLE: username/%s@//server.address:port/instance
|
||||||
- PostgreSQL: dbname='template1' user='dbuser' host='localhost' port='5432' password=%s
|
- PostgreSQL:
|
||||||
|
dbname='template1' user='dbuser' host='localhost' port='5432' password=%s
|
||||||
- SQLite: sqlite:///test.db
|
- SQLite: sqlite:///test.db
|
||||||
"""),
|
"""),
|
||||||
'password': fields.char('Password' , size=40),
|
'password': fields.char('Password', size=40),
|
||||||
'connector': fields.selection(CONNECTORS, 'Connector', required=True,
|
'connector': fields.selection(CONNECTORS, 'Connector',
|
||||||
help = "If a connector is missing from the list, check the " \
|
required=True,
|
||||||
+ "server log to confirm that the required componentes were detected."),
|
help="If a connector is missing from the\
|
||||||
|
list, check the server log to confirm\
|
||||||
|
that the required components were\
|
||||||
|
detected."),
|
||||||
}
|
}
|
||||||
|
|
||||||
def conn_open(self, cr, uid, id1):
|
def conn_open(self, cr, uid, id1):
|
||||||
@@ -98,24 +104,28 @@ Sample connection strings:
|
|||||||
conn = cx_Oracle.connect(connStr)
|
conn = cx_Oracle.connect(connStr)
|
||||||
elif data.connector == 'pyodbc':
|
elif data.connector == 'pyodbc':
|
||||||
conn = pyodbc.connect(connStr)
|
conn = pyodbc.connect(connStr)
|
||||||
elif data.connector in ('sqlite','mysql','mssql'):
|
elif data.connector in ('sqlite', 'mysql', 'mssql'):
|
||||||
conn = sqlalchemy.create_engine(connStr).connect()
|
conn = sqlalchemy.create_engine(connStr).connect()
|
||||||
elif data.connector == 'postgresql':
|
elif data.connector == 'postgresql':
|
||||||
conn = psycopg2.connect(connStr)
|
conn = psycopg2.connect(connStr)
|
||||||
|
|
||||||
return conn
|
return conn
|
||||||
|
|
||||||
def execute(self, cr, uid, ids, sqlquery, sqlparams=None, metadata=False, context=None):
|
def execute(self, cr, uid, ids, sqlquery, sqlparams=None, metadata=False,
|
||||||
"""Executes SQL and returns a list of rows.
|
context=None):
|
||||||
|
"""Executes SQL and returns a list of rows.
|
||||||
"sqlparams" can be a dict of values, that can be referenced in the SQL statement
|
|
||||||
using "%(key)s" or, in the case of Oracle, ":key".
|
"sqlparams" can be a dict of values, that can be referenced in
|
||||||
Example:
|
the SQL statement using "%(key)s" or, in the case of Oracle,
|
||||||
sqlquery = "select * from mytable where city = %(city)s and date > %(dt)s"
|
":key".
|
||||||
params = {'city': 'Lisbon', 'dt': datetime.datetime(2000, 12, 31)}
|
Example:
|
||||||
|
sqlquery = "select * from mytable where city = %(city)s and
|
||||||
If metadata=True, it will instead return a dict containing the rows list and the columns list,
|
date > %(dt)s"
|
||||||
in the format:
|
params = {'city': 'Lisbon',
|
||||||
|
'dt': datetime.datetime(2000, 12, 31)}
|
||||||
|
|
||||||
|
If metadata=True, it will instead return a dict containing the
|
||||||
|
rows list and the columns list, in the format:
|
||||||
{ 'cols': [ 'col_a', 'col_b', ...]
|
{ 'cols': [ 'col_a', 'col_b', ...]
|
||||||
, 'rows': [ (a0, b0, ...), (a1, b1, ...), ...] }
|
, 'rows': [ (a0, b0, ...), (a1, b1, ...), ...] }
|
||||||
"""
|
"""
|
||||||
@@ -123,19 +133,21 @@ Sample connection strings:
|
|||||||
rows, cols = list(), list()
|
rows, cols = list(), list()
|
||||||
for obj in data:
|
for obj in data:
|
||||||
conn = self.conn_open(cr, uid, obj.id)
|
conn = self.conn_open(cr, uid, obj.id)
|
||||||
if obj.connector in ["sqlite","mysql","mssql"]:
|
if obj.connector in ["sqlite", "mysql", "mssql"]:
|
||||||
#using sqlalchemy
|
#using sqlalchemy
|
||||||
cur = conn.execute(sqlquery, sqlparams)
|
cur = conn.execute(sqlquery, sqlparams)
|
||||||
if metadata: cols = cur.keys()
|
if metadata:
|
||||||
|
cols = cur.keys()
|
||||||
rows = [r for r in cur]
|
rows = [r for r in cur]
|
||||||
else:
|
else:
|
||||||
#using other db connectors
|
#using other db connectors
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
cur.execute(sqlquery, sqlparams)
|
cur.execute(sqlquery, sqlparams)
|
||||||
if metadata: cols = [d[0] for d in cur.description]
|
if metadata:
|
||||||
|
cols = [d[0] for d in cur.description]
|
||||||
rows = cur.fetchall()
|
rows = cur.fetchall()
|
||||||
conn.close()
|
conn.close()
|
||||||
if metadata:
|
if metadata:
|
||||||
return{'cols': cols, 'rows': rows}
|
return{'cols': cols, 'rows': rows}
|
||||||
else:
|
else:
|
||||||
return rows
|
return rows
|
||||||
@@ -146,14 +158,18 @@ Sample connection strings:
|
|||||||
try:
|
try:
|
||||||
conn = self.conn_open(cr, uid, obj.id)
|
conn = self.conn_open(cr, uid, obj.id)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
raise osv.except_osv(_("Connection test failed!"), _("Here is what we got instead:\n %s") % tools.ustr(e))
|
raise orm.except_orm(_("Connection test failed!"),
|
||||||
|
_("Here is what we got instead:\n %s")
|
||||||
|
% tools.ustr(e))
|
||||||
finally:
|
finally:
|
||||||
try:
|
try:
|
||||||
if conn: conn.close()
|
if conn:
|
||||||
|
conn.close()
|
||||||
except Exception:
|
except Exception:
|
||||||
# ignored, just a consequence of the previous exception
|
# ignored, just a consequence of the previous exception
|
||||||
pass
|
pass
|
||||||
#TODO: if OK a (wizard) message box should be displayed
|
#TODO: if OK a (wizard) message box should be displayed
|
||||||
raise osv.except_osv(_("Connection test succeeded!"), _("Everything seems properly set up!"))
|
raise orm.except_orm(_("Connection test succeeded!"),
|
||||||
|
_("Everything seems properly set up!"))
|
||||||
base_external_dbsource()
|
|
||||||
|
#EOF
|
||||||
|
|||||||
0
base_external_dbsource/base_external_dbsource_demo.xml
Executable file → Normal file
0
base_external_dbsource/base_external_dbsource_demo.xml
Executable file → Normal file
@@ -9,7 +9,7 @@
|
|||||||
<field name="model">base.external.dbsource</field>
|
<field name="model">base.external.dbsource</field>
|
||||||
<field name="type">tree</field>
|
<field name="type">tree</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<tree>
|
<tree string="External DB Sources">
|
||||||
<field name="name"/>
|
<field name="name"/>
|
||||||
<field name="connector"/>
|
<field name="connector"/>
|
||||||
<field name="conn_string"/>
|
<field name="conn_string"/>
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
<field name="model">base.external.dbsource</field>
|
<field name="model">base.external.dbsource</field>
|
||||||
<field name="type">form</field>
|
<field name="type">form</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<form>
|
<form string="External DB Source">
|
||||||
<field name="name"/>
|
<field name="name"/>
|
||||||
<field name="password" password="True"/>
|
<field name="password" password="True"/>
|
||||||
<newline/>
|
<newline/>
|
||||||
@@ -45,7 +45,7 @@
|
|||||||
|
|
||||||
<menuitem name="Database Sources"
|
<menuitem name="Database Sources"
|
||||||
id="menu_dbsource"
|
id="menu_dbsource"
|
||||||
parent="base.next_id_15"
|
parent="base.next_id_9"
|
||||||
action="action_dbsource"/>
|
action="action_dbsource"/>
|
||||||
|
|
||||||
</data>
|
</data>
|
||||||
|
|||||||
0
base_external_dbsource/security/ir.model.access.csv
Executable file → Normal file
0
base_external_dbsource/security/ir.model.access.csv
Executable file → Normal file
0
base_external_dbsource/test/dbsource_connect.yml
Executable file → Normal file
0
base_external_dbsource/test/dbsource_connect.yml
Executable file → Normal file
Reference in New Issue
Block a user