Exemplo n.º 1
0
def export(ctx, language, db_name, module, fix):
    modules = module or ['all']

    from odoo.modules.registry import Registry
    from odooku.api import environment
    from odoo.tools import trans_export

    with tempfile.TemporaryFile() as t:

        # Perform checks (and possible fixes)
        registry = Registry(db_name)
        with registry.cursor() as cr:
            with environment(cr) as env:
                lang = env['res.lang'].with_context(
                    dict(active_test=False)).search([('code', '=', language)])
                if not lang:
                    raise ValueError("Language %s does not exist" % language)
                if not lang[0].active:
                    if not fix:
                        raise ValueError("Language %s is not activated" %
                                         language)
                    else:
                        installed = env['ir.module.module'].search([
                            ('state', '=', 'installed')
                        ])
                        installed._update_translations(language)

                if module:
                    installed = env['ir.module.module'].search([
                        ('name', 'in', module), ('state', '=', 'installed')
                    ])
                    missing = set(module) - set(
                        [mod.name for mod in installed])
                    if missing:
                        if not fix:
                            raise ValueError("Modules '%s' are not installed" %
                                             ", ".join(missing))
                        else:
                            ctx.obj['config']['init'] = {
                                module_name: 1
                                for module_name in module
                            }

        # Export
        registry = Registry.new(db_name, update_module=fix)
        with registry.cursor() as cr:
            with environment(cr) as env:
                trans_export(language, modules, t, 'po', cr)

        t.seek(0)
        # Pipe to stdout
        while True:
            chunk = t.read(CHUNK_SIZE)
            if not chunk:
                break
            sys.stdout.buffer.write(chunk)
Exemplo n.º 2
0
def newdbuuid(ctx, db_name):
    config = (ctx.obj['config'])

    from odoo.modules.registry import Registry
    from odooku.api import environment

    registry = Registry(db_name)
    with registry.cursor() as cr:
        with environment(cr) as env:
            env['ir.config_parameter'].init(force=True)
Exemplo n.º 3
0
def shell(ctx, input_file, db_name):
    from odoo.modules.registry import RegistryManager
    from odooku.api import environment
    registry = RegistryManager.get(db_name)

    with registry.cursor() as cr:
        with environment(cr) as env:
            context = {'env': env, 'self': env.user}

            args = []
            if input_file is not None:
                args = [input_file]

            bpython.embed(context, args=args, banner='Odooku shell')
Exemplo n.º 4
0
def update(ctx, db_name, module, language, overwrite):
    context = {'overwrite': overwrite}

    from odoo.modules.registry import Registry
    from odooku.api import environment

    domain = [('state', '=', 'installed')]
    if module:
        domain = [('name', 'in', module)]

    for db in db_name:
        registry = Registry(db)
        with registry.cursor() as cr:
            with environment(cr) as env:
                mods = env['ir.module.module'].search(domain)
                mods.with_context(
                    overwrite=overwrite)._update_translations(language)
Exemplo n.º 5
0
    def import_(self, fp, fake=False):
        with self._registry.cursor() as cr:
            with environment(cr) as env:
                context = SerializationContext(
                    env,
                    strict=self._strict,
                    config=self._config
                )

                try:
                    cr.execute('SAVEPOINT import_save')
                    for entry in ijson.items(fp, 'item'):
                        id = entry.pop('__id__')
                        model_name = entry.pop('__model__')
                        with context.new_entry(model_name, id) as entry_context:
                            self._deserialize_entry(entry, entry_context)
                except Exception:
                    cr.execute('ROLLBACK TO SAVEPOINT import_save')
                    raise

                if fake:
                    cr.execute('ROLLBACK TO SAVEPOINT import_save')
Exemplo n.º 6
0
def import_(ctx, language, db_name, overwrite):
    context = {'overwrite': overwrite}

    from odoo.modules.registry import Registry
    from odooku.api import environment
    from odoo.tools import trans_load

    with tempfile.NamedTemporaryFile(suffix='.po', delete=False) as t:
        registry = Registry(db_name)

        # Read from stdin
        while True:
            chunk = sys.stdin.buffer.read(CHUNK_SIZE)
            if not chunk:
                break
            t.write(chunk)
        t.close()

        with registry.cursor() as cr:
            with environment(cr) as env:
                trans_load(cr, t.name, language, context=context)

        os.unlink(t.name)
Exemplo n.º 7
0
    def export(self, fp):
        self._begin_write(fp)
        with self._registry.cursor() as cr:
            with environment(cr) as env:

                context = SerializationContext(env,
                                               strict=self._strict,
                                               link=self._link,
                                               config=self._config)

                # Get models to export
                models = [
                    model_name
                    for model_name in context.serializers.iterkeys()
                    if not (match_any(model_name, self._config.excludes) or (
                        self._config.includes
                        and not match_any(model_name, self._config.includes)))
                ]

                _logger.info("Serializing %s models" % len(models))
                for (model_name, id, values) in self.iterator(models, context):
                    self._write(model_name, id, values)

            self._end_write()