Exemple #1
0
def new_dump_db(db_name, stream, backup_format='zip', anonymized=True):
    if anonymized:
        with RegistryManager.new(db_name).cursor() as cr:
            env = api.Environment(cr, SUPERUSER_ID, {})
            anon_query = env['ir.model.fields'].get_anonymization_query()
        if not anon_query:
            db._logger.info("No data to anonymize in database `%s`.", db_name)
        else:
            db._logger.info('Anonymize and dump database `%s`.', db_name)
            anon_db_name = '%s_anon_%s' % (db_name,
                                           time.strftime('%Y%m%d_%H%M%S'))
            db.exp_duplicate_database(db_name, anon_db_name)
            try:
                if backup_format == 'zip':
                    # To avoid to archive filestore
                    # with non-anonymized attachments
                    anon_fs = tools.config.filestore(anon_db_name)
                    shutil.rmtree(anon_fs, ignore_errors=True)
                with RegistryManager.new(anon_db_name).cursor() as cr:
                    db._logger.info('ANONYMIZE DB: %s', anon_db_name)
                    cr.execute(anon_query)
            except Exception:
                db.exp_drop(anon_db_name)
            return NewDbDump(anon_db_name, stream, backup_format)
    return native_dump_db(db_name, stream, backup_format)
Exemple #2
0
 def _update_registry(self):
     """ Update the registry after a modification on action rules. """
     if self.env.registry.ready:
         # for the sake of simplicity, simply force the registry to reload
         self._cr.commit()
         self.env.reset()
         RegistryManager.new(self._cr.dbname)
         RegistryManager.signal_registry_change(self._cr.dbname)
Exemple #3
0
 def runtests():
     registry = RegistryManager.new(db_name)
     total = (registry._assertion_report.successes +
              registry._assertion_report.failures)
     failures = registry._assertion_report.failures
     logger.info("Completed (%s) tests. %s failures." % (total, failures))
     sys.exit(1 if failures else 0)
 def __enter__(self):
     """
     Context enter function.
     Temporarily add odoo 10 server path to system path and pop afterwards.
     Import odoo 10 server from path as library.
     Init logger, registry and environment.
     Add addons path to config.
     :returns Odoo10Context: This instance
     """
     sys.path.append(self.server_path)
     from odoo import netsvc, api
     from odoo.modules.registry import RegistryManager
     from odoo.tools import trans_export, config, trans_load_data
     self.trans_export = trans_export
     self.trans_load_data = trans_load_data
     sys.path.pop()
     netsvc.init_logger()
     config['addons_path'] = (
         config.get('addons_path') + ',' + self.addons_path
     )
     registry = RegistryManager.new(self.dbname)
     self.environment_manage = api.Environment.manage()
     self.environment_manage.__enter__()
     self.cr = registry.cursor()
     return self
Exemple #5
0
def preload(ctx, db_name, module, demo_data):
    config = (
        ctx.obj['config']
    )

    from odoo.modules.registry import RegistryManager

    if module:
        modules = {
            module_name: 1
            for module_name in module
        }
        config['init'] = dict(modules)

    registry = RegistryManager.new(db_name, force_demo=demo_data, update_module=True)
Exemple #6
0
def update(ctx, db_name, module):
    config = (
        ctx.obj['config']
    )

    from odoo.modules.registry import RegistryManager

    module = module or ['all']
    modules = {
        module_name: 1
        for module_name in module
    }

    config['update'] = dict(modules)
    for db in db_name:
        registry = RegistryManager.new(db, update_module=True)
Exemple #7
0
 def __enter__(self):
     """
     Context enter function.
     Temporarily add odoo 8 server path to system path and pop afterwards.
     Import odoo 8 server from path as library.
     Init logger, registry and environment.
     Add addons path to config.
     :returns Odoo8Context: This instance
     """
     sys.path.append(self.server_path)
     from openerp import netsvc, api
     from openerp.modules.registry import RegistryManager
     from openerp.tools import trans_export, config
     self.trans_export = trans_export
     sys.path.pop()
     netsvc.init_logger()
     config['addons_path'] = (config.get('addons_path') + ',' +
                              self.addons_path)
     registry = RegistryManager.new(self.dbname)
     self.environment_manage = api.Environment.manage()
     self.environment_manage.__enter__()
     self.cr = registry.cursor()
     return self