コード例 #1
0
ファイル: tools.py プロジェクト: esciara/oerpscenario
def impl_backup_database(ctx, dump_directory):
    db_name = ctx.conf.get('db_name')
    if not osp.isdir(dump_directory):
        puts("Invalid Directory")
        raise Exception('Invalid Directory')
    filename = osp.join(dump_directory,
                        "%s_%s.dump" %
                        (db_name,
                         dt.datetime.now().strftime('%Y%m%d_%H%M%S'))
                        )
    cmd = ['pg_dump', '--no-owner', '--compress=9',
           '--format=c', '--file', filename.encode('utf-8')]
    if ctx.conf.get('db_user'):
        cmd += ['--username', ctx.conf.get('db_user')]
    if ctx.conf.get('db_host'):
        cmd += ['--host', ctx.conf.get('db_host')]
    if ctx.conf.get('db_port'):
        cmd += ['--port', str(ctx.conf.get('db_port'))]
    cmd.append(db_name)
    env = os.environ.copy()
    if ctx.conf.get('db_password'):
        env['PGPASSWORD'] = ctx.conf.get('db_password')
    try:
        output = subprocess.check_call(cmd, env=env)
    except subprocess.CalledProcessError:
        raise Exception("Subprocess return %s" % (output))
コード例 #2
0
ファイル: tools.py プロジェクト: esciara/oerpscenario
def impl_backup_database(ctx, dump_directory):
    db_name = ctx.conf.get('db_name')
    if not osp.isdir(dump_directory):
        puts("Invalid Directory")
        raise Exception('Invalid Directory')
    filename = osp.join(
        dump_directory,
        "%s_%s.dump" % (db_name, dt.datetime.now().strftime('%Y%m%d_%H%M%S')))
    cmd = [
        'pg_dump', '--no-owner', '--compress=9', '--format=c', '--file',
        filename.encode('utf-8')
    ]
    if ctx.conf.get('db_user'):
        cmd += ['--username', ctx.conf.get('db_user')]
    if ctx.conf.get('db_host'):
        cmd += ['--host', ctx.conf.get('db_host')]
    if ctx.conf.get('db_port'):
        cmd += ['--port', str(ctx.conf.get('db_port'))]
    cmd.append(db_name)
    env = os.environ.copy()
    if ctx.conf.get('db_password'):
        env['PGPASSWORD'] = ctx.conf.get('db_password')
    try:
        output = subprocess.check_call(cmd, env=env)
    except subprocess.CalledProcessError:
        raise Exception("Subprocess return %s" % (output))
コード例 #3
0
def impl(ctx):
    for row in ctx.table:
        date = datetime.date.today().strftime(row['date'])
        currency = model('res.currency').get([('name', '=', row['currency'])])
        ctype_id = False
        if row['type']:
            ctype = model('res.currency.rate.type').get([('name', '=', row['type'])])
            assert ctype
            ctype_id = ctype.id
        curr_rate = model('res.currency.rate').browse([('name', '=', date),
                                                       ('currency_id', '=', currency.id)])
        if not curr_rate:
            puts('creating new rate')
            values = {'name': date, 'currency_id': currency.id,
                      'rate': row['rate'], 'currency_rate_type_id': ctype_id}
            model('res.currency.rate').create(values)
        else:
            curr_rate[0].rate = row["rate"]
コード例 #4
0
ファイル: tools.py プロジェクト: esciara/oerpscenario
def impl_execute_sql(ctx):
    assert_true(ctx.text)

    cr = get_cursor_from_context(ctx)

    try:
        cr.autocommit(True)
        for command in ctx.text.split(';'):
            sql = command.strip()
            if sql:
                cr.execute(sql)
                puts(cr.statusmessage)
        try:
            ctx.data['return'] = cr.fetchall()
        except Exception:
            # ProgrammingError: no results to fetch
            ctx.data['return'] = []
    finally:
        cr.close()
コード例 #5
0
ファイル: tools.py プロジェクト: esciara/oerpscenario
def impl_execute_sql(ctx):
    assert_true(ctx.text)

    cr = get_cursor_from_context(ctx)

    try:
        cr.autocommit(True)
        for command in ctx.text.split(';'):
            sql = command.strip()
            if sql:
                cr.execute(sql)
                puts(cr.statusmessage)
        try:
            ctx.data['return'] = cr.fetchall()
        except Exception:
            # ProgrammingError: no results to fetch
            ctx.data['return'] = []
    finally:
        cr.close()
コード例 #6
0
def impl(ctx):
    for row in ctx.table:
        date = datetime.date.today().strftime(row['date'])
        currency = model('res.currency').get([('name', '=', row['currency'])])
        ctype_id = False
        if row['type']:
            ctype = model('res.currency.rate.type').get([('name', '=',
                                                          row['type'])])
            assert ctype
            ctype_id = ctype.id
        curr_rate = model('res.currency.rate').browse([('name', '=', date),
                                                       ('currency_id', '=',
                                                        currency.id)])
        if not curr_rate:
            puts('creating new rate')
            values = {
                'name': date,
                'currency_id': currency.id,
                'rate': row['rate'],
                'currency_rate_type_id': ctype_id
            }
            model('res.currency.rate').create(values)
        else:
            curr_rate[0].rate = row["rate"]
コード例 #7
0
def impl(ctx, users):
    puts(['This sentence is deprecated ! Please use "we assign to {users} the groups below" with one "l"'])
    raise Exception ("Sentence Deprecated !")