Browse Source

Migration of server_environment to 10.0

pull/595/head
Adrien Peiffer (ACSONE) 8 years ago
committed by Stéphane Bidoul (ACSONE)
parent
commit
0438f4ed83
  1. 8
      server_environment/README.rst
  2. 4
      server_environment/__manifest__.py
  3. 92
      server_environment/serv_config.py
  4. 5
      server_environment/serv_config.xml
  5. 6
      server_environment/system_info.py
  6. 4
      server_environment/tests/test_server_environment.py
  7. 6
      server_environment_files_sample/README.rst
  8. 4
      server_environment_files_sample/__manifest__.py

8
server_environment/README.rst

@ -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
: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
@ -85,11 +85,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues
<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,
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**>`_.
help us smashing it by providing a detailed and welcomed feedback.
Credits
=======

4
server_environment/__manifest__.py

@ -21,7 +21,7 @@
{
"name": "server configuration environment files",
"version": "9.0.1.2.0",
"version": "10.0.1.2.0",
"depends": ["base", "server_environment_files"],
"author": "Camptocamp,Odoo Community Association (OCA)",
"summary": "move some configurations out of the database",
@ -31,6 +31,4 @@
"data": [
'serv_config.xml',
],
'installable': False,
"active": False,
}

92
server_environment/serv_config.py

@ -24,12 +24,12 @@ import ConfigParser
from lxml import etree
from itertools import chain
from openerp import models, fields
from openerp.tools.config import config as system_base_config
from odoo import api, fields, models
from odoo.tools.config import config as system_base_config
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__)
# Same dict as RawConfigParser._boolean_states
@ -120,63 +120,71 @@ class ServerConfiguration(models.TransientModel):
_name = 'server.config'
_conf_defaults = _Defaults()
def __init__(self, pool, cr):
@classmethod
def _build_model(cls, pool, cr):
"""Add columns to model dynamically
and init some properties
"""
self._add_columns()
super(ServerConfiguration, self).__init__(pool, cr)
self.running_env = system_base_config['running_env']
ModelClass = super(ServerConfiguration, cls)._build_model(pool, cr)
ModelClass._add_columns()
ModelClass.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()
ModelClass.show_passwords = ModelClass.running_env in ('dev',)
ModelClass._arch = None
ModelClass._build_osv()
return ModelClass
def _format_key(self, section, key):
@classmethod
def _format_key(cls, section, key):
return '%s | %s' % (section, key)
def _add_columns(self):
@classmethod
def _add_columns(cls):
"""Add columns to model dynamically"""
cols = chain(
self._get_base_cols().items(),
self._get_env_cols().items(),
self._get_system_cols().items()
cls._get_base_cols().items(),
cls._get_env_cols().items(),
cls._get_system_cols().items()
)
for col, value in cols:
col_name = col.replace('.', '_')
setattr(ServerConfiguration,
col_name,
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"""
res = {}
for col, item in system_base_config.options.items():
key = self._format_key('openerp', col)
key = cls._format_key('odoo', col)
res[key] = item
return res
def _get_env_cols(self, sections=None):
@classmethod
def _get_env_cols(cls, sections=None):
""" Compute base fields"""
res = {}
sections = sections if sections else serv_config.sections()
for section in sections:
for col, item in serv_config.items(section):
key = self._format_key(section, col)
key = cls._format_key(section, col)
res[key] = item
return res
def _get_system_cols(self):
@classmethod
def _get_system_cols(cls):
""" Compute system fields"""
res = {}
for col, item in get_server_environment():
key = self._format_key('system', col)
key = cls._format_key('system', col)
res[key] = item
return res
def _group(self, items):
@classmethod
def _group(cls, items):
"""Return an XML chunk which represents a group of fields."""
names = []
@ -187,55 +195,55 @@ class ServerConfiguration(models.TransientModel):
_escape(name) for name in names]) +
'</group>')
def _build_osv(self):
@classmethod
def _build_osv(cls):
"""Build the view for the current configuration."""
arch = ('<?xml version="1.0" encoding="utf-8"?>'
'<form string="Configuration Form">'
'<notebook colspan="4">')
# OpenERP server configuration
# Odoo server configuration
rcfile = system_base_config.rcfile
items = self._get_base_cols()
arch += '<page string="OpenERP">'
items = cls._get_base_cols()
arch += '<page string="Odoo">'
arch += '<separator string="%s" colspan="4"/>' % _escape(rcfile)
arch += self._group(items)
arch += cls._group(items)
arch += '<separator colspan="4"/></page>'
arch += '<page string="Environment based configurations">'
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 += self._group(items)
arch += cls._group(items)
arch += '<separator colspan="4"/></page>'
# System information
arch += '<page string="System">'
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 += '</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',
context=None, toolbar=False, submenu=False):
@api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False,
submenu=False):
"""Overwrite the default method to render the custom view."""
res = super(ServerConfiguration, self).fields_view_get(cr, uid,
view_id,
res = super(ServerConfiguration, self).fields_view_get(view_id,
view_type,
context,
toolbar)
View = self.env['ir.ui.view']
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 = View.postprocess_and_fields(
self._name, arch_node, view_id)
res['arch'] = xarch
res['fields'] = xfields
return res
def default_get(self, cr, uid, fields_list, context=None):
@api.model
def default_get(self, fields_list):
res = {}
for key in self._conf_defaults:
if 'passw' in key and not self.show_passwords:

5
server_environment/serv_config.xml

@ -1,5 +1,5 @@
<?xml version="1.0"?>
<openerp>
<odoo>
<data>
<act_window id="act_show_config_window"
@ -10,10 +10,9 @@
<menuitem
parent="base.menu_ir_property"
icon="STOCK_PROPERTIES"
sequence="90"
action="act_show_config_window"
id="menu_server_show_config"/>
</data>
</openerp>
</odoo>

6
server_environment/system_info.py

@ -24,8 +24,8 @@ import os
import platform
import subprocess
from openerp import release
from openerp.tools.config import config
from odoo import release
from odoo.tools.config import config
def _get_output(cmd):
@ -61,6 +61,6 @@ def get_server_environment():
('architecture', platform.architecture()[0]),
('locale', os_lang),
('python', platform.python_version()),
('openerp', release.version),
('odoo', release.version),
('revision', rev_id),
)

4
server_environment/tests/test_server_environment.py

@ -18,8 +18,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.tests import common
from openerp.addons.server_environment import serv_config
from odoo.tests import common
from odoo.addons.server_environment import serv_config
class TestEnv(common.TransactionCase):

6
server_environment_files_sample/README.rst

@ -31,11 +31,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues
<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,
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**>`_.
help us smashing it by providing a detailed and welcomed feedback.
Credits
=======

4
server_environment_files_sample/__manifest__.py

@ -21,7 +21,7 @@
{
"name": "Example server configuration environment files repository module",
"version": "9.0.1.0.0",
"version": "10.0.1.0.0",
"depends": ["base"],
"author": "Camptocamp,Odoo Community Association (OCA)",
"summary": "sample config file for server_environment",
@ -29,6 +29,4 @@
"license": "GPL-3 or any later version",
"category": "Tools",
"data": [],
'installable': False,
"active": False,
}
Loading…
Cancel
Save