def load_module_graph(db_name, graph, config): pool = pooler.get_pool() for package in graph: if package.name in _loaded_addons: continue cherrypy.log("Loading module '%s'" % package.name, "INFO") imp_module(package.name) static = paths.addons(package.name, 'static') if os.path.isdir(static): from openobject.widgets import register_resource_directory register_resource_directory(config, package.name, static) addon_path = paths.addons(package.name) if os.path.isdir(paths.addons(package.name, 'po')): i18n.load_translations(addon_path) i18n.load_translations(addon_path, domain="javascript") _loaded_addons[package.name] = True for package in graph: pool.load(package.name) _loaded[db_name][package.name] = True
def _get_modules(modules): """Get iterator of tuples of all the available addons with first item is addon name and second item is full path to the addon. """ if modules.upper() == "ALL": modules = os.listdir(paths.addons()) else: modules = modules.split(",") for module in modules: d = paths.addons(module) if os.path.isfile(os.path.join(d, '__openerp__.py')): yield module, d
def imp_module(name): fp, pathname, description = imp.find_module(name, [paths.addons()]) try: return imp.load_module(name, fp, pathname, description) finally: if fp: fp.close()
def get_template_lookup(): """Return the Template Lookup for the current database""" lookup = pooler.get_pool().get(None, TEMPLATE_LOOKUP_GROUP) if not lookup: lookup = TemplateLookup(directories=[paths.root(), paths.addons()], default_filters=filters, imports=imports, preprocessor=templating.edition_preprocessor) pooler.get_pool().get_group(TEMPLATE_LOOKUP_GROUP)[None] = lookup return lookup
def get_template_lookup(): """Return the Template Lookup for the current database""" lookup = pooler.get_pool().get(None, TEMPLATE_LOOKUP_GROUP) if not lookup: lookup = TemplateLookup( directories=[paths.root(), paths.addons()], default_filters=filters, imports=imports, preprocessor=templating.edition_preprocessor) pooler.get_pool().get_group(TEMPLATE_LOOKUP_GROUP)[None] = lookup return lookup
def get_info(module): mod_path = paths.addons(module) if not os.path.isdir(mod_path): return {} terp_file = os.path.join(mod_path, '__openerp__.py') if not os.path.isfile(terp_file): return {} try: return openobject.tools.ast.literal_eval(open(terp_file).read()) except: cherrypy.log('module %s: eval file %s' % (module, terp_file), "ERROR") raise
def get_new_modules(): if not writeable: return [] modules = rpc.RPCProxy('ir.module.module') web_modules = modules.list_web() if not web_modules: return [] addons_to_load = map(operator.itemgetter(0), web_modules) addons_to_download = [ name for (name, version) in web_modules if (not exists(name) or version > get_info(name).get('version', '0')) ] # avoid querying for 0 addons if we have everything already if not addons_to_download: return addons_to_load web_payload = modules.get_web(addons_to_download) for module in web_payload: # Due to the way zip_directory works on the server, we get a toplevel # dir called "web" for our addon, rather than having it named # "the right way". Dump to temp directory and move to right name. temp_dir = tempfile.mkdtemp() openobject.tools.zip.extract_zip_file( StringIO(module['content'].decode('base64')), temp_dir) # cleanup any existing addon of the same name module_dir = paths.addons(module['name']) shutil.rmtree(module_dir, ignore_errors=True) shutil.move(os.path.join(temp_dir, 'web'), module_dir) shutil.rmtree(temp_dir) dependencies = map(lambda u: u.encode('utf-8'), module['depends']) descriptor = open(os.path.join(module_dir, '__openerp__.py'), 'wb') descriptor.write('# -*- coding: utf-8 -*-\n') descriptor.write("%s" % ({ 'name': module['name'].encode('utf-8'), 'version': module['version'].encode('utf-8'), # addons depend at least of openerp 'depends': dependencies or ['openerp'], },)) descriptor.close() return addons_to_load
def get_new_modules(self): if not addons.writeable: return [] modules = rpc.RPCProxy('ir.module.module') web_modules = modules.list_web() if not web_modules: return [] addons_to_load = map(operator.itemgetter(0), web_modules) addons_to_download = [ name for (name, version) in web_modules if (not addons.exists(name) or version > addons.get_info(name).get('version', '0')) ] # avoid querying for 0 addons if we have everything already if not addons_to_download: return addons_to_load web_payload = modules.get_web(addons_to_download) for module in web_payload: # Due to the way zip_directory works on the server, we get a toplevel dir called "web" for our addon, # rather than having it named "the right way". Dump to temp directory and move to right name. temp_dir = tempfile.mkdtemp() extract_zip_file(StringIO(module['content'].decode('base64')), temp_dir) # cleanup any existing addon of the same name module_dir = paths.addons(module['name']) shutil.rmtree(module_dir, ignore_errors=True) shutil.move(os.path.join(temp_dir, 'web'), module_dir) shutil.rmtree(temp_dir) dependencies = map(lambda u: u.encode('utf-8'), module['depends']) descriptor = open(os.path.join(module_dir, '__openerp__.py'), 'wb') descriptor.write('# -*- coding: utf-8 -*-\n') descriptor.write("%s" % ( { 'name': module['name'].encode('utf-8'), 'version': module['version'].encode('utf-8'), # addons depend at least of openerp 'depends': dependencies or ['openerp'], }, )) descriptor.close() return addons_to_load
def exists(module): return os.path.exists(paths.addons(module, '__openerp__.py'))
def get_local_addons(): return [f for f in os.listdir(paths.addons()) \ if os.path.isfile(paths.addons(f, "__openerp__.py"))]
if db_name in _loaded: return cherrypy.request.loading_addons = True _loaded[db_name] = {} base_addons = [m for m in get_local_addons() if get_info(m).get("active")] graph = create_graph(base_addons) load_module_graph(db_name, graph, config) try: obj = pooler.get_pool().get_controller("/openerp/modules") new_modules = obj.get_new_modules() except errors.AuthenticationError: new_modules = [] new_modules_in_graph = upgrade_graph(graph, new_modules) if new_modules_in_graph: load_module_graph(db_name, graph, config) cherrypy.request.loading_addons = False writeable = os.access(paths.addons(), os.W_OK) if not writeable: cherrypy.log.error("Can not write to the addons directory '%s', " "will not be able to download web modules" % paths.addons(), "WARNING", severity=logging.WARNING)
def load_addons(db_name, config): if db_name in _loaded: return cherrypy.request.loading_addons = True _loaded[db_name] = {} base_addons = [m for m in get_local_addons() if get_info(m).get("active")] graph = create_graph(base_addons) load_module_graph(db_name, graph, config) try: obj = pooler.get_pool().get_controller("/openerp/modules") new_modules = obj.get_new_modules() except errors.AuthenticationError: new_modules = [] new_modules_in_graph = upgrade_graph(graph, new_modules) if new_modules_in_graph: load_module_graph(db_name, graph, config) cherrypy.request.loading_addons = False writeable = os.access(paths.addons(), os.W_OK) if not writeable: cherrypy.log.error( "Can not write to the addons directory '%s', " "will not be able to download web modules" % paths.addons(), "WARNING", severity=logging.WARNING)
graph = create_graph(base_addons) load_module_graph(db_name, graph, config) try: new_modules = get_new_modules() except errors.AuthenticationError: new_modules = [] new_modules_in_graph = upgrade_graph(graph, new_modules) if new_modules_in_graph: load_module_graph(db_name, graph, config) cherrypy.request.loading_addons = False writeable = os.access(paths.addons(), os.W_OK) if not writeable: logger.warn( "Can not write to the addons directory '%s', " "will not be able to download web modules", paths.addons()) def has_new_modules(): """ Returns whether there are new web modules available for download (brand new or updates) :rtype bool: """ try: return bool([ name for (name, version) in rpc.RPCProxy('ir.module.module').list_web()