From d5debf686f752cbb417a3150eba48aaf10baaf1a Mon Sep 17 00:00:00 2001 From: nvi-openerp Date: Thu, 18 Nov 2010 10:34:12 +0100 Subject: [PATCH] [IMP] wip bzr revid: nicolas.vanhoren@openerp.com-20101118093412-czjcmcqupngfqjnt --- .bzrignore | 3 + bin/addons/base/ir/ir_config_parameter.py | 81 ++++++++++++++++++++++ bin/addons/base/maintenance/dbuuid.py | 45 ++++++++++++ bin/addons/base/maintenance/maintenance.py | 12 ++-- bin/tools/maintenance.py | 2 +- 5 files changed, 138 insertions(+), 5 deletions(-) create mode 100644 bin/addons/base/ir/ir_config_parameter.py create mode 100644 bin/addons/base/maintenance/dbuuid.py diff --git a/.bzrignore b/.bzrignore index 5581ee20f94..f67a6e2c6b6 100644 --- a/.bzrignore +++ b/.bzrignore @@ -18,3 +18,6 @@ bin/python2.6 build/ bin/yolk bin/pil*.py +.project +.pydevproject +.settings diff --git a/bin/addons/base/ir/ir_config_parameter.py b/bin/addons/base/ir/ir_config_parameter.py new file mode 100644 index 00000000000..a7502490ea4 --- /dev/null +++ b/bin/addons/base/ir/ir_config_parameter.py @@ -0,0 +1,81 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2009 Tiny SPRL (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +""" +A module to store some configuration parameters relative to a whole database. +""" + +from osv import osv,fields + +class ir_config_parameter(osv.osv): + """ An osv to old configuration parameters for a given database. + + To be short, it's just a global dictionnary of strings stored in a table. """ + + _name = 'ir.config_parameter' + + _columns = { + # The key of the configuration parameter. + 'key': fields.char('Key', size=256, required=True, select=1), + # The value of the configuration parameter. + 'value': fields.text('Value', required=True), + } + + _sql_constraints = [ + ('key_uniq', 'unique (key)', 'Key must be unique.') + ] + + def get_param(self, cr, uid, key, context=None): + """ Get the value of a parameter. + + @param key: The key of the parameter. + @type key: string + @return: The value of the parameter, False if it does not exist. + @rtype: string + """ + ids = self.search(cr, uid, [('key','=',key)], context=context) + if not ids: + return False + param = self.browse(cr, uid, ids[0], context=context) + value = param.value + return value + + def set_param(self, cr, uid, key, value, context=None): + """ Set the value of a parameter. + + @param key: The key of the parameter. + @type key: string + @param value: The value of the parameter. + @type value: string + @return: Return the previous value of the parameter of False if it did + not existed. + @rtype: string + """ + ids = self.search(cr, uid, [('key','=',key)], context=context) + if ids: + param = self.browse(cr, uid, ids[0], context=context) + old = param.value + self.write(cr, uid, ids, {'value': value}, context=context) + return old + else: + self.create(cr, uid, {'key': key, 'value': value}, context=context) + return False + +ir_config_parameter() diff --git a/bin/addons/base/maintenance/dbuuid.py b/bin/addons/base/maintenance/dbuuid.py new file mode 100644 index 00000000000..1cbb10fab1b --- /dev/null +++ b/bin/addons/base/maintenance/dbuuid.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2009 Tiny SPRL (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +""" +A module to handle a database UUID. That uuid will be stored in the osv +"ir.config_parameter" with key "database.uuid". +""" + +from osv import osv +import uuid + +class uuid_saver(osv.osv_memory): + """ An empty osv memory to init the uuid of the database the first it is + used. """ + + _name = 'maintenance.database_uuid_saver' + + def init(self, cr): + """ Checks that the database uuid was already created and create it if + it not the case. """ + params = self.pool.get('ir.config_parameter') + uniq = params.get_param(cr, 1, 'database.uuid') + if not uniq: + uniq = str(uuid.uuid1()) + params.set_param(cr, 1, 'database.uuid', uniq) + +uuid_saver() + diff --git a/bin/addons/base/maintenance/maintenance.py b/bin/addons/base/maintenance/maintenance.py index f4f97a2c5f5..a6e10c71e3c 100644 --- a/bin/addons/base/maintenance/maintenance.py +++ b/bin/addons/base/maintenance/maintenance.py @@ -22,11 +22,13 @@ from osv import osv, fields import time import netsvc - from tools.misc import ustr from tools.translate import _ import tools.maintenance as tm +_nlogger = netsvc.Logger() +_CHAN = __name__.split()[-1] + class maintenance_contract(osv.osv): _name = "maintenance.contract" _description = "Maintenance Contract" @@ -35,6 +37,7 @@ class maintenance_contract(osv.osv): return [contract for contract in self.browse(cr, uid, self.search(cr, uid, [])) if contract.state == 'valid'] def status(self, cr, uid): + """ Method called by the client to check availability of maintenance contract. """ contracts = self._get_valid_contracts(cr, uid) return { 'status': "full" if contracts else "none" , @@ -42,6 +45,7 @@ class maintenance_contract(osv.osv): } def send(self, cr, uid, tb, explanations, remarks=None): + """ Method called by the client to send a problem to the maintenance server. """ if not remarks: remarks = "" @@ -63,7 +67,7 @@ class maintenance_contract(osv.osv): origin = 'client' dbuuid = self.pool.get('ir.config_parameter').get_param(cr, uid, 'database.uuid') - crm_case_id = rc.submit({ + crm_case_id = rc.submit_6({ 'contract_name': contract_name, 'tb': tb, 'explanations': explanations, @@ -73,11 +77,11 @@ class maintenance_contract(osv.osv): 'dbuuid': dbuuid}) except tm.RemoteContractException, rce: - netsvc.Logger().notifyChannel('maintenance', netsvc.LOG_INFO, rce) + _nlogger.notifyChannel(_CHAN, netsvc.LOG_INFO, rce) except osv.except_osv: raise except: - pass # don't want to throw exceptions in exception handler + pass # we don't want to throw exceptions in an exception handler if not crm_case_id: return False diff --git a/bin/tools/maintenance.py b/bin/tools/maintenance.py index 6789ac5f8f8..f0488b957ac 100644 --- a/bin/tools/maintenance.py +++ b/bin/tools/maintenance.py @@ -82,7 +82,7 @@ def remote_contract(cr, uid, contract_id): _logger.exception("Exception") raise RemoteContractException("Unable to contact the migration server") - info = ro.check_contract({ + info = ro.check_contract_6({ "contract_name": contract_id, "dbuuid": dbuuid, "dbname": cr.dbname})