diff --git a/trytond/config.py b/trytond/config.py index eec7467075..1efc11b116 100644 --- a/trytond/config.py +++ b/trytond/config.py @@ -82,7 +82,6 @@ class ConfigManager(object): self.options['data_path'] = False for arg in ( - 'db_name', 'verbose', 'debug_mode', 'pidfile', @@ -91,6 +90,12 @@ class ConfigManager(object): if getattr(opt, arg) is not None: self.options[arg] = getattr(opt, arg) + db_name = [] + if opt.db_name: + for i in opt.db_name.split(','): + db_name.append(i) + self.options['db_name'] = db_name + init = {} if opt.init and self.options.get('db_name'): for i in opt.init.split(','): diff --git a/trytond/module.py b/trytond/module.py index b3134a7015..a027a7e366 100644 --- a/trytond/module.py +++ b/trytond/module.py @@ -351,12 +351,13 @@ def load_modules(database, update_module=False, lang=None): cursor.execute("SELECT name FROM ir_module_module " \ "WHERE state IN ('installed', 'to upgrade', 'to remove')") module_list = [name for (name,) in cursor.fetchall()] - for module in CONFIG['init'].keys(): - if CONFIG['init'][module]: - module_list.append(module) - for module in CONFIG['update'].keys(): - if CONFIG['update'][module]: - module_list.append(module) + if update_module: + for module in CONFIG['init'].keys(): + if CONFIG['init'][module]: + module_list.append(module) + for module in CONFIG['update'].keys(): + if CONFIG['update'][module]: + module_list.append(module) graph = create_graph(module_list, force)[0] try: @@ -365,26 +366,23 @@ def load_modules(database, update_module=False, lang=None): cursor.rollback() raise - - for kind in ('init', 'update'): - CONFIG[kind] = {} - if update_module: cursor.execute("SELECT name FROM ir_module_module " \ "WHERE state IN ('to remove')") - for (mod_name,) in cursor.fetchall(): - pool = pooler.get_pool(cursor.dbname) - #TODO check if ressource not updated by the user - cursor.execute('SELECT model, db_id FROM ir_model_data ' \ - 'WHERE module = %s ' \ - 'ORDER BY id DESC', (mod_name,)) - for rmod, rid in cursor.fetchall(): - pool.get(rmod).delete(cursor, 0, rid) + if cursor.rowcount: + for (mod_name,) in cursor.fetchall(): + pool = pooler.get_pool(cursor.dbname) + #TODO check if ressource not updated by the user + cursor.execute('SELECT model, db_id FROM ir_model_data ' \ + 'WHERE module = %s ' \ + 'ORDER BY id DESC', (mod_name,)) + for rmod, rid in cursor.fetchall(): + pool.get(rmod).delete(cursor, 0, rid) + cursor.commit() + cursor.execute("UPDATE ir_module_module SET state = %s " \ + "WHERE state IN ('to remove')", ('uninstalled',)) cursor.commit() - cursor.execute("UPDATE ir_module_module SET state = %s " \ - "WHERE state IN ('to remove')", ('uninstalled',)) - cursor.commit() - pooler.restart_pool(cursor.dbname) + pooler.restart_pool(cursor.dbname) pool = pooler.get_pool(cursor.dbname) module_obj = pool.get('ir.module.module') diff --git a/trytond/server.py b/trytond/server.py index 4e95fd97a9..830bd61c75 100644 --- a/trytond/server.py +++ b/trytond/server.py @@ -50,81 +50,85 @@ class TrytonServer(object): def run(self): "Run the server and never return" - db_name = CONFIG["db_name"] - - cursor = None - try: - if db_name: - cursor = pooler.get_db_only(db_name).cursor() - except psycopg2.OperationalError: - self.logger.notify_channel("init", netsvc.LOG_INFO, - "could not connect to database '%s'!" % db_name,) - - init = False - if cursor and CONFIG['init']: - cursor.execute("SELECT relname " \ - "FROM pg_class " \ - "WHERE relkind = 'r' AND relname in (" \ - "'inherit', " - "'ir_model', " - "'ir_model_field', " - "'ir_ui_view', " - "'ir_ui_menu', " - "'res_user', " - "'res_group', " - "'res_group_user_rel', " - "'wkf', " - "'wkf_activity', " - "'wkf_transition', " - "'wkf_instance', " - "'wkf_workitem', " - "'wkf_witm_trans', " - "'ir_module_category', " - "'ir_module_module', " - "'ir_module_module_dependency, '" - "'ir_translation, '" - "'ir_lang'" - ")") - if len(cursor.fetchall()) == 0: - self.logger.notify_channel("init", netsvc.LOG_INFO, "init db") - sql_db.init_db(cursor) - init = True - cursor.commit() - - register_classes() - update_module = False - if db_name: - lang = None - if cursor: - cursor.execute('SELECT code FROM ir_lang ' \ - 'WHERE translatable = True') - lang = [x[0] for x in cursor.fetchall()] + init = {} + for db_name in CONFIG["db_name"]: + cursor = None + try: + if db_name: + cursor = pooler.get_db_only(db_name).cursor() + except psycopg2.OperationalError: + self.logger.notify_channel("init", netsvc.LOG_INFO, + "could not connect to database '%s'!" % db_name,) + + init[db_name] = False + if cursor and CONFIG['init']: + cursor.execute("SELECT relname " \ + "FROM pg_class " \ + "WHERE relkind = 'r' AND relname in (" \ + "'inherit', " + "'ir_model', " + "'ir_model_field', " + "'ir_ui_view', " + "'ir_ui_menu', " + "'res_user', " + "'res_group', " + "'res_group_user_rel', " + "'wkf', " + "'wkf_activity', " + "'wkf_transition', " + "'wkf_instance', " + "'wkf_workitem', " + "'wkf_witm_trans', " + "'ir_module_category', " + "'ir_module_module', " + "'ir_module_module_dependency, '" + "'ir_translation, '" + "'ir_lang'" + ")") + if len(cursor.fetchall()) == 0: + self.logger.notify_channel("init", netsvc.LOG_INFO, "init db") + sql_db.init_db(cursor) + init[db_name] = True + cursor.commit() + + register_classes() + + if db_name: + lang = None + if cursor: + cursor.execute('SELECT code FROM ir_lang ' \ + 'WHERE translatable = True') + lang = [x[0] for x in cursor.fetchall()] + cursor.close() + update_module = bool(CONFIG['init'] or CONFIG['update']) + pooler.get_db_and_pool(db_name, update_module=update_module, + lang=lang) + + for kind in ('init', 'update'): + CONFIG[kind] = {} + + for db_name in CONFIG['db_name']: + if init[db_name]: + while True: + password = getpass('Admin Password for %s:' % db_name) + password2 = getpass('Admin Password Confirmation:') + if password != password2: + sys.stderr.write('Admin Password Confirmation doesn\'t match ' \ + 'Admin Password!\n') + continue + if not password: + sys.stderr.write('Admin Password is required!\n') + continue + break + + cursor = pooler.get_db_only(db_name).cursor() + cursor.execute('UPDATE res_user ' \ + 'SET password = %s ' \ + 'WHERE login = \'admin\'', + (sha.new(password).hexdigest(),)) + cursor.commit() cursor.close() - update_module = bool(CONFIG['init'] or CONFIG['update']) - pooler.get_db_and_pool(db_name, update_module=update_module, - lang=lang) - - if init and db_name: - while True: - password = getpass('Admin Password:') - password2 = getpass('Admin Password Confirmation:') - if password != password2: - sys.stderr.write('Admin Password Confirmation doesn\'t match ' \ - 'Admin Password!\n') - continue - if not password: - sys.stderr.write('Admin Password is required!\n') - continue - break - - cursor = pooler.get_db_only(db_name).cursor() - cursor.execute('UPDATE res_user ' \ - 'SET password = %s ' \ - 'WHERE login = \'admin\'', - (sha.new(password).hexdigest(),)) - cursor.commit() - cursor.close() if update_module: self.logger.notify_channel('init', netsvc.LOG_INFO,