Stefan Rijnhart (Therp) has proposed merging lp:~therp-nl/openupgrade-server/8.0-openupgrade_records_style into lp:openupgrade-server/8.0.
Requested reviews: OpenUpgrade Committers (openupgrade-committers) For more details, see: https://code.launchpad.net/~therp-nl/openupgrade-server/8.0-openupgrade_records_style/+merge/218278 - Try not to import deprecated API: osv.osv and friends - Reset apriori knowledge for the 8.0 edition - Flake8 -- https://code.launchpad.net/~therp-nl/openupgrade-server/8.0-openupgrade_records_style/+merge/218278 Your team OpenUpgrade Committers is requested to review the proposed merge of lp:~therp-nl/openupgrade-server/8.0-openupgrade_records_style into lp:openupgrade-server/8.0.
=== modified file 'openerp/addons/openupgrade_records/__openerp__.py' --- openerp/addons/openupgrade_records/__openerp__.py 2014-04-08 10:54:25 +0000 +++ openerp/addons/openupgrade_records/__openerp__.py 2014-05-05 12:51:20 +0000 @@ -2,7 +2,7 @@ ############################################################################## # # OpenERP, Open Source Management Solution -# This module Copyright (C) 2012 OpenUpgrade community +# This module Copyright (C) 2012-2014 OpenUpgrade community # https://launchpad.net/~openupgrade-committers # # Contributors: @@ -28,7 +28,7 @@ 'name': 'OpenUpgrade Records', 'version': '0.2', 'category': 'Normal', - 'description': """Allow OpenUpgrade records to be + 'description': """Allow OpenUpgrade records to be stored in the database and compare with other servers. This module depends on OpenERP client lib: @@ -57,7 +57,7 @@ 'installable': True, 'auto_install': False, 'external_dependencies': { - 'python' : ['openerplib'], + 'python': ['openerplib'], }, } # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: === modified file 'openerp/addons/openupgrade_records/__terp__.py' --- openerp/addons/openupgrade_records/__terp__.py 2014-04-08 10:54:25 +0000 +++ openerp/addons/openupgrade_records/__terp__.py 2014-05-05 12:51:20 +0000 @@ -2,7 +2,7 @@ ############################################################################## # # OpenERP, Open Source Management Solution -# This module Copyright (C) 2012 OpenUpgrade community +# This module Copyright (C) 2012-2014 OpenUpgrade community # https://launchpad.net/~openupgrade-committers # # Contributors: @@ -28,7 +28,7 @@ 'name': 'OpenUpgrade Records', 'version': '0.2', 'category': 'Normal', - 'description': """Allow OpenUpgrade records to be + 'description': """Allow OpenUpgrade records to be stored in the database and compare with other servers. This module depends on OpenERP client lib: @@ -57,7 +57,7 @@ 'installable': True, 'auto_install': False, 'external_dependencies': { - 'python' : ['openerplib'], + 'python': ['openerplib'], }, } # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: === modified file 'openerp/addons/openupgrade_records/lib/apriori.py' --- openerp/addons/openupgrade_records/lib/apriori.py 2014-04-08 10:54:25 +0000 +++ openerp/addons/openupgrade_records/lib/apriori.py 2014-05-05 12:51:20 +0000 @@ -3,11 +3,6 @@ """ renamed_modules = { - 'account_coda': 'l10n_be_coda', - 'base_crypt': 'auth_crypt', - 'mrp_subproduct': 'mrp_byproduct', - 'users_ldap': 'auth_ldap', - 'wiki': 'document_page', } renamed_models = { === modified file 'openerp/addons/openupgrade_records/lib/compare.py' --- openerp/addons/openupgrade_records/lib/compare.py 2014-04-08 10:54:25 +0000 +++ openerp/addons/openupgrade_records/lib/compare.py 2014-05-05 12:51:20 +0000 @@ -45,10 +45,12 @@ 'inherits', ] + def module_map(module): return apriori.renamed_modules.get( module, module) + def compare_records(dict_old, dict_new, fields): """ Check equivalence of two OpenUpgrade field representations @@ -70,6 +72,7 @@ return False return True + def search(item, item_list, fields): """ Find a match of a dictionary in a list of similar dictionaries @@ -82,6 +85,7 @@ return i return None + def fieldprint(old, new, field, text, reprs): fieldrepr = "%s (%s)" % (old['field'], old['type']) repr = '%s / %s / %s' % ( @@ -94,6 +98,7 @@ "%s: %s is now \'%s\' ('%s')" % ( repr, field, new[field], old[field])) + def report_generic(new, old, attrs, reprs): for attr in attrs: if attr == 'required': @@ -113,6 +118,7 @@ if old[attr] != new[attr]: fieldprint(old, new, attr, None, reprs) + def compare_sets(old_records, new_records): """ Compare a set of OpenUpgrade field representations. @@ -126,15 +132,15 @@ for record in old_records + new_records: record['matched'] = False origlen = len(old_records) - new_models = set([ column['model'] for column in new_records ]) - old_models = set([ column['model'] for column in old_records ]) + new_models = set([column['model'] for column in new_records]) + old_models = set([column['model'] for column in old_records]) matched_direct = 0 matched_other_module = 0 matched_other_type = 0 matched_other_name = 0 in_obsolete_models = 0 - + obsolete_models = [] for model in old_models: if model not in new_models: @@ -149,7 +155,7 @@ for model in new_models: if model not in old_models: reprs['general'].append('new model %s' % model) - + def match(match_fields, report_fields, warn=False): count = 0 for column in copy.copy(old_records): @@ -166,17 +172,20 @@ matched_direct = match( ['module', 'mode', 'model', 'field'], - ['relation', 'type', 'selection_keys', 'inherits', 'isfunction', 'required']) + ['relation', 'type', 'selection_keys', 'inherits', + 'isfunction', 'required']) # other module, same type and operation matched_other_module = match( ['mode', 'model', 'field', 'type'], - ['module', 'relation', 'selection_keys', 'inherits', 'isfunction', 'required']) + ['module', 'relation', 'selection_keys', 'inherits', + 'isfunction', 'required']) # other module, same operation, other type matched_other_type = match( ['mode', 'model', 'field'], - ['relation', 'type', 'selection_keys', 'inherits', 'isfunction', 'required']) + ['relation', 'type', 'selection_keys', 'inherits', + 'isfunction', 'required']) # fields with other names #matched_other_name = match( @@ -209,18 +218,19 @@ ), reprs) for line in [ - "# %d fields matched," % (origlen - len(old_records)), - "# Direct match: %d" % matched_direct, - "# Found in other module: %d" % matched_other_module, - "# Found with different type: %d" % matched_other_type, - "# Found with different name: %d" % matched_other_name, - "# In obsolete models: %d" % in_obsolete_models, - "# Not matched: %d" % len(old_records), - "# New columns: %d" % len(new_records), - ]: + "# %d fields matched," % (origlen - len(old_records)), + "# Direct match: %d" % matched_direct, + "# Found in other module: %d" % matched_other_module, + "# Found with different type: %d" % matched_other_type, + "# Found with different name: %d" % matched_other_name, + "# In obsolete models: %d" % in_obsolete_models, + "# Not matched: %d" % len(old_records), + "# New columns: %d" % len(new_records) + ]: reprs['general'].append(line) return reprs + def compare_xml_sets(old_records, new_records): reprs = {} match_fields = ['module', 'model', 'name'] @@ -241,10 +251,8 @@ ) for entry in sorted_records: if 'old' in entry: - content = 'DEL %s: %s' % (entry['model'], - entry['name']) + content = 'DEL %s: %s' % (entry['model'], entry['name']) elif 'new' in entry: - content = 'NEW %s: %s' % (entry['model'], - entry['name']) + content = 'NEW %s: %s' % (entry['model'], entry['name']) reprs.setdefault(module_map(entry['module']), []).append(content) return reprs === modified file 'openerp/addons/openupgrade_records/model/__init__.py' --- openerp/addons/openupgrade_records/model/__init__.py 2014-04-08 10:54:25 +0000 +++ openerp/addons/openupgrade_records/model/__init__.py 2014-05-05 12:51:20 +0000 @@ -3,4 +3,3 @@ import analysis_wizard import generate_records_wizard import install_all_wizard - === modified file 'openerp/addons/openupgrade_records/model/analysis_wizard.py' --- openerp/addons/openupgrade_records/model/analysis_wizard.py 2014-04-08 10:54:25 +0000 +++ openerp/addons/openupgrade_records/model/analysis_wizard.py 2014-05-05 12:51:20 +0000 @@ -2,7 +2,7 @@ ############################################################################## # # OpenERP, Open Source Management Solution -# This module Copyright (C) 2012 OpenUpgrade community +# This module Copyright (C) 2012-2014 OpenUpgrade community # https://launchpad.net/~openupgrade-committers # # Contributors: @@ -24,18 +24,20 @@ ############################################################################## import os -from openerp.osv import osv, fields try: + from openerp.osv.orm import TransientModel + from openerp.osv import fields from openerp.addons.openupgrade_records.lib import compare - from openerp.addons.openupgrade_records.lib import apriori from openerp.addons import get_module_path except ImportError: + from osv.osv import osv_memory as TransientModel + from osv import fields from openupgrade_records.lib import compare - from openupgrade_records.lib import apriori from addons import get_module_path -class openupgrade_analysis_wizard(osv.osv_memory): + +class openupgrade_analysis_wizard(TransientModel): _name = 'openupgrade.analysis.wizard' _description = 'OpenUpgrade Analysis Wizard' _columns = { @@ -62,8 +64,8 @@ perform the comparison and register the resulting change set """ - def write_file( - module, version, contents, filename='openupgrade_analysis.txt'): + def write_file(module, version, contents, + filename='openupgrade_analysis.txt'): module_path = get_module_path(module) if not module_path: return "ERROR: could not find module path:\n" @@ -94,7 +96,8 @@ # Retrieve field representations and compare remote_records = remote_record_obj.field_dump(context) local_records = local_record_obj.field_dump(cr, uid, context) - modules_record = set([record['module'] for record in remote_records + local_records]) + modules_record = set([record['module'] + for record in remote_records + local_records]) res = compare.compare_sets(remote_records, local_records) # Retrieve xml id representations and compare @@ -113,7 +116,9 @@ for x in remote_record_obj.read( remote_xml_record_ids, fields) ] - modules_xml_records = set([record['module'] for record in remote_xml_records + local_xml_records]) + modules_xml_records = set( + [record['module'] + for record in remote_xml_records + local_xml_records]) res_xml = compare.compare_xml_sets( remote_xml_records, local_xml_records) @@ -122,12 +127,14 @@ module_obj = self.pool.get('ir.module.module') module_ids = module_obj.search( cr, uid, [('state', '=', 'installed')]) - modules = dict([(x['name'], x) for x in module_obj.read(cr, uid, module_ids)]) + modules = dict( + [(x['name'], x) for x in module_obj.read(cr, uid, module_ids)]) general = '' for key in keys: contents = "---Fields in module '%s'---\n" % key if key in res: - contents += '\n'.join([unicode(line) for line in sorted(res[key])]) + contents += '\n'.join( + [unicode(line) for line in sorted(res[key])]) if res[key]: contents += '\n' contents += "---XML records in module '%s'---\n" % key @@ -178,4 +185,3 @@ return result openupgrade_analysis_wizard() - === modified file 'openerp/addons/openupgrade_records/model/comparison_config.py' --- openerp/addons/openupgrade_records/model/comparison_config.py 2014-04-08 10:54:25 +0000 +++ openerp/addons/openupgrade_records/model/comparison_config.py 2014-05-05 12:51:20 +0000 @@ -2,7 +2,7 @@ ############################################################################## # # OpenERP, Open Source Management Solution -# This module Copyright (C) 2012 OpenUpgrade community +# This module Copyright (C) 2012-2014 OpenUpgrade community # https://launchpad.net/~openupgrade-committers # # Contributors: @@ -23,11 +23,18 @@ # ############################################################################## -from openerp.osv import osv, fields import openerplib -from openerp.tools.translate import _ - -class openupgrade_comparison_config(osv.osv): +try: + from openerp.osv.orm import Model, except_orm + from openerp.osv import fields + from openerp.tools.translate import _ +except ImportError: + from osv.osv import osv as Model, except_osv as except_orm + from osv import fields + from tools.translate import _ + + +class openupgrade_comparison_config(Model): _name = 'openupgrade.comparison.config' _columns = { 'name': fields.char('Name', size=64), @@ -39,7 +46,8 @@ 'Protocol', required=True), 'database': fields.char('Database', size=64, required=True), 'username': fields.char('Username', size=24, required=True), - 'password': fields.char('Password', size=24, required=True, password=True), + 'password': fields.char('Password', size=24, required=True, + password=True), 'last_log': fields.text('Last log'), } _defaults = { @@ -49,16 +57,16 @@ def get_connection(self, cr, uid, ids, context=None): if not ids: - raise osv.except_osv( + raise except_orm( _("Cannot connect"), _("Invalid id passed.")) conf = self.read(cr, uid, ids[0], context=None) return openerplib.get_connection( - hostname=conf['server'], - database=conf['database'], - login=conf['username'], - password=conf['password'], - port=conf['port'], - ) + hostname=conf['server'], + database=conf['database'], + login=conf['username'], + password=conf['password'], + port=conf['port'], + ) def test_connection(self, cr, uid, ids, context=None): try: @@ -67,13 +75,13 @@ ids = user_model.search([("login", "=", "admin")]) user_info = user_model.read(ids[0], ["name"]) except Exception, e: - raise osv.except_osv( + raise except_orm( _("Connection failed."), unicode(e)) - raise osv.except_osv( + raise except_orm( _("Connection succesful."), _("%s is connected.") % user_info["name"] ) - + def analyze(self, cr, uid, ids, context=None): """ Run the analysis wizard === modified file 'openerp/addons/openupgrade_records/model/generate_records_wizard.py' --- openerp/addons/openupgrade_records/model/generate_records_wizard.py 2014-04-08 10:54:25 +0000 +++ openerp/addons/openupgrade_records/model/generate_records_wizard.py 2014-05-05 12:51:20 +0000 @@ -2,7 +2,7 @@ ############################################################################## # # OpenERP, Open Source Management Solution -# This module Copyright (C) 2012 OpenUpgrade community +# This module Copyright (C) 2012-2014 OpenUpgrade community # https://launchpad.net/~openupgrade-committers # # Contributors: @@ -23,19 +23,24 @@ # ############################################################################## -import os -from openerp.osv import osv, fields -from openerp import pooler try: + from openerp.osv.orm import TransientModel, except_orm + from openerp.osv import fields from openerp.openupgrade import openupgrade_tools + from openerp import pooler except ImportError: + from osv.osv import osv_memory as TransientModel, except_osv as except_orm + from osv import fields from openupgrade import openupgrade_tools - -class generate_records_wizard(osv.osv_memory): + import pooler + + +class generate_records_wizard(TransientModel): _name = 'openupgrade.generate.records.wizard' _description = 'OpenUpgrade Generate Records Wizard' _columns = { - 'state': fields.selection([('init', 'init'), ('ready', 'ready')], 'State'), + 'state': fields.selection( + [('init', 'init'), ('ready', 'ready')], 'State'), } _defaults = { 'state': lambda *a: 'init', @@ -53,7 +58,7 @@ """ # Truncate the records table if (openupgrade_tools.table_exists(cr, 'openupgrade_attribute') and - openupgrade_tools.table_exists(cr, 'openupgrade_record')): + openupgrade_tools.table_exists(cr, 'openupgrade_record')): cr.execute( 'TRUNCATE openupgrade_attribute, openupgrade_record;' ) @@ -71,8 +76,8 @@ if module_ids: modules = module_obj.read( cr, uid, module_ids, ['name'], context=context) - raise except_osv( - "Cannot reliably generate records", + raise except_orm( + "Cannot reliably generate records", ("Cannot seem to install or upgrade modules " + ', '.join([x['name'] for x in modules]))) # Now reinitialize all installed modules @@ -87,4 +92,3 @@ return True generate_records_wizard() - === modified file 'openerp/addons/openupgrade_records/model/install_all_wizard.py' --- openerp/addons/openupgrade_records/model/install_all_wizard.py 2014-04-08 10:54:25 +0000 +++ openerp/addons/openupgrade_records/model/install_all_wizard.py 2014-05-05 12:51:20 +0000 @@ -2,7 +2,7 @@ ############################################################################## # # OpenERP, Open Source Management Solution -# This module Copyright (C) 2012 OpenUpgrade community +# This module Copyright (C) 2012-2014 OpenUpgrade community # https://launchpad.net/~openupgrade-committers # # Contributors: @@ -24,22 +24,29 @@ ############################################################################## import time -import os -from openerp.osv import osv, fields -from openerp import pooler - -class install_all_wizard(osv.osv_memory): +try: + from openerp.osv.orm import TransientModel + from openerp.osv import fields + from openerp import pooler +except ImportError: + from osv.osv import osv_memory as TransientModel + from osv import fields + import pooler + + +class install_all_wizard(TransientModel): _name = 'openupgrade.install.all.wizard' _description = 'OpenUpgrade Install All Wizard' _columns = { - 'state': fields.selection([('init', 'init'), ('ready', 'ready')], 'State', readonly=True), - 'to_install': fields.integer('Number of modules to install', readonly=True), + 'state': fields.selection( + [('init', 'init'), ('ready', 'ready')], 'State', readonly=True), + 'to_install': fields.integer( + 'Number of modules to install', readonly=True), } _defaults = { 'state': lambda *a: 'init', } - def default_get(self, cr, uid, fields, context=None): """ Update module list and retrieve the number @@ -51,18 +58,21 @@ update, add = module_obj.update_list(cr, uid,) print "%s modules added" % add module_ids = module_obj.search( - cr, uid, [('state', 'not in', ['installed', 'uninstallable', 'unknown'])]) + cr, uid, [ + ('state', 'not in', + ['installed', 'uninstallable', 'unknown']) + ]) res.update( {'to_install': module_ids and len(module_ids) or False} ) return res def quirk_fiscalyear(self, cr, uid, ids, context=None): - """ + """ Install account module first and create a fiscal year, in order to prevent "No fiscal year defined" exception during an upgrade or reinstallation of the account module. - + Refer to account_fiscalyear.find(), which is called as a default function by the orm upon module upgrade. """ @@ -87,12 +97,12 @@ fy_obj = pool.get('account.fiscalyear') if not fy_obj.find(cr, uid, False, exception=False, context=context): fy_obj.create(cr, uid, { - 'name': time.strftime('%Y'), - 'code': time.strftime('%Y'), - 'date_start': "%s-01-01" % time.strftime('%Y'), - 'date_stop': "%s-12-31" % time.strftime('%Y'), - }) - + 'name': time.strftime('%Y'), + 'code': time.strftime('%Y'), + 'date_start': "%s-01-01" % time.strftime('%Y'), + 'date_stop': "%s-12-31" % time.strftime('%Y'), + }) + def install_all(self, cr, uid, ids, context=None): """ Main wizard step. Set all installable modules to install @@ -100,7 +110,9 @@ """ module_obj = self.pool.get('ir.module.module') module_ids = module_obj.search( - cr, uid, [('state', 'not in', ['installed', 'uninstallable', 'unknown'])]) + cr, uid, [ + ('state', 'not in', + ['installed', 'uninstallable', 'unknown'])]) if module_ids: module_obj.write( cr, uid, module_ids, {'state': 'to install'}) @@ -110,4 +122,3 @@ return True install_all_wizard() - === modified file 'openerp/addons/openupgrade_records/model/openupgrade_record.py' --- openerp/addons/openupgrade_records/model/openupgrade_record.py 2014-04-08 10:54:25 +0000 +++ openerp/addons/openupgrade_records/model/openupgrade_record.py 2014-05-05 12:51:20 +0000 @@ -2,7 +2,7 @@ ############################################################################## # # OpenERP, Open Source Management Solution -# This module Copyright (C) 2012 OpenUpgrade community +# This module Copyright (C) 2012-2014 OpenUpgrade community # https://launchpad.net/~openupgrade-committers # # Contributors: @@ -23,14 +23,21 @@ # ############################################################################## -from openerp.osv import osv, fields +try: + from openerp.osv.orm import Model + from openerp.osv import fields +except ImportError: + from osv.osv import osv as Model + from osv import fields + # Cannot use forward references in 6.0 -class openupgrade_record(osv.osv): +class openupgrade_record(Model): _name = 'openupgrade.record' openupgrade_record() -class openupgrade_attribute(osv.osv): + +class openupgrade_attribute(Model): _name = 'openupgrade.attribute' _rec_name = 'name' _columns = { @@ -50,7 +57,8 @@ } openupgrade_attribute() -class openupgrade_record(osv.osv): + +class openupgrade_record(Model): _inherit = 'openupgrade.record' _columns = { @@ -65,7 +73,7 @@ 'in this module. If this module modifies an attribute of an ' 'exting field, set to Modify.', readonly=True, - ), + ), 'type': fields.selection( [('field', 'Field'), ('xmlid', 'XML ID')], 'Type', @@ -76,6 +84,7 @@ readonly=True, ), } + def field_dump(self, cr, uid, context=None): keys = [ 'module', @@ -98,11 +107,11 @@ for record in records: repr = template.copy() repr.update({ - 'module': record.module, - 'model': record.model, - 'field': record.field, - 'mode': record.mode, - }) + 'module': record.module, + 'model': record.model, + 'field': record.field, + 'mode': record.mode, + }) repr.update( dict([(x.name, x.value) for x in record.attribute_ids])) data.append(repr)
-- Mailing list: https://launchpad.net/~credativ Post to : [email protected] Unsubscribe : https://launchpad.net/~credativ More help : https://help.launchpad.net/ListHelp

