def unlink(self, cr, user, ids, context=None): for model in self.browse(cr, user, ids, context): if model.state != "manual": raise except_orm(_("Error"), _("You can not remove the model '%s' !") % (model.name,)) res = super(ir_model, self).unlink(cr, user, ids, context) pooler.restart_pool(cr.dbname) return res
def unlink(self, cr, user, ids, context=None): for model in self.browse(cr, user, ids, context): if model.state != 'manual': raise except_orm(_('Error'), _("You can not remove the model '%s' !") %(model.name,)) res = super(ir_model, self).unlink(cr, user, ids, context) pooler.restart_pool(cr.dbname) return res
def execute(self, cr, uid, ids, context=None): modules = self.pool.get('ir.module.module') to_install = list(self.modules_to_install( cr, uid, ids, context=context)) self.logger.notifyChannel( 'installer', netsvc.LOG_INFO, 'Selecting addons %s to install'%to_install) modules.state_update( cr, uid, modules.search(cr, uid, [('name','in',to_install)]), 'to install', ['uninstalled'], context=context) cr.commit() #TOFIX: after remove this statement, installation wizard is fail pooler.restart_pool(cr.dbname, update_module=True)
def exp_migrate_databases(self,databases): from osv.orm import except_orm from osv.osv import except_osv l = netsvc.Logger() for db in databases: try: l.notifyChannel('migration', netsvc.LOG_INFO, 'migrate database %s' % (db,)) tools.config['update']['base'] = True pooler.restart_pool(db, force_demo=False, update_module=True) except except_orm, inst: self.abortResponse(1, inst.name, 'warning', inst.value) except except_osv, inst: self.abortResponse(1, inst.name, inst.exc_type, inst.value)
def install_module(self, module): logger.info('Installing module %s', module) import pooler from destral.transaction import Transaction module_obj = self.pool.get('ir.module.module') with Transaction().start(self.config['db_name']) as txn: module_obj.update_list(txn.cursor, txn.user) module_ids = module_obj.search( txn.cursor, DEFAULT_USER, [('name', '=', module)], ) assert module_ids, "Module %s not found" % module module_obj.button_install(txn.cursor, DEFAULT_USER, module_ids) pool = pooler.get_pool(txn.cursor.dbname) mod_obj = pool.get('ir.module.module') ids = mod_obj.search(txn.cursor, txn.user, [ ('state', 'in', ['to upgrade', 'to remove', 'to install']) ]) unmet_packages = [] mod_dep_obj = pool.get('ir.module.module.dependency') for mod in mod_obj.browse(txn.cursor, txn.user, ids): deps = mod_dep_obj.search(txn.cursor, txn.user, [ ('module_id', '=', mod.id) ]) for dep_mod in mod_dep_obj.browse(txn.cursor, txn.user, deps): if dep_mod.state in ('unknown', 'uninstalled'): unmet_packages.append(dep_mod.name) mod_obj.download(txn.cursor, txn.user, ids) txn.cursor.commit() self.db, self.pool = pooler.restart_pool( self.config['db_name'], update_module=True )
def install_module(self, module): logger.info('Installing module %s', module) import pooler from destral.transaction import Transaction module_obj = self.pool.get('ir.module.module') with Transaction().start(self.config['db_name']) as txn: module_obj.update_list(txn.cursor, txn.user) module_ids = module_obj.search( txn.cursor, DEFAULT_USER, [('name', '=', module)], ) assert module_ids, "Module %s not found" % module module_obj.button_install(txn.cursor, DEFAULT_USER, module_ids) pool = pooler.get_pool(txn.cursor.dbname) mod_obj = pool.get('ir.module.module') ids = mod_obj.search( txn.cursor, txn.user, [('state', 'in', ['to upgrade', 'to remove', 'to install'])]) unmet_packages = [] mod_dep_obj = pool.get('ir.module.module.dependency') for mod in mod_obj.browse(txn.cursor, txn.user, ids): deps = mod_dep_obj.search(txn.cursor, txn.user, [('module_id', '=', mod.id)]) for dep_mod in mod_dep_obj.browse(txn.cursor, txn.user, deps): if dep_mod.state in ('unknown', 'uninstalled'): unmet_packages.append(dep_mod.name) mod_obj.download(txn.cursor, txn.user, ids) txn.cursor.commit() self.db, self.pool = pooler.restart_pool(self.config['db_name'], update_module=True)
def upgrade_module(self, cr, uid, ids, context=None): mod_obj = self.pool.get('ir.module.module') ids = mod_obj.search(cr, uid, [('state', 'in', ['to upgrade', 'to remove', 'to install'])]) unmet_packages = [] mod_dep_obj = self.pool.get('ir.module.module.dependency') for mod in mod_obj.browse(cr, uid, ids): depends_mod_ids = mod_dep_obj.search(cr, uid, [('module_id', '=', mod.id)]) for dep_mod in mod_dep_obj.browse(cr, uid, depends_mod_ids): if dep_mod.state in ('unknown','uninstalled'): unmet_packages.append(dep_mod.name) if len(unmet_packages): raise osv.except_osv(_('Unmet dependency !'), _('Following modules are not installed or unknown: %s') % ('\n\n' + '\n'.join(unmet_packages))) mod_obj.download(cr, uid, ids, context=context) cr.commit() _db, pool = pooler.restart_pool(cr.dbname, update_module=True) data_obj = pool.get('ir.model.data') id2 = data_obj._get_id(cr, uid, 'base', 'view_base_module_upgrade_install') if id2: id2 = data_obj.browse(cr, uid, id2, context=context).res_id return { 'view_type': 'form', 'view_mode': 'form', 'res_model': 'base.module.upgrade', 'views': [(id2, 'form')], 'view_id': False, 'type': 'ir.actions.act_window', 'target': 'new', }
def execute(self, cr, uid, ids, context=None): module_pool = self.pool.get('ir.module.module') modules_selected = [] datas = self.read(cr, uid, ids, context=context)[0] for mod in datas.keys(): if mod in ('id', 'progress'): continue if datas[mod] == 1: modules_selected.append(mod) module_ids = module_pool.search(cr, uid, [('name', 'in', modules_selected)], context=context) need_install = False for module in module_pool.browse(cr, uid, module_ids, context=context): if module.state == 'uninstalled': module_pool.state_update(cr, uid, [module.id], 'to install', ['uninstalled'], context) need_install = True cr.commit() elif module.state == 'installed': cr.execute("update ir_actions_todo set state='open' \ from ir_model_data as data where data.res_id = ir_actions_todo.id \ and ir_actions_todo.type='special'\ and data.model = 'ir.actions.todo' and data.module=%s", (module.name, )) if need_install: self.pool = pooler.restart_pool(cr.dbname, update_module=True)[1] return
def button_immediate_install(self, cr, uid, ids, context=None): """ Installs the selected module(s) immediately and fully, returns the next res.config action to execute :param ids: identifiers of the modules to install :returns: next res.config item to execute :rtype: dict[str, object] """ self.button_install(cr, uid, ids, context=context) cr.commit() db, pool = pooler.restart_pool(cr.dbname, update_module=True) config = pool.get('res.config').next(cr, uid, [], context=context) or {} if config.get('type') not in ('ir.actions.reload', 'ir.actions.act_window_close'): return config menu_ids = self.root_menus(cr,uid,ids,context) if menu_ids: action = { 'type': 'ir.ui.menu', 'menu_id': menu_ids[0], 'reload' : True, } return action return False
def button_immediate_install(self, cr, uid, ids, context=None): """ Installs the selected module(s) immediately and fully, returns the next res.config action to execute :param ids: identifiers of the modules to install :returns: next res.config item to execute :rtype: dict[str, object] """ self.button_install(cr, uid, ids, context=context) cr.commit() db, pool = pooler.restart_pool(cr.dbname, update_module=True) config = pool.get('res.config').next(cr, uid, [], context=context) or {} if config.get('type') not in ('ir.actions.reload', 'ir.actions.act_window_close'): return config menu_ids = self.root_menus(cr, uid, ids, context) if menu_ids: action = { 'type': 'ir.ui.menu', 'menu_id': menu_ids[0], 'reload': True, } return action return False
def execute(self, cr, uid, ids, context=None): modules = self.pool.get('ir.module.module') to_install = list( self.modules_to_install(cr, uid, ids, context=context)) self.logger.notifyChannel( 'installer', netsvc.LOG_INFO, 'Selecting addons %s to install' % to_install) modules.state_update(cr, uid, modules.search(cr, uid, [('name', 'in', to_install)]), 'to install', ['uninstalled'], context=context) cr.commit( ) #TOFIX: after remove this statement, installation wizard is fail pooler.restart_pool(cr.dbname, update_module=True)
def execute(self, cr, uid, ids, context=None): modules = self.pool.get('ir.module.module') to_install = list(self.modules_to_install( cr, uid, ids, context=context)) self.__logger.info('Selecting addons %s to install', to_install) modules.state_update( cr, uid, modules.search(cr, uid, [('name','in',to_install)]), 'to install', ['uninstalled'], context=context) # Since we are about to restart the pool, the transaction _must_ be # committed now. cr.commit() new_db, self.pool = pooler.restart_pool(cr.dbname, update_module=True)
def execute(self, cr, uid, ids, context=None): modules = self.pool.get("ir.module.module") to_install = list(self.modules_to_install(cr, uid, ids, context=context)) self.__logger.info("Selecting addons %s to install", to_install) modules.state_update( cr, uid, modules.search(cr, uid, [("name", "in", to_install)]), "to install", ["uninstalled"], context=context, ) cr.commit() # TOFIX: after remove this statement, installation wizard is fail new_db, self.pool = pooler.restart_pool(cr.dbname, update_module=True)
def _update(self, cr, uid, data, context): pool=pooler.get_pool(cr.dbname) form=data['form'] if 'profile' in data['form'] and data['form']['profile'] > 0: module_obj=pool.get('ir.module.module') module_obj.state_update(cr, uid, [data['form']['profile']], 'to install', ['uninstalled'], context) company_obj=pool.get('res.company') partner_obj=pool.get('res.partner') address_obj=pool.get('res.partner.address') ids=company_obj.search(cr, uid, []) company=company_obj.browse(cr, uid, ids)[0] company_obj.write(cr, uid, [company.id], { 'name': form['name'], 'rml_header1': form['rml_header1'], 'rml_footer1': form['rml_footer1'], 'rml_footer2': form['rml_footer2'], 'currency_id': form['currency'], 'logo': form['logo'], }) partner_obj.write(cr, uid, [company.partner_id.id], { 'name': form['name'], }) values={ 'name': form['name'], 'street': form['street'], 'street2': form['street2'], 'zip': form['zip'], 'city': form['city'], 'email': form['email'], 'phone': form['phone'], } # we can do this, or set res.append((False, '')) in _get_all() if form['country_id'] > 0: values['country_id'] = form['country_id'] if form['state_id'] > 0: values['state_id'] = form['state_id'] if company.partner_id.address: address=company.partner_id.address[0] address_obj.write(cr, uid, [address.id], values) else: values['partner_id']=company.partner_id.id add_id=address_obj.create(cr, uid, values) cr.commit() (db, pool)=pooler.restart_pool(cr.dbname, update_module=True) return {}
def _upgrade_module(self, cr, uid, data, context): pool = pooler.get_pool(cr.dbname) mod_obj = pool.get('ir.module.module') ids = mod_obj.search(cr, uid, [('state', 'in', ['to upgrade', 'to remove', 'to install'])]) unmet_packages = [] mod_dep_obj = pool.get('ir.module.module.dependency') for mod in mod_obj.browse(cr, uid, ids): depends_mod_ids = mod_dep_obj.search(cr, uid, [('module_id', '=', mod.id)]) for dep_mod in mod_dep_obj.browse(cr, uid, depends_mod_ids): if dep_mod.state in ('unknown','uninstalled'): unmet_packages.append(dep_mod.name) if len(unmet_packages): raise wizard.except_wizard('Unmet dependency !', 'Following modules are uninstalled or unknown. \n\n'+'\n'.join(unmet_packages)) mod_obj.download(cr, uid, ids, context=context) cr.commit() db, pool = pooler.restart_pool(cr.dbname, update_module=True) return {}
def action_install(self, cr, uid, ids, context=None): result = self.read(cr, uid, ids) mod_obj = self.pool.get('ir.module.module') for res in result: for r in res: if r <> 'id' and res[r]: ids = mod_obj.search(cr, uid, [('name', '=', r)]) mod_obj.button_install(cr, uid, ids, context=context) cr.commit() db, pool = pooler.restart_pool(cr.dbname, update_module=True) return { 'view_type': 'form', "view_mode": 'form', 'res_model': 'ir.actions.configuration.wizard', 'type': 'ir.actions.act_window', 'target': 'new', }
def action_install(self, cr, uid, ids, context=None): result=self.read(cr,uid,ids) mod_obj = self.pool.get('ir.module.module') for res in result: for r in res: if r<>'id' and res[r]: ids = mod_obj.search(cr, uid, [('name', '=', r)]) mod_obj.button_install(cr, uid, ids, context=context) cr.commit() db, pool = pooler.restart_pool(cr.dbname,update_module=True) return { 'view_type': 'form', "view_mode": 'form', 'res_model': 'ir.actions.configuration.wizard', 'type': 'ir.actions.act_window', 'target':'new', }
def __call__(self, serv, id, db_name, demo, lang, user_password='******'): cr = None try: serv.actions[id]['progress'] = 0 cr = sql_db.db_connect(db_name).cursor() tools.init_db(cr) tools.config['lang'] = lang cr.commit() cr.close() cr = None pool = pooler.restart_pool(db_name, demo, serv.actions[id], update_module=True)[1] cr = sql_db.db_connect(db_name).cursor() if lang: modobj = pool.get('ir.module.module') mids = modobj.search(cr, 1, [('state', '=', 'installed')]) modobj.update_translations(cr, 1, mids, lang) cr.execute('UPDATE res_users SET password=%s, context_lang=%s, active=True WHERE login=%s', ( user_password, lang, 'admin')) cr.execute('SELECT login, password, name ' \ ' FROM res_users ' \ ' ORDER BY login') serv.actions[id]['users'] = cr.dictfetchall() serv.actions[id]['clean'] = True cr.commit() cr.close() except Exception, e: serv.actions[id]['clean'] = False serv.actions[id]['exception'] = e import traceback e_str = StringIO() traceback.print_exc(file=e_str) traceback_str = e_str.getvalue() e_str.close() netsvc.Logger().notifyChannel('web-services', netsvc.LOG_ERROR, 'CREATE DATABASE\n%s' % (traceback_str)) serv.actions[id]['traceback'] = traceback_str if cr: cr.close()
def __call__(self, serv, id, db_name, demo, lang, user_password='******'): cr = None try: serv.actions[id]['progress'] = 0 cr = sql_db.db_connect(db_name).cursor() tools.init_db(cr) tools.config['lang'] = lang cr.commit() cr.close(True) cr = None pool = pooler.restart_pool(db_name, demo, serv.actions[id], update_module=True)[1] cr = sql_db.db_connect(db_name).cursor() if lang: modobj = pool.get('ir.module.module') mids = modobj.search(cr, 1, [('state', '=', 'installed')]) modobj.update_translations(cr, 1, mids, lang) cr.execute('UPDATE res_users SET password=%s, context_lang=%s, active=True WHERE login=%s', ( user_password, lang, 'admin')) cr.execute('SELECT login, password, name ' \ ' FROM res_users ' \ ' ORDER BY login') serv.actions[id]['users'] = cr.dictfetchall() serv.actions[id]['clean'] = True cr.commit() cr.close(True) except Exception, e: serv.actions[id]['clean'] = False serv.actions[id]['exception'] = e import traceback e_str = StringIO() traceback.print_exc(file=e_str) traceback_str = e_str.getvalue() e_str.close() netsvc.Logger().notifyChannel('web-services', netsvc.LOG_ERROR, 'CREATE DATABASE\n%s' % (traceback_str)) serv.actions[id]['traceback'] = traceback_str if cr: cr.close(True)
def reconnect_sync_server(): """Reconnect the connection manager to the SYNC_SERVER if password file exists """ import tools credential_filepath = os.path.join(tools.config['root_path'], 'unifield-socket.py') if os.path.isfile(credential_filepath): import base64 import pooler f = open(credential_filepath, 'r') lines = f.readlines() f.close() if lines: try: dbname = base64.decodestring(lines[0]) password = base64.decodestring(lines[1]) logger.info('dbname = %s' % dbname) db, pool = pooler.get_db_and_pool(dbname) db, pool = pooler.restart_pool(dbname) # do not remove this line, it is required to restart pool not to have # strange behaviour with the connection on web interface # do not execute this code on server side if not pool.get("sync.server.entity"): cr = db.cursor() # delete the credential file os.remove(credential_filepath) # reconnect to SYNC_SERVER connection_module = pool.get("sync.client.sync_server_connection") connection_module.connect(cr, 1, password=password) # in caes of automatic patching, relaunch the sync # (as the sync that launch the silent upgrade was aborted to do the upgrade first) if connection_module.is_automatic_patching_allowed(cr, 1): pool.get('sync.client.entity').sync_withbackup(cr, 1) cr.close() except Exception as e: message = "Impossible to automatically re-connect to the SYNC_SERVER using credentials file : %s" logger.error(message % (unicode(e)))
def upgrade_module(self, cr, uid, ids, context=None): mod_obj = self.pool.get('ir.module.module') ids = mod_obj.search( cr, uid, [('state', 'in', ['to upgrade', 'to remove', 'to install'])]) unmet_packages = [] mod_dep_obj = self.pool.get('ir.module.module.dependency') for mod in mod_obj.browse(cr, uid, ids): depends_mod_ids = mod_dep_obj.search(cr, uid, [('module_id', '=', mod.id)]) for dep_mod in mod_dep_obj.browse(cr, uid, depends_mod_ids): if dep_mod.state in ('unknown', 'uninstalled'): unmet_packages.append(dep_mod.name) if len(unmet_packages): raise osv.except_osv( _('Unmet dependency !'), _('Following modules are not installed or unknown: %s') % ('\n\n' + '\n'.join(unmet_packages))) mod_obj.download(cr, uid, ids, context=context) cr.commit() _db, pool = pooler.restart_pool(cr.dbname, update_module=True) data_obj = pool.get('ir.model.data') id2 = data_obj._get_id(cr, uid, 'base', 'view_base_module_upgrade_install') if id2: id2 = data_obj.browse(cr, uid, id2, context=context).res_id return { 'view_type': 'form', 'view_mode': 'form', 'res_model': 'base.module.upgrade', 'views': [(id2, 'form')], 'view_id': False, 'type': 'ir.actions.act_window', 'target': 'new', }