Migration of server_environment to 10.0
This commit is contained in:
parent
81b343ea24
commit
9b58d8c18d
|
|
@ -68,7 +68,7 @@ To use this module, in your code, you can follow this example::
|
||||||
|
|
||||||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
|
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
|
||||||
:alt: Try me on Runbot
|
:alt: Try me on Runbot
|
||||||
:target: https://runbot.odoo-community.org/runbot/149/9.0
|
:target: https://runbot.odoo-community.org/runbot/149/10.0
|
||||||
|
|
||||||
|
|
||||||
Known issues / Roadmap
|
Known issues / Roadmap
|
||||||
|
|
@ -85,11 +85,7 @@ Bug Tracker
|
||||||
Bugs are tracked on `GitHub Issues
|
Bugs are tracked on `GitHub Issues
|
||||||
<https://github.com/OCA/server-tools/issues>`_. In case of trouble, please
|
<https://github.com/OCA/server-tools/issues>`_. In case of trouble, please
|
||||||
check there if your issue has already been reported. If you spotted it first,
|
check there if your issue has already been reported. If you spotted it first,
|
||||||
help us smashing it by providing a detailed and welcomed `feedback
|
help us smashing it by providing a detailed and welcomed feedback.
|
||||||
<https://github.com/OCA/
|
|
||||||
server-tools/issues/new?body=module:%20
|
|
||||||
server_environment%0Aversion:%20
|
|
||||||
9.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
|
|
||||||
|
|
||||||
Credits
|
Credits
|
||||||
=======
|
=======
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
{
|
{
|
||||||
"name": "server configuration environment files",
|
"name": "server configuration environment files",
|
||||||
"version": "9.0.1.2.0",
|
"version": "10.0.1.2.0",
|
||||||
"depends": ["base", "server_environment_files"],
|
"depends": ["base", "server_environment_files"],
|
||||||
"author": "Camptocamp,Odoo Community Association (OCA)",
|
"author": "Camptocamp,Odoo Community Association (OCA)",
|
||||||
"summary": "move some configurations out of the database",
|
"summary": "move some configurations out of the database",
|
||||||
|
|
@ -31,6 +31,5 @@
|
||||||
"data": [
|
"data": [
|
||||||
'serv_config.xml',
|
'serv_config.xml',
|
||||||
],
|
],
|
||||||
'installable': False,
|
'installable': True,
|
||||||
"active": False,
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,12 +24,12 @@ import ConfigParser
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
|
|
||||||
from openerp import models, fields
|
from odoo import api, fields, models
|
||||||
from openerp.tools.config import config as system_base_config
|
from odoo.tools.config import config as system_base_config
|
||||||
|
|
||||||
from .system_info import get_server_environment
|
from .system_info import get_server_environment
|
||||||
|
|
||||||
from openerp.addons import server_environment_files
|
from odoo.addons import server_environment_files
|
||||||
_dir = os.path.dirname(server_environment_files.__file__)
|
_dir = os.path.dirname(server_environment_files.__file__)
|
||||||
|
|
||||||
# Same dict as RawConfigParser._boolean_states
|
# Same dict as RawConfigParser._boolean_states
|
||||||
|
|
@ -103,6 +103,7 @@ def _load_config():
|
||||||
|
|
||||||
return config_p
|
return config_p
|
||||||
|
|
||||||
|
|
||||||
serv_config = _load_config()
|
serv_config = _load_config()
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -120,63 +121,71 @@ class ServerConfiguration(models.TransientModel):
|
||||||
_name = 'server.config'
|
_name = 'server.config'
|
||||||
_conf_defaults = _Defaults()
|
_conf_defaults = _Defaults()
|
||||||
|
|
||||||
def __init__(self, pool, cr):
|
@classmethod
|
||||||
|
def _build_model(cls, pool, cr):
|
||||||
"""Add columns to model dynamically
|
"""Add columns to model dynamically
|
||||||
and init some properties
|
and init some properties
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self._add_columns()
|
ModelClass = super(ServerConfiguration, cls)._build_model(pool, cr)
|
||||||
super(ServerConfiguration, self).__init__(pool, cr)
|
ModelClass._add_columns()
|
||||||
self.running_env = system_base_config['running_env']
|
ModelClass.running_env = system_base_config['running_env']
|
||||||
# Only show passwords in development
|
# Only show passwords in development
|
||||||
self.show_passwords = self.running_env in ('dev',)
|
ModelClass.show_passwords = ModelClass.running_env in ('dev',)
|
||||||
self._arch = None
|
ModelClass._arch = None
|
||||||
self._build_osv()
|
ModelClass._build_osv()
|
||||||
|
return ModelClass
|
||||||
|
|
||||||
def _format_key(self, section, key):
|
@classmethod
|
||||||
|
def _format_key(cls, section, key):
|
||||||
return '%s | %s' % (section, key)
|
return '%s | %s' % (section, key)
|
||||||
|
|
||||||
def _add_columns(self):
|
@classmethod
|
||||||
|
def _add_columns(cls):
|
||||||
"""Add columns to model dynamically"""
|
"""Add columns to model dynamically"""
|
||||||
cols = chain(
|
cols = chain(
|
||||||
self._get_base_cols().items(),
|
cls._get_base_cols().items(),
|
||||||
self._get_env_cols().items(),
|
cls._get_env_cols().items(),
|
||||||
self._get_system_cols().items()
|
cls._get_system_cols().items()
|
||||||
)
|
)
|
||||||
for col, value in cols:
|
for col, value in cols:
|
||||||
col_name = col.replace('.', '_')
|
col_name = col.replace('.', '_')
|
||||||
setattr(ServerConfiguration,
|
setattr(ServerConfiguration,
|
||||||
col_name,
|
col_name,
|
||||||
fields.Char(string=col, readonly=True))
|
fields.Char(string=col, readonly=True))
|
||||||
self._conf_defaults[col_name] = value
|
cls._conf_defaults[col_name] = value
|
||||||
|
|
||||||
def _get_base_cols(self):
|
@classmethod
|
||||||
|
def _get_base_cols(cls):
|
||||||
""" Compute base fields"""
|
""" Compute base fields"""
|
||||||
res = {}
|
res = {}
|
||||||
for col, item in system_base_config.options.items():
|
for col, item in system_base_config.options.items():
|
||||||
key = self._format_key('openerp', col)
|
key = cls._format_key('odoo', col)
|
||||||
res[key] = item
|
res[key] = item
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def _get_env_cols(self, sections=None):
|
@classmethod
|
||||||
|
def _get_env_cols(cls, sections=None):
|
||||||
""" Compute base fields"""
|
""" Compute base fields"""
|
||||||
res = {}
|
res = {}
|
||||||
sections = sections if sections else serv_config.sections()
|
sections = sections if sections else serv_config.sections()
|
||||||
for section in sections:
|
for section in sections:
|
||||||
for col, item in serv_config.items(section):
|
for col, item in serv_config.items(section):
|
||||||
key = self._format_key(section, col)
|
key = cls._format_key(section, col)
|
||||||
res[key] = item
|
res[key] = item
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def _get_system_cols(self):
|
@classmethod
|
||||||
|
def _get_system_cols(cls):
|
||||||
""" Compute system fields"""
|
""" Compute system fields"""
|
||||||
res = {}
|
res = {}
|
||||||
for col, item in get_server_environment():
|
for col, item in get_server_environment():
|
||||||
key = self._format_key('system', col)
|
key = cls._format_key('system', col)
|
||||||
res[key] = item
|
res[key] = item
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def _group(self, items):
|
@classmethod
|
||||||
|
def _group(cls, items):
|
||||||
"""Return an XML chunk which represents a group of fields."""
|
"""Return an XML chunk which represents a group of fields."""
|
||||||
names = []
|
names = []
|
||||||
|
|
||||||
|
|
@ -187,55 +196,55 @@ class ServerConfiguration(models.TransientModel):
|
||||||
_escape(name) for name in names]) +
|
_escape(name) for name in names]) +
|
||||||
'</group>')
|
'</group>')
|
||||||
|
|
||||||
def _build_osv(self):
|
@classmethod
|
||||||
|
def _build_osv(cls):
|
||||||
"""Build the view for the current configuration."""
|
"""Build the view for the current configuration."""
|
||||||
arch = ('<?xml version="1.0" encoding="utf-8"?>'
|
arch = ('<?xml version="1.0" encoding="utf-8"?>'
|
||||||
'<form string="Configuration Form">'
|
'<form string="Configuration Form">'
|
||||||
'<notebook colspan="4">')
|
'<notebook colspan="4">')
|
||||||
|
|
||||||
# OpenERP server configuration
|
# Odoo server configuration
|
||||||
rcfile = system_base_config.rcfile
|
rcfile = system_base_config.rcfile
|
||||||
items = self._get_base_cols()
|
items = cls._get_base_cols()
|
||||||
arch += '<page string="OpenERP">'
|
arch += '<page string="Odoo">'
|
||||||
arch += '<separator string="%s" colspan="4"/>' % _escape(rcfile)
|
arch += '<separator string="%s" colspan="4"/>' % _escape(rcfile)
|
||||||
arch += self._group(items)
|
arch += cls._group(items)
|
||||||
arch += '<separator colspan="4"/></page>'
|
arch += '<separator colspan="4"/></page>'
|
||||||
|
|
||||||
arch += '<page string="Environment based configurations">'
|
arch += '<page string="Environment based configurations">'
|
||||||
for section in sorted(serv_config.sections()):
|
for section in sorted(serv_config.sections()):
|
||||||
items = self._get_env_cols(sections=[section])
|
items = cls._get_env_cols(sections=[section])
|
||||||
arch += '<separator string="[%s]" colspan="4"/>' % _escape(section)
|
arch += '<separator string="[%s]" colspan="4"/>' % _escape(section)
|
||||||
arch += self._group(items)
|
arch += cls._group(items)
|
||||||
arch += '<separator colspan="4"/></page>'
|
arch += '<separator colspan="4"/></page>'
|
||||||
|
|
||||||
# System information
|
# System information
|
||||||
arch += '<page string="System">'
|
arch += '<page string="System">'
|
||||||
arch += '<separator string="Server Environment" colspan="4"/>'
|
arch += '<separator string="Server Environment" colspan="4"/>'
|
||||||
arch += self._group(self._get_system_cols())
|
arch += cls._group(cls._get_system_cols())
|
||||||
arch += '<separator colspan="4"/></page>'
|
arch += '<separator colspan="4"/></page>'
|
||||||
|
|
||||||
arch += '</notebook></form>'
|
arch += '</notebook></form>'
|
||||||
self._arch = etree.fromstring(arch)
|
cls._arch = etree.fromstring(arch)
|
||||||
|
|
||||||
def fields_view_get(self, cr, uid, view_id=None, view_type='form',
|
@api.model
|
||||||
context=None, toolbar=False, submenu=False):
|
def fields_view_get(self, view_id=None, view_type='form', toolbar=False,
|
||||||
|
submenu=False):
|
||||||
"""Overwrite the default method to render the custom view."""
|
"""Overwrite the default method to render the custom view."""
|
||||||
res = super(ServerConfiguration, self).fields_view_get(cr, uid,
|
res = super(ServerConfiguration, self).fields_view_get(view_id,
|
||||||
view_id,
|
|
||||||
view_type,
|
view_type,
|
||||||
context,
|
|
||||||
toolbar)
|
toolbar)
|
||||||
|
View = self.env['ir.ui.view']
|
||||||
if view_type == 'form':
|
if view_type == 'form':
|
||||||
arch_node = self._arch
|
arch_node = self._arch
|
||||||
xarch, xfields = self._view_look_dom_arch(cr, uid,
|
xarch, xfields = View.postprocess_and_fields(
|
||||||
arch_node,
|
self._name, arch_node, view_id)
|
||||||
view_id,
|
|
||||||
context=context)
|
|
||||||
res['arch'] = xarch
|
res['arch'] = xarch
|
||||||
res['fields'] = xfields
|
res['fields'] = xfields
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def default_get(self, cr, uid, fields_list, context=None):
|
@api.model
|
||||||
|
def default_get(self, fields_list):
|
||||||
res = {}
|
res = {}
|
||||||
for key in self._conf_defaults:
|
for key in self._conf_defaults:
|
||||||
if 'passw' in key and not self.show_passwords:
|
if 'passw' in key and not self.show_passwords:
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<openerp>
|
<odoo>
|
||||||
<data>
|
|
||||||
|
|
||||||
<act_window id="act_show_config_window"
|
<act_window id="act_show_config_window"
|
||||||
name="Server Environment"
|
name="Server Environment"
|
||||||
res_model="server.config"
|
res_model="server.config"
|
||||||
|
|
@ -10,10 +8,8 @@
|
||||||
|
|
||||||
<menuitem
|
<menuitem
|
||||||
parent="base.menu_ir_property"
|
parent="base.menu_ir_property"
|
||||||
icon="STOCK_PROPERTIES"
|
|
||||||
sequence="90"
|
sequence="90"
|
||||||
action="act_show_config_window"
|
action="act_show_config_window"
|
||||||
id="menu_server_show_config"/>
|
id="menu_server_show_config"/>
|
||||||
|
|
||||||
</data>
|
</odoo>
|
||||||
</openerp>
|
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,8 @@ import os
|
||||||
import platform
|
import platform
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from openerp import release
|
from odoo import release
|
||||||
from openerp.tools.config import config
|
from odoo.tools.config import config
|
||||||
|
|
||||||
|
|
||||||
def _get_output(cmd):
|
def _get_output(cmd):
|
||||||
|
|
@ -61,6 +61,6 @@ def get_server_environment():
|
||||||
('architecture', platform.architecture()[0]),
|
('architecture', platform.architecture()[0]),
|
||||||
('locale', os_lang),
|
('locale', os_lang),
|
||||||
('python', platform.python_version()),
|
('python', platform.python_version()),
|
||||||
('openerp', release.version),
|
('odoo', release.version),
|
||||||
('revision', rev_id),
|
('revision', rev_id),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,8 @@
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
from openerp.tests import common
|
from odoo.tests import common
|
||||||
from openerp.addons.server_environment import serv_config
|
from odoo.addons.server_environment import serv_config
|
||||||
|
|
||||||
|
|
||||||
class TestEnv(common.TransactionCase):
|
class TestEnv(common.TransactionCase):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue