コード例 #1
0
ファイル: testing.py プロジェクト: shalabhaggarwal/nereid
    def init(self):
        from trytond.config import CONFIG
        CONFIG['database_type'] = 'sqlite'
        self.db_name = ':memory:'

        from trytond.backend import Database
        database = Database()
        cursor = database.cursor()
        databases = database.list(cursor)
        cursor.close()

        if self.db_name not in databases:
            from trytond.protocols.dispatcher import create
            create(self.db_name, 'admin', 'en_US', 'admin')


        self.user = 1
        self.context = None

        from trytond.pool import Pool
        from trytond.transaction import Transaction
        with Transaction().start(self.db_name, self.user, self.context) as txn:
            self.pool = Pool(self.db_name)
            self.pool.init()


        self.initialised = True
コード例 #2
0
def install_module(name):
    '''
    Install module for the tested database
    '''
    database = Database().connect()
    cursor = database.cursor()
    databases = database.list(cursor)
    cursor.close()
    if DB_NAME not in databases:
        create(DB_NAME, CONFIG['admin_passwd'], 'en_US', USER_PASSWORD)
    with Transaction().start(DB_NAME, USER,
            context=CONTEXT) as transaction:
        module_obj = POOL.get('ir.module.module')

        module_ids = module_obj.search([
            ('name', '=', name),
            ])
        assert module_ids

        module_ids = module_obj.search([
            ('name', '=', name),
            ('state', '!=', 'installed'),
            ])

        if not module_ids:
            return

        module_obj.install(module_ids)
        transaction.cursor.commit()

        install_upgrade_obj = POOL.get('ir.module.module.install_upgrade',
                type='wizard')
        install_upgrade_obj.transition_upgrade(None)
        transaction.cursor.commit()
コード例 #3
0
ファイル: config.py プロジェクト: ferchuochoa/SIGCoop
    def __init__(self, database_name=None, user='******', database_type=None,
            language='en_US', password='', config_file=None):
        super(TrytondConfig, self).__init__()
        from trytond.config import CONFIG
        CONFIG.update_etc(config_file)
        CONFIG.set_timezone()
        if database_type is not None:
            CONFIG['db_type'] = database_type
        from trytond.pool import Pool
        from trytond import backend
        from trytond.protocols.dispatcher import create
        from trytond.cache import Cache
        from trytond.transaction import Transaction
        self.database_type = CONFIG['db_type']
        if database_name is None:
            if self.database_type == 'sqlite':
                database_name = ':memory:'
            else:
                database_name = 'test_%s' % int(time.time())
        self.database_name = database_name
        self._user = user
        self.config_file = config_file

        Pool.start()

        with Transaction().start(None, 0) as transaction:
            cursor = transaction.cursor
            databases = backend.get('Database').list(cursor)
        if database_name not in databases:
            create(database_name, CONFIG['admin_passwd'], language, password)

        database_list = Pool.database_list()
        self.pool = Pool(database_name)
        if database_name not in database_list:
            self.pool.init()

        with Transaction().start(self.database_name, 0) as transaction:
            Cache.clean(database_name)
            User = self.pool.get('res.user')
            transaction.context = self.context
            self.user = User.search([
                ('login', '=', user),
                ], limit=1)[0].id
            with transaction.set_user(self.user):
                self._context = User.get_preferences(context_only=True)
        Cache.resets(database_name)
コード例 #4
0
def create_db():
    if not db_exist():
        create(None, DB_NAME, None, 'en_US', USER_PASSWORD)
コード例 #5
0
ファイル: test_tryton.py プロジェクト: kret0s/gnuhealth-live
def create_db():
    if not db_exist():
        create(DB_NAME, None, 'en_US', USER_PASSWORD)
コード例 #6
0
    def __init__(self, database_uri=None, user='******', language='en_US',
                 admin_password='',
                 super_pwd=None,
                 config_file=None):
        OrigConfigModule.Config.__init__(self)
        # FixMe: straighten this mess out

        if config_file is None:
            config_file = os.environ.get('TRYTOND_CONFIG')
        assert config_file and os.path.isfile(config_file), \
            "Set the environment variable TRYTOND_CONFIG to the path of TRYTOND CONFIG"

        if not database_uri:
            database_uri = os.environ.get('TRYTOND_DATABASE_URI')
        else:
            os.environ['TRYTOND_DATABASE_URI'] = database_uri
        assert os.path.isfile(config_file), \
            "set os.environ.get('TRYTOND_CONFIG') to be the Tryton config file"

        from trytond.config import config
        config.update_etc(config_file)

        from trytond.pool import Pool
        from trytond import backend
        from trytond.protocols.dispatcher import create
        from trytond.cache import Cache
        from trytond.transaction import Transaction
        self.database = database_uri
        database_name = None
        if database_uri:
            uri = urlparse.urlparse(database_uri)
            database_name = uri.path.strip('/')
        if not database_name:
            assert 'DB_NAME' in os.environ, \
                "Set os.environ['DB_NAME'] to be the database name"
            database_name = os.environ['DB_NAME']
        self.database_name = database_name
        self._user = user
        self.config_file = config_file

        Pool.start()
        if False:
           # new in 3.4
            self.pool = Pool(database_name)
            self.pool.init()
        else:
            # 3.2 code created the database if it did not exist
            with Transaction().start(None, 0) as transaction:
                cursor = transaction.cursor
                databases = backend.get('Database').list(cursor)
            if database_name not in databases:
                # trytond/protocols/dispatcher.py
                '''
                Create a database

                :param database_name: the database name
                :param password: the server password
                :param lang: the default language for the database
                :param admin_password: the admin password
                :return: True if succeed
                '''
                if not super_pwd:
                    sys.stderr.write(
                        "WARN: No super_pwd to create db %s\n" % (database_name,))
                    #! This is NOT the postgres server password
                    #! This calls security.check_super(password)
                    #! which is set in the conf file, [session]super_pwd
                    #! using crypt to generate it from from the command line
                    #! We default it to admin which may also be the
                    #! of the user 'admin': admin_password
                    super_pwd = 'admin'

                assert admin_password, "ERROR: No admin_password to create db " + database_name
                sys.stderr.write(
                    "create %s %s %s %s\n" % (database_name, super_pwd, language, admin_password,))
                create(database_name, super_pwd, language, admin_password)

            database_list = Pool.database_list()
            self.pool = Pool(database_name)
            if database_name not in database_list:
                self.pool.init()

        with Transaction().start(self.database_name, 0) as transaction:
            Cache.clean(database_name)
            User = self.pool.get('res.user')
            transaction.context = self.context
            self.user = User.search([
                ('login', '=', user),
                ], limit=1)[0].id
            with transaction.set_user(self.user):
                self._context = User.get_preferences(context_only=True)
            Cache.resets(database_name)
コード例 #7
0
ファイル: createdb.py プロジェクト: tinavas/FSERP
import FSERP

import trytond
from trytond.config import config

config.update_etc('./FSERP/trytond/etc/trytond.conf')

from trytond.pool import Pool
from trytond.cache import Cache
from trytond.transaction import Transaction
from trytond.protocols import dispatcher


def db_exist(dbname):
    Database = trytond.backend.get('Database')
    database = Database().connect()
    cursor = database.cursor()
    databases = database.list(cursor)
    cursor.close()
    return dbname in databases


if __name__ == '__main__':
    dbname = 'testdb'
    if not db_exist(dbname):
        dispatcher.create(dbname, 'admin', 'en_US', 'root')
        print " db with name %s has been creted with server password admin and admin password root" % (
            dbname)
    else:
        print " db with name %s  already exists" % (dbname)