<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Created on 2013-11-25

@author: <NAME>
'''

import oerplib, sys
import socket

from models.OErpModel import OErpModel

class OpenERP(object):

    def __init__(self, credentials):
        print "Getting connection to {} for {}".format(credentials['db_name'], credentials['user_id'])
	try:
	    oerp = oerplib.OERP(server=credentials['host_name'], protocol='xmlrpc', port=credentials['host_port'])
	    OErpModel.openErpConnection['super'] = oerp
	    if credentials['db_name'] in oerp.db.list():
	        db_connect(credentials['user_id'], credentials['user_pwd'], credentials['db_name'])
	    else:
	        print "There is no database called : {}".format(credentials['db_name'])
	except socket.gaierror:
	    sys.exit("Is this the correct URL : {}".format(credentials['host_name']))
	except socket.error:
	    sys.exit("Is this the correct port number : {}".format(credentials['host_port']))

def db_connect(usr, pwd, db):
    oerp = OErpModel.openErpConnection['super']
    user = oerp.login(user=usr, database=db, passwd=pwd)
    OErpModel.openErpConnection['admin'] = user
    # print " - - {} - - ".format(user)
<commit_msg>pep8 cleanup 	modified:   openerp_utils.py<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Created on 2013-11-25

@author: <NAME>
'''

import oerplib
import sys
import socket

from models.OErpModel import OErpModel


class OpenERP(object):

    def __init__(self, credentials):
        db = credentials['db_name']
        user_id = credentials['user_id']
        host_name = credentials['host_name']
        host_port = credentials['host_port']
        user_pwd = credentials['user_pwd']

        print "Getting connection to {} for {}".format(db, user_id)
        try:
            oerp = oerplib.OERP(
                server=host_name, protocol='xmlrpc', port=host_port)
            OErpModel.openErpConnection['super'] = oerp
            if db in oerp.db.list():
                db_connect(user_id, user_pwd, db)
            else:
                print "There is no database called : {}".format(db)
        except socket.gaierror:
            sys.exit(
                "Is this the correct URL : {}".format(host_name))
        except socket.error:
            sys.exit(
                "Is this the correct port number : {}".format(host_port))


def db_connect(usr, pwd, db):
    oerp = OErpModel.openErpConnection['super']
    user = oerp.login(user=usr, database=db, passwd=<PASSWORD>)
    OErpModel.openErpConnection['admin'] = user
    # print " - - {} - - ".format(user)
{'fraction_non_alphanumeric': 0.14224971008890608, 'fraction_numerical': 0.007344414379590259, 'mean_word_length': 3.082018927444795, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1151857', 'n_tokens_mistral': 873, 'n_tokens_neox': 828, 'n_words': 183}