Example #1
0
def db_exec(host, port, method, *args):
    connection = ServerProxy(host, port)
    logging.getLogger(__name__).info('common.db.%s(None, None, %s)' %
                                     (method, args))
    result = getattr(connection.common.db, method)(None, None, *args)
    logging.getLogger(__name__).debug(repr(result))
    return result
Example #2
0
def login(parameters):
    from tryton import common
    global CONNECTION, _USER
    global _CLIENT_DATE
    host = CONFIG['login.host']
    hostname = common.get_hostname(host)
    port = common.get_port(host)
    database = CONFIG['login.db']
    username = CONFIG['login.login']
    language = CONFIG['client.lang']
    date = CONFIG['login.date']
    connection = ServerProxy(hostname, port, database)
    logging.getLogger(__name__).info('common.db.login(%s, %s, %s)' %
                                     (username, 'x' * 10, language))
    result = connection.common.db.login(username, parameters, language)
    logging.getLogger(__name__).debug(repr(result))
    _USER = result[0]
    session = ':'.join(map(str, [username] + result))
    if CONNECTION is not None:
        CONNECTION.close()
    CONNECTION = ServerPool(hostname,
                            port,
                            database,
                            session=session,
                            cache=not CONFIG['dev'])
    _CLIENT_DATE = date
    bus.listen(CONNECTION)
Example #3
0
def login(parameters):
    from tryton import common
    global CONNECTION, _USER, _USERNAME, _HOST, _PORT, _DATABASE
    global _VIEW_CACHE, _TOOLBAR_CACHE, _KEYWORD_CACHE
    global _CLIENT_DATE
    host = CONFIG['login.host']
    hostname = common.get_hostname(host)
    port = common.get_port(host)
    database = CONFIG['login.db']
    username = CONFIG['login.login']
    language = CONFIG['client.lang']
    date = CONFIG['login.date']
    connection = ServerProxy(hostname, port, database)
    logging.getLogger(__name__).info('common.db.login(%s, %s, %s)' %
                                     (username, 'x' * 10, language))
    result = connection.common.db.login(username, parameters, language)
    logging.getLogger(__name__).debug(repr(result))
    _USER = result[0]
    session = ':'.join(map(str, [username] + result))
    if CONNECTION is not None:
        CONNECTION.close()
    CONNECTION = ServerPool(hostname, port, database, session=session)
    _HOST = host
    _PORT = port
    _DATABASE = database
    _USERNAME = ''
    _CLIENT_DATE = date
    _VIEW_CACHE = {}
    _TOOLBAR_CACHE = {}
    _KEYWORD_CACHE = {}

    bus.listen(CONNECTION)
Example #4
0
def login(host,
          port,
          database,
          username,
          parameters,
          language=None,
          date=None,
          set_date=None):
    global CONNECTION, _USER, _USERNAME, _HOST, _PORT, _DATABASE
    global _VIEW_CACHE, _TOOLBAR_CACHE, _KEYWORD_CACHE
    global _CLIENT_DATE
    connection = ServerProxy(host, port, database)
    logging.getLogger(__name__).info('common.db.login(%s, %s, %s)' %
                                     (username, 'x' * 10, language))
    if set_date:
        _CLIENT_DATE = date
    result = connection.common.db.login(username, parameters, language)
    logging.getLogger(__name__).debug(repr(result))
    _USER = result[0]
    _USERNAME = username
    session = ':'.join(map(str, [username] + result))
    if CONNECTION is not None:
        CONNECTION.close()
    CONNECTION = ServerPool(host, port, database, session=session)
    _HOST = host
    _PORT = port
    _DATABASE = database
    _VIEW_CACHE = {}
    _TOOLBAR_CACHE = {}
    _KEYWORD_CACHE = {}
    IPCServer(host, port, database).run()
Example #5
0
def login(username, password, host, port, database):
    global CONNECTION, _USER, _USERNAME, _SESSION, _HOST, _PORT, _DATABASE
    global _VIEW_CACHE, _TOOLBAR_CACHE, _KEYWORD_CACHE
    _VIEW_CACHE = {}
    _TOOLBAR_CACHE = {}
    _KEYWORD_CACHE = {}
    try:
        _SEMAPHORE.acquire()
        try:
            if CONNECTION is not None:
                CONNECTION.close()
            CONNECTION = ServerProxy(host, port, database)
            logging.getLogger(__name__).info('common.db.login(%s, %s)' %
                (username, 'x' * 10))
            result = CONNECTION.common.db.login(username, password)
            logging.getLogger(__name__).debug(repr(result))
        finally:
            _SEMAPHORE.release()
    except socket.error:
        _USER = None
        _SESSION = ''
        return -1
    if not result:
        _USER = None
        _SESSION = ''
        return -2
    _USER = result[0]
    _USERNAME = username
    _SESSION = result[1]
    _HOST = host
    _PORT = port
    _DATABASE = database
    IPCServer(host, port, database).run()
    return 1
Example #6
0
def server_version(host, port):
    try:
        connection = ServerProxy(host, port)
        logging.getLogger(__name__).info('common.server.version(None, None)')
        result = connection.common.server.version()
        logging.getLogger(__name__).debug(repr(result))
        return result
    except (Fault, socket.error):
        return None
Example #7
0
def db_list(host, port):
    try:
        connection = ServerProxy(host, port)
        logging.getLogger(__name__).info('common.db.list()')
        result = connection.common.db.list()
        logging.getLogger(__name__).debug(repr(result))
        return result
    except Fault as exception:
        logging.getLogger(__name__).debug(exception.faultCode)
        if exception.faultCode == str(HTTPStatus.FORBIDDEN.value):
            return []
        else:
            return None
Example #8
0
def db_list(host, port):
    try:
        connection = ServerProxy(host, port)
        logging.getLogger(__name__).info('common.db.list()')
        result = connection.common.db.list()
        logging.getLogger(__name__).debug(repr(result))
        return result
    except Fault, exception:
        if exception.faultCode == 'AccessDenied':
            logging.getLogger(__name__).debug('AccessDenied')
            return None
        else:
            logging.getLogger(__name__).debug(repr(None))
            return None
Example #9
0
def context_reload():
    global CONTEXT, TIMEZONE, _HOST, _PORT
    try:
        context = execute('model', 'res.user', 'get_preferences', True, {})
    except Fault:
        return
    CONTEXT = {}
    for i in context:
        value = context[i]
        CONTEXT[i] = value
        if i == 'timezone':
            try:
                connection = ServerProxy(_HOST, _PORT)
                TIMEZONE = connection.common.server.timezone_get(None, None)
            except Fault:
                pass