def main(): args = sys.argv[1:] # The only shared option is '--addons-path=' needed to discover additional # commands from modules if len(args) > 1 and args[0].startswith( '--addons-path=') and not args[1].startswith("-"): # parse only the addons-path, do not setup the logger... openerp.tools.config._parse_config([args[0]]) args = args[1:] # Default legacy command command = "server" # TODO: find a way to properly discover addons subcommands without importing the world # Subcommand discovery if len(args) and not args[0].startswith("-"): logging.disable(logging.CRITICAL) for module in get_modules(): if isdir(joinpath(get_module_path(module), 'cli')): __import__('openerp.addons.' + module) logging.disable(logging.NOTSET) command = args[0] args = args[1:] if command in commands: o = commands[command]() o.run(args)
def main(starter, conf, version=None, just_test=False, server_wide_modules=None, gevent_script_path=None): """Call the `starter` script, dispatching configuration. All arguments are set in the standalone script produced by buildout through entry point options. :param starter: path to the main script source file (currently ``openerp-server``) :param conf: path to the Odoo configuration file (managed by the recipe) :param version: Odoo major version :param server_wide_modules: additional server wide modules, to pass with the ``--load`` command-line option (ignored if the option is actually there on the command line) :type version: tuple of integers :param just_test: if True, only run unit tests """ arguments = ['-c', conf] if just_test: arguments.extend(('--log-level', 'test' if version >= (6, 0) else 'info', '--stop-after-init')) if version >= (7, 0): arguments.append('--test-enable') if server_wide_modules: for opt in sys.argv[1:]: if opt.startswith('--load'): break else: arguments.append('--load=' + ','.join(server_wide_modules)) if '--install-all' in sys.argv: sys.argv.remove('--install-all') from openerp.tools import config # Maybe we should preparse config in all cases and therefore avoid # adding the '-c' on the fly ? # Still, cautious about pre-6.1 versions config.parse_config(['-c', conf]) from openerp.modules import get_modules arguments.extend(('-i', ','.join(get_modules()))) insert_args(arguments) if version >= (8, 0): # always true in a.r.odoo, but keeping for now assert gevent_script_path is not None patch_odoo.do_patch(gevent_script_path) os.chdir(os.path.split(starter)[0]) glob = globals() glob['__name__'] = '__main__' glob['__file__'] = starter sys.argv[0] = starter try: execfile(starter, globals()) except SystemExit as exc: return exc.code
def update_uninstallable_state(self): """ Just in case module list update overwrite some of our values """ # make uninstallable all not installed modules that has a none # istallable visibility self._get_not_installed_uninstallable_modules().write( {'state': 'uninstallable'}) # make uninstallable all modules that are not contracted self.search([('state', '=', 'uninstalled'), ('adhoc_category_id.contracted', '=', False) ]).write({'state': 'uninstallable'}) # we check if some uninstallable modules has become installable # visibility installable, dcontracte and terp says instsallable uninstallable_installable_modules = self.search([ ('conf_visibility', 'not in', uninstallables), ('adhoc_category_id.contracted', '=', True), ('state', '=', 'uninstallable'), ]) uninstallable_installable_modules_names = dict([ (m.name, m) for m in uninstallable_installable_modules ]) for mod_name in modules.get_modules(): # mod is the in database mod = uninstallable_installable_modules_names.get(mod_name) # terp is the module on file terp = self.get_module_info(mod_name) if mod: # si terp dice que es instalable lo ponemos uninstalled if terp.get('installable', True): mod.state = 'uninstalled'
def update_auto_install_from_visibility(self): # make none auto_install modules auto_install if vis. auto_install visibility_auto_install_modules = self.search([ ('conf_visibility', '=', 'auto_install'), ('auto_install', '=', False), ]) visibility_auto_install_modules.write({'auto_install': True}) # in case an auto_install module became normal # we check modules with auto_install and no visibility auto install visibility_none_auto_install_auto_modules = self.search([ ('conf_visibility', '!=', 'auto_install'), ('auto_install', '=', True), ]) visibility_none_auto_install_auto_modules_names = dict([ (m.name, m) for m in visibility_none_auto_install_auto_modules ]) for mod_name in modules.get_modules(): # mod is the in database mod = visibility_none_auto_install_auto_modules_names.get(mod_name) # terp is the module on file terp = self.get_module_info(mod_name) if mod: # si terp dice que es no es auto_intall lo ponemos false if not terp.get('auto_install', False): mod.auto_install = False
def main(): args = sys.argv[1:] # The only shared option is '--addons-path=' needed to discover additional # commands from modules if len(args) > 1 and args[0].startswith('--addons-path=') and not args[1].startswith("-"): # parse only the addons-path, do not setup the logger... openerp.tools.config._parse_config([args[0]]) args = args[1:] # Default legacy command command = "server" # TODO: find a way to properly discover addons subcommands without importing the world # Subcommand discovery if len(args) and not args[0].startswith("-"): logging.disable(logging.CRITICAL) for module in get_modules(): if isdir(joinpath(get_module_path(module), 'cli')): __import__('openerp.addons.' + module) logging.disable(logging.NOTSET) command = args[0] args = args[1:] if command in commands: o = commands[command]() o.run(args)
def update_list(self, cr, uid, context=None): res = [0, 0] # [update, add] default_version = modules.adapt_version('1.0') known_mods = self.browse(cr, uid, self.search(cr, uid, [])) known_mods_names = dict([(m.name, m) for m in known_mods]) # iterate through detected modules and update/create them in db for mod_name in modules.get_modules(): mod = known_mods_names.get(mod_name) terp = self.get_module_info(mod_name) values = self.get_values_from_terp(terp) if mod: updated_values = {} for key in values: old = getattr(mod, key) updated = isinstance(values[key], basestring) and tools.ustr( values[key]) or values[key] if (old or updated) and updated != old: updated_values[key] = values[key] if terp.get('installable', True) and mod.state == 'uninstallable': updated_values['state'] = 'uninstalled' if parse_version(terp.get( 'version', default_version)) > parse_version( mod.latest_version or default_version): res[0] += 1 if updated_values: self.write(cr, uid, mod.id, updated_values) else: mod_path = modules.get_module_path(mod_name) if not mod_path: continue if not terp or not terp.get('installable', True): continue id = self.create( cr, uid, dict(name=mod_name, state='uninstalled', **values)) mod = self.browse(cr, uid, id) res[1] += 1 self._update_dependencies(cr, uid, mod, terp.get('depends', [])) self._update_category(cr, uid, mod, terp.get('category', 'Uncategorized')) # Trigger load_addons if new module have been discovered it exists on # wsgi handlers, so they can react accordingly if tuple(res) != (0, 0): for handler in openerp.service.wsgi_server.module_handlers: if hasattr(handler, 'load_addons'): handler.load_addons() return res
def update_list(self, cr, uid, context=None): res = [0, 0] # [update, add] default_version = modules.adapt_version("1.0") known_mods = self.browse(cr, uid, self.search(cr, uid, [])) known_mods_names = dict([(m.name, m) for m in known_mods]) # iterate through detected modules and update/create them in db for mod_name in modules.get_modules(): mod = known_mods_names.get(mod_name) terp = self.get_module_info(mod_name) values = self.get_values_from_terp(terp) if mod: updated_values = {} for key in values: old = getattr(mod, key) updated = isinstance(values[key], basestring) and tools.ustr(values[key]) or values[key] if (old or updated) and updated != old: updated_values[key] = values[key] if terp.get("installable", True) and mod.state == "uninstallable": updated_values["state"] = "uninstalled" if parse_version(terp.get("version", default_version)) > parse_version( mod.latest_version or default_version ): res[0] += 1 if updated_values: self.write(cr, uid, mod.id, updated_values) else: mod_path = modules.get_module_path(mod_name) if not mod_path: continue if not terp or not terp.get("installable", True): continue id = self.create(cr, uid, dict(name=mod_name, state="uninstalled", **values)) mod = self.browse(cr, uid, id) res[1] += 1 self._update_dependencies(cr, uid, mod, terp.get("depends", [])) self._update_category(cr, uid, mod, terp.get("category", "Uncategorized")) # Trigger load_addons if new module have been discovered it exists on # wsgi handlers, so they can react accordingly if tuple(res) != (0, 0): for handler in openerp.service.wsgi_server.module_handlers: if hasattr(handler, "load_addons"): handler.load_addons() return res
def update_list(self, cr, uid, context=None): res = [0, 0] # [update, add] default_version = modules.adapt_version('1.0') known_mods = self.browse(cr, uid, self.search(cr, uid, [])) known_mods_names = dict([(m.name, m) for m in known_mods]) # iterate through detected modules and update/create them in db for mod_name in modules.get_modules(): mod = known_mods_names.get(mod_name) terp = self.get_module_info(mod_name) values = self.get_values_from_terp(terp) if mod: updated_values = {} for key in values: old = getattr(mod, key) updated = isinstance(values[key], basestring) and tools.ustr( values[key]) or values[key] if (old or updated) and updated != old: updated_values[key] = values[key] if terp.get('installable', True) and mod.state == 'uninstallable': updated_values['state'] = 'uninstalled' if parse_version(terp.get( 'version', default_version)) > parse_version( mod.latest_version or default_version): res[0] += 1 if updated_values: self.write(cr, uid, mod.id, updated_values) else: mod_path = modules.get_module_path(mod_name) if not mod_path: continue if not terp or not terp.get('installable', True): continue id = self.create( cr, uid, dict(name=mod_name, state='uninstalled', **values)) mod = self.browse(cr, uid, id) res[1] += 1 self._update_dependencies(cr, uid, mod, terp.get('depends', [])) self._update_category(cr, uid, mod, terp.get('category', 'Uncategorized')) return res
def update_list(self, cr, uid, context=None): res = [0, 0] # [update, add] default_version = modules.adapt_version("1.0") known_mods = self.browse(cr, uid, self.search(cr, uid, [])) known_mods_names = dict([(m.name, m) for m in known_mods]) # iterate through detected modules and update/create them in db for mod_name in modules.get_modules(): mod = known_mods_names.get(mod_name) terp = self.get_module_info(mod_name) values = self.get_values_from_terp(terp) if mod: updated_values = {} for key in values: old = getattr(mod, key) updated = isinstance(values[key], basestring) and tools.ustr(values[key]) or values[key] if (old or updated) and updated != old: updated_values[key] = values[key] if terp.get("installable", True) and mod.state == "uninstallable": updated_values["state"] = "uninstalled" if parse_version(terp.get("version", default_version)) > parse_version( mod.latest_version or default_version ): res[0] += 1 if updated_values: self.write(cr, uid, mod.id, updated_values) else: mod_path = modules.get_module_path(mod_name) if not mod_path: continue if not terp or not terp.get("installable", True): continue id = self.create(cr, uid, dict(name=mod_name, state="uninstalled", **values)) mod = self.browse(cr, uid, id) res[1] += 1 self._update_dependencies(cr, uid, mod, terp.get("depends", [])) self._update_category(cr, uid, mod, terp.get("category", "Uncategorized")) return res
def update_list(self, cr, uid, context=None): res = [0, 0] # [update, add] known_mods = self.browse(cr, uid, self.search(cr, uid, [])) known_mods_names = dict([(m.name, m) for m in known_mods]) # iterate through detected modules and update/create them in db for mod_name in addons.get_modules(): mod = known_mods_names.get(mod_name) terp = self.get_module_info(mod_name) values = self.get_values_from_terp(terp) if mod: updated_values = {} for key in values: old = getattr(mod, key) updated = isinstance(values[key], basestring) and tools.ustr(values[key]) or values[key] if not old == updated: updated_values[key] = values[key] if terp.get('installable', True) and mod.state == 'uninstallable': updated_values['state'] = 'uninstalled' if parse_version(terp.get('version', '')) > parse_version(mod.latest_version or ''): res[0] += 1 if updated_values: self.write(cr, uid, mod.id, updated_values) else: mod_path = addons.get_module_path(mod_name) if not mod_path: continue if not terp or not terp.get('installable', True): continue id = self.create(cr, uid, dict(name=mod_name, state='uninstalled', **values)) mod = self.browse(cr, uid, id) res[1] += 1 self._update_dependencies(cr, uid, mod, terp.get('depends', [])) self._update_category(cr, uid, mod, terp.get('category', 'Uncategorized')) return res
warnings.filterwarnings("ignore", message="Old style callback, usecb_func(ok, store) instead") ERP_PATH = settings.ERP_PATH if not ERP_PATH in sys.path: sys.path.insert(0, os.path.dirname(ERP_PATH)) from openerp.tools import config from openerp.modules import get_modules from openerp.pooler import get_db_and_pool # Configurar el server con los parametros adecuados. config.parse_config(['-c', settings.ERP_CONF]) # Modulos en nuestra conf de OpenERP get_modules() DB, POOL = get_db_and_pool(settings.ERP_DB) cursor = DB.cursor() user_obj = POOL.get('res.users') try: USER = user_obj.search(cursor, 1, [ ('login', '=', settings.ERP_UN), ], limit=1)[0] except: cursor.rollback() finally: