From b8cb4f95f4cbbf2e7789b753900917e8d26fca5f Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Fri, 18 Jan 2013 16:13:32 +0100 Subject: [PATCH] [7.0] 1st pass at porting server_environment --- server_environment/__openerp__.py | 70 ++++++++++++++++++------------- server_environment/serv_config.py | 38 ++++++++++------- server_environment/system_info.py | 4 +- 3 files changed, 67 insertions(+), 45 deletions(-) diff --git a/server_environment/__openerp__.py b/server_environment/__openerp__.py index 88f3c4439..f4c3b29ba 100644 --- a/server_environment/__openerp__.py +++ b/server_environment/__openerp__.py @@ -24,51 +24,63 @@ "version": "1.0", "depends": ["base", "server_environment_files"], "author": "Camptocamp", - "description": """This module provides a classical configuration by environnement file pattern into OpenERP. -Based on code written by WinGo and Camptocamp. + "description": """\ +Environment file pattern for OpenERP +==================================== -This module allows you to use the classical environment file pattern by reading -a directive call running_env in config file or openerpc. +This module provides a classical configuration by environnement file +pattern into OpenERP. Based on code written by WinGo and Camptocamp. -[options] -running_env=dev / prod / etc. +This module allows you to use the classical environment file pattern +by reading a directive call `running_env` in the OpenERP configuration +file:: -We intended to add a server command line but there is no correct way to do it. + [options] + running_env=dev / prod / etc. -This method allows you to have your settings into a module instead of using config file that might be mixed with openerprc or altered. -It is an alternative way to config the base config file. -All your configurations will be read_only and accessible under the admin menu. -If you are not in the 'dev' environment you will not be able to see the values containing 'passw' in key. +We intended to add a server command line but there is no correct way +to do it. -At the current time, the module does not allow to set low level attributes such as database server, etc. . +This method allows you to keep your settings into a module instead of +using config files that might be mixed with openerprc or altered. It +is an alternative way to the base config file for such configuration +needs . All your configurations will be read only and accessible +under the admin menu. If you are not in the 'dev' environment you +will not be able to see the values contained in keys named 'passw'. -The first goal of the module is to ensure that OpenERP will never mess up the external system. -Once installed, profile is mandatory. We do not want to launch an instance in the dev environment on a production server. +At the current time, the module does not allow to set low level +attributes such as database server, etc. . +The first goal of the module is to ensure that OpenERP will never mess +up the external system. Once installed, profile is mandatory. We do +not want to launch an instance in the dev environment on a production +server. +The configuration files are stored in the `server_environment_files` +module, and user config parser module syntax. Look at the module to +get some examples. The `default` configuration are stored in the +`default/` directory. You can add one directory for each environment +you want to define, named after the environment. All config defined in +non-default environments will override or complement the default +config. If your attibutes contain `passw`, it will only be shown in +the `dev` environment. -The configuration files are to put in the module server_environment_files ; they are using the config parser module syntax. -Look at the module to get some sexamples. -The default configuration are to put in the default folder. All config defined in other environment will be overwritten or added to default one. -Then, you can add a folder by used environment with the name of the environment -If your attibutes contain passw it will only be shown in dev environment. +Example usage +------------- -Usage samples: +:: -from server_environment import serv_config -for key, value in serv_config.items('external_service.ftp'): - print (key, value) + from server_environment import serv_config + for key, value in serv_config.items('external_service.ftp'): + print (key, value) - -serv_config.get('external_service.ftp', 'tls') + serv_config.get('external_service.ftp', 'tls') """, "website": "http://www.camptocamp.com", "category": "Tools", - "init_xml": [], - "demo_xml": [], - "update_xml": [ + "data": [ 'serv_config.xml', ], - "installable": False, + "installable": True, "active": False, } diff --git a/server_environment/serv_config.py b/server_environment/serv_config.py index 196b33ef1..2628ceb2b 100644 --- a/server_environment/serv_config.py +++ b/server_environment/serv_config.py @@ -21,15 +21,14 @@ import os import ConfigParser - from lxml import etree -from osv import osv, fields -from tools.config import config as system_base_config +from openerp.osv import osv, fields, orm +from openerp.tools.config import config as system_base_config from .system_info import get_server_environment -import server_environment_files +import openerp.addons import server_environment_files _dir = os.path.dirname(server_environment_files.__file__) # Same dict as RawConfigParser._boolean_states @@ -38,8 +37,10 @@ _boolean_states = {'1': True, 'yes': True, 'true': True, 'on': True, if not system_base_config.get('running_env', False): raise Exception( - "The parameter 'running_env' has not be set neither in base config file option -c or in openerprc.\n" - "We strongly recommend against using the rc file but instead use an explicit config file with this content:\n" + "The parameter 'running_env' has not be set neither in base config " + "file option -c or in openerprc.\n" + "We strongly recommend against using the rc file but instead use an " + "explicit config file with this content:\n" "[options]\nrunning_env = dev" ) @@ -47,7 +48,8 @@ ck_path = os.path.join(_dir, system_base_config['running_env']) if not os.path.exists(ck_path) : raise Exception( - "Provided server environment does not exist, please add a folder %s" % ck_path + "Provided server environment does not exist, " + "please add a folder %s" % ck_path ) def setboolean(obj, attr, _bool=_boolean_states): @@ -78,7 +80,8 @@ def _listconf(env_path): def _load_config(): """Load the configuration and return a ConfigParser instance.""" default = os.path.join(_dir, 'default') - running_env = os.path.join(_dir, system_base_config['running_env']) + running_env = os.path.join(_dir, + system_base_config['running_env']) if os.path.isdir(default): conf_files = _listconf(default) + _listconf(running_env) else: @@ -105,7 +108,7 @@ class _Defaults(dict): return dict.__setitem__(self, key, func) -class ServerConfiguration(osv.osv_memory): +class ServerConfiguration(orm.TransientModel): """Display server configuration.""" _name = 'server.config' _columns = {} @@ -116,8 +119,8 @@ class ServerConfiguration(osv.osv_memory): self.running_env = system_base_config['running_env'] # Only show passwords in development self.show_passwords = self.running_env in ('dev',) + self._arch = None self._build_osv() - return res def _group(self, items, prefix): """Return an XML chunk which represents a group of fields.""" @@ -166,12 +169,20 @@ class ServerConfiguration(osv.osv_memory): arch += '' self._arch = etree.fromstring(arch) - def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): + def fields_view_get(self, cr, uid, view_id=None, view_type='form', + context=None, toolbar=False, submenu=False): """Overwrite the default method to render the custom view.""" - res = super(ServerConfiguration, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar) + res = super(ServerConfiguration, self).fields_view_get(cr, uid, + view_id, + view_type, + context, + toolbar) if view_type == 'form': arch_node = self._arch - xarch, xfields = self._view_look_dom_arch(cr, uid, arch_node, view_id, context=context) + xarch, xfields = self._view_look_dom_arch(cr, uid, + arch_node, + view_id, + context=context) res['arch'] = xarch res['fields'] = xfields return res @@ -182,4 +193,3 @@ class ServerConfiguration(osv.osv_memory): for key in self._conf_defaults: res[key] = self._conf_defaults[key]() return res -ServerConfiguration() diff --git a/server_environment/system_info.py b/server_environment/system_info.py index e93226372..5c5875eb0 100644 --- a/server_environment/system_info.py +++ b/server_environment/system_info.py @@ -24,8 +24,8 @@ import os import platform import subprocess -import release -from tools.config import config +from openerp import release +from openerp.tools.config import config def _get_output(cmd):