~openbias/bias-trunk/bias-public-trunk

« back to all changes in this revision

Viewing changes to bias_olap/wizard/wizard_test_connection.py

  • Committer: Jose Patricio
  • Date: 2011-10-19 03:16:40 UTC
  • Revision ID: josepato@bias.com.mx-20111019031640-05zd7r5lxwx084qu
el push inicial

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import psycopg2
 
2
 
 
3
import wizard
 
4
import pooler
 
5
import netsvc
 
6
from tools.misc import UpdateableStr, UpdateableDict
 
7
 
 
8
 
 
9
_connection_arch = UpdateableStr()
 
10
 
 
11
def _test_connection(self,cr,uid,part,context={}):
 
12
    lines=pooler.get_pool(cr.dbname).get('olap.fact.database').browse(cr, uid, part['id'],context)
 
13
    host = lines.db_host
 
14
    port = lines.db_port
 
15
    db_name = lines.db_name
 
16
    user = lines.db_login
 
17
    password = lines.db_password
 
18
    type = lines.type
 
19
    return_str = "Connection Successful"
 
20
    try:        
 
21
        if type == 'postgres':
 
22
            tdb = psycopg2.connect('host=%s port=%s dbname=%s user=%s password=%s' % (host, port, db_name, user, password))
 
23
 
 
24
        elif type == 'mysql':
 
25
            import MySQLdb
 
26
            tdb = MySQLdb.connect(host = host,port = port, db = db_name, user = user, passwd = password)
 
27
                
 
28
 
 
29
        elif type == 'oracle':
 
30
            import cx_Oracle
 
31
            tdb = cx_Oracle.connect(user, password, host)
 
32
                
 
33
    except Exception, e:
 
34
            return_str = e.message
 
35
 
 
36
    _arch = ['''<?xml version="1.0"?>''', '''<form string="Connection Status">''']
 
37
    _arch.append('''<label string='%s' />''' % (return_str))
 
38
    _arch.append('''</form>''')
 
39
    _connection_arch.string = '\n'.join(_arch)
 
40
 
 
41
    return {}
 
42
 
 
43
 
 
44
 
 
45
class wizard_test_connection(wizard.interface):
 
46
    states = {
 
47
        'init': {
 
48
            'actions': [_test_connection],
 
49
            'result': {'type':'form', 'arch': _connection_arch, 'fields':{}, 'state':[('end','Ok')]}
 
50
        },
 
51
    }
 
52
wizard_test_connection('olap.fact.database.test_connection')