Commit 062d17ca authored by Jérome Perrin's avatar Jérome Perrin

upgrader: make upgrader pass coding style test

Change upgrader internal API to use `filter_dict` instead of `filter`
which is a builtin.
Remove a lot of unused code in extensions

/reviewed-on !1014
parent 21cd9c2f
Pipeline #7499 passed with stage
in 0 seconds
##############################################################################
#
# Copyright (c) 2009 Nexedi SA and Contributors. All Rights Reserved.
# Rafael Monnerat <rafael@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from Products.ERP5Type.Cache import CachingMethod
from App.config import getConfiguration
from AccessControl import Unauthorized
import os
# XXX This file is destinated to include methods or scripts that are not prevent
# into one old version. The methods here should be removed once the version
# installed into the instance is not supported anymore.
# XXX DO NOT KEEP LOCAL CHANGES HERE, ALL CHANGES SHOULD BE DONE ONLY IN
# INTROSPECTION TOOL OR TRUNK, AND BACKPORTED TO HERE LATER.
#########################################################################################
# Methods introduced into portal_introspection into 5.4.3
#
# XXX This method is a copy and paste of IntrospectionTool._loadExternalConfig
# This should be kept until versions lower than 5.4.3 still supported.
# NOT USED BY EXTERNAL METHOD
def _loadExternalConfig():
"""
Load configuration from one external file, this configuration
should be set for security reasons to prevent people access
forbidden areas in the system.
"""
def cached_loadExternalConfig():
import ConfigParser
config = ConfigParser.ConfigParser()
config.readfp(open('/etc/erp5.cfg'))
return config
cached_loadExternalConfig = CachingMethod(cached_loadExternalConfig,
id='IntrospectionTool__loadExternalConfig',
cache_factory='erp5_content_long')
return cached_loadExternalConfig()
# XXX This method is a copy and paste of IntrospectionTool._getZopeConfigurationFile
# This should be kept until versions lower than 5.4.3 still supported.
# NOT USED BY EXTERNAL METHOD
def _getZopeConfigurationFile(relative_path="", mode="r"):
"""
Get a configuration file from the instance using relative path
"""
if ".." in relative_path or relative_path.startswith("/"):
raise Unauthorized("In Relative Path, you cannot use .. or startwith / for security reason.")
instance_home = getConfiguration().instancehome
file_path = os.path.join(instance_home, relative_path)
if not os.path.exists(file_path):
raise IOError, 'The file: %s does not exist.' % file_path
return open(file_path, mode)
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Extension Component" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>default_reference</string> </key>
<value> <string>ERP5UpgraderCompatibility</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>extension.erp5.ERP5UpgraderCompatibility</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Extension Component</string> </value>
</item>
<item>
<key> <string>sid</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>validate</string> </value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>validated</string> </value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
</ZopeData>
...@@ -29,72 +29,6 @@ ...@@ -29,72 +29,6 @@
# #
############################################################################## ##############################################################################
from App.config import getConfiguration
from Products.ERP5Type.Log import log
from Products.CMFActivity.ActiveResult import ActiveResult
import os
def ERP5Site_editERP5SiteProperty(self, prop, value):
"""
The ERP5Site miss this method, so we implement.
"""
portal = self.getPortalObject()
method = portal._setProperty
if portal.hasProperty(prop):
method = portal._updateProperty
method(prop, value)
return True
def ERP5Site_clearActivities(self):
"""
This method is used to recreated the activities keeping the
previous activities from one activity. The issue related to recreate
the Activity tables from one activity is that the activity (this method)
is also recreated, so it is kept for ever.
This method use a flag to define if the portal already recreated the
activities table. If yes, the flag is removed and the recreation will
be ignored.
This method should be run into a single activity to prevent some action
be excetured many times other parts.
"""
instance_home = getConfiguration().instancehome
flag_fs_path = instance_home + "/ACTIVITY_RECREATE_FLAG"
log("Start to Clear activities.")
if not os.path.exists(flag_fs_path):
try:
flag = open(flag_fs_path, 'w+')
log("Clear Activities")
self.getPortalObject().portal_activities.manageClearActivities(keep=1)
active_result = ActiveResult()
active_result.edit(summary="Activities Recreated",
severity=0,
detail="Activities Tables was recreated Sucessfully.")
return active_result
except:
os.remove(flag_fs_path)
raise
os.remove(flag_fs_path)
return
def ERP5Site_runVerificationScript(self, method_id):
""" Run a Python Script return the method. This should avoid raise error,
even one intergrity verification script raise error, and provide good
information.
"""
method = getattr(self.getPortalObject(), method_id, None)
if method is None:
return 'Script %s was not Found!' % (method_id)
try:
integrity_result = method()
except Exception, e:
# Is it required include the trace back
return 'Script %s fail to run, Exception: %s , message: %s .' % (method_id, e.__class__, e )
if len(integrity_result) > 0:
return '%s : \n - %s ' % (method_id, '\n - '.join(integrity_result))
def ERP5Site_dumpWorkflowChainByPortalType(self, REQUEST=None): def ERP5Site_dumpWorkflowChainByPortalType(self, REQUEST=None):
# This method outputs the workflow chain by portal type # This method outputs the workflow chain by portal type
...@@ -109,13 +43,13 @@ def ERP5Site_dumpWorkflowChainByPortalType(self, REQUEST=None): ...@@ -109,13 +43,13 @@ def ERP5Site_dumpWorkflowChainByPortalType(self, REQUEST=None):
ti = workflow_tool._listTypeInfo() ti = workflow_tool._listTypeInfo()
chain_by_type_dict = {} chain_by_type_dict = {}
for t in ti: for t in ti:
id = t.getId() type_information_id = t.getId()
title = t.Title() title = t.Title()
if title == id: if title == type_information_id:
title = None title = None
if cbt is not None and cbt.has_key(id): if cbt is not None and cbt.has_key(type_information_id):
chain = sorted(cbt[id]) chain = sorted(cbt[type_information_id])
else: else:
chain = ['(Default)'] chain = ['(Default)']
chain_by_type_dict.setdefault(id, []).extend(chain) chain_by_type_dict.setdefault(type_information_id, []).extend(chain)
return chain_by_type_dict return chain_by_type_dict
\ No newline at end of file
...@@ -6,10 +6,22 @@ ...@@ -6,10 +6,22 @@
</pickle> </pickle>
<pickle> <pickle>
<dictionary> <dictionary>
<item>
<key> <string>_recorded_property_dict</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item> <item>
<key> <string>default_reference</string> </key> <key> <string>default_reference</string> </key>
<value> <string>ERP5UpgraderUtils</string> </value> <value> <string>ERP5UpgraderUtils</string> </value>
</item> </item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>extension.erp5.ERP5UpgraderUtils</string> </value> <value> <string>extension.erp5.ERP5UpgraderUtils</string> </value>
...@@ -24,6 +36,18 @@ ...@@ -24,6 +36,18 @@
<none/> <none/>
</value> </value>
</item> </item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item> <item>
<key> <string>version</string> </key> <key> <string>version</string> </key>
<value> <string>erp5</string> </value> <value> <string>erp5</string> </value>
...@@ -31,13 +55,28 @@ ...@@ -31,13 +55,28 @@
<item> <item>
<key> <string>workflow_history</string> </key> <key> <string>workflow_history</string> </key>
<value> <value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent> <persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
</record> </record>
<record id="2" aka="AAAAAAAAAAI="> <record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle> <pickle>
<global name="PersistentMapping" module="Persistence.mapping"/> <global name="PersistentMapping" module="Persistence.mapping"/>
</pickle> </pickle>
...@@ -50,7 +89,7 @@ ...@@ -50,7 +89,7 @@
<item> <item>
<key> <string>component_validation_workflow</string> </key> <key> <string>component_validation_workflow</string> </key>
<value> <value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent> <persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value> </value>
</item> </item>
</dictionary> </dictionary>
...@@ -59,26 +98,30 @@ ...@@ -59,26 +98,30 @@
</dictionary> </dictionary>
</pickle> </pickle>
</record> </record>
<record id="3" aka="AAAAAAAAAAM="> <record id="4" aka="AAAAAAAAAAQ=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<list> <key> <string>_log</string> </key>
<dictionary> <value>
<item> <list>
<key> <string>action</string> </key> <dictionary>
<value> <string>validate</string> </value> <item>
</item> <key> <string>action</string> </key>
<item> <value> <string>validate</string> </value>
<key> <string>validation_state</string> </key> </item>
<value> <string>validated</string> </value> <item>
</item> <key> <string>validation_state</string> </key>
</dictionary> <value> <string>validated</string> </value>
</list> </item>
</tuple> </dictionary>
</list>
</value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
</ZopeData> </ZopeData>
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
Run Upgrade step Run Upgrade step
IMPORTANT: Don't use the constraint_type upgrader to data migration or big amount of objects, IMPORTANT: Don't use the constraint_type upgrader to data migration or big amount of objects,
because this step is suppose to run all constraints in the same transaction. because this step is suppose to run all constraints in the same transaction.
""" """
portal = context.getPortalObject() portal = context.getPortalObject()
...@@ -10,7 +10,7 @@ portal = context.getPortalObject() ...@@ -10,7 +10,7 @@ portal = context.getPortalObject()
_, type_per_constraint_type = context.Base_getConstraintTypeListPerPortalType() _, type_per_constraint_type = context.Base_getConstraintTypeListPerPortalType()
portal_type_list = type_per_constraint_type.get('upgrader', []) portal_type_list = type_per_constraint_type.get('upgrader', [])
tool_portal_type = 'Template Tool' tool_portal_type = 'Template Tool'
if tool_portal_type in portal_type_list: if tool_portal_type in portal_type_list:
portal_type_list.remove(tool_portal_type) portal_type_list.remove(tool_portal_type)
...@@ -20,7 +20,7 @@ with context.defaultActivateParameterDict(activate_kw, placeless=True): ...@@ -20,7 +20,7 @@ with context.defaultActivateParameterDict(activate_kw, placeless=True):
active_process = context.newActiveProcess(activate_kw=activate_kw) active_process = context.newActiveProcess(activate_kw=activate_kw)
method_kw = {'fixit': fixit, method_kw = {'fixit': fixit,
'filter': {"constraint_type": 'upgrader'}, 'filter_dict': {"constraint_type": 'upgrader'},
'active_process': active_process.getRelativeUrl(), 'active_process': active_process.getRelativeUrl(),
'activate_kw': activate_kw, 'activate_kw': activate_kw,
} }
......
...@@ -6,7 +6,7 @@ if active_process.ActiveProcess_sense() and not fixit: ...@@ -6,7 +6,7 @@ if active_process.ActiveProcess_sense() and not fixit:
with context.defaultActivateParameterDict(activate_kw, placeless=True): with context.defaultActivateParameterDict(activate_kw, placeless=True):
constraint_message_list = context.checkConsistency( constraint_message_list = context.checkConsistency(
fixit=fixit, filter=filter,) fixit=fixit, filter=filter_dict,)
if constraint_message_list and not active_process.getResultList(): if constraint_message_list and not active_process.getResultList():
active_process.postActiveResult( active_process.postActiveResult(
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>fixit, filter, active_process, activate_kw</string> </value> <value> <string>fixit, filter_dict, active_process, activate_kw</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
...@@ -3,6 +3,13 @@ constraint_type = filter_dict.get("constraint_type") ...@@ -3,6 +3,13 @@ constraint_type = filter_dict.get("constraint_type")
if not constraint_type: if not constraint_type:
return return
if activate_kw is None:
activate_kw = {}
if filter_dict is None:
filter_dict = {}
portal_type_list = [] portal_type_list = []
append = portal_type_list.append append = portal_type_list.append
for portal_type, constraint_type_list in constraint_type_per_type.iteritems(): for portal_type, constraint_type_list in constraint_type_per_type.iteritems():
...@@ -16,7 +23,7 @@ if portal_type_list: ...@@ -16,7 +23,7 @@ if portal_type_list:
portal_type=portal_type_list, portal_type=portal_type_list,
method_kw={ method_kw={
'fixit': fixit, 'fixit': fixit,
'filter': filter_dict, 'filter_dict': filter_dict,
'active_process': active_process.getRelativeUrl(), 'active_process': active_process.getRelativeUrl(),
'activate_kw': activate_kw, 'activate_kw': activate_kw,
}, },
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>active_process, activate_kw={}, fixit=False, filter_dict={}</string> </value> <value> <string>active_process, activate_kw=None, fixit=False, filter_dict=None</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
# Because this script is called during the post-upgrade phase, we are # Because this script is called during the post-upgrade phase, we are
# looking for the category by its new name. # looking for the category by its new name.
if activate_kw is None:
activate_kw = {}
portal = context.getPortalObject() portal = context.getPortalObject()
error_list = [] error_list = []
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>fixit=False, activate_kw={}, **kw</string> </value> <value> <string>fixit=False, activate_kw=None, **kw</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
...@@ -828,7 +828,6 @@ class TestUpgrader(ERP5TypeTestCase): ...@@ -828,7 +828,6 @@ class TestUpgrader(ERP5TypeTestCase):
self.assertEqual(title, 'M. post_upgrade') self.assertEqual(title, 'M. post_upgrade')
def stepCheckPersonTitleHistory(self, sequence=None): def stepCheckPersonTitleHistory(self, sequence=None):
person = sequence['person']
self.assertEqual( self.assertEqual(
[x.changes for x in self.portal.person_module['1'].Base_getZODBHistoryList()[-3:]], [x.changes for x in self.portal.person_module['1'].Base_getZODBHistoryList()[-3:]],
[('title:M. pre_upgrade',), ('title:M. upgrader',), ('title:M. post_upgrade',)]) [('title:M. pre_upgrade',), ('title:M. upgrader',), ('title:M. post_upgrade',)])
......
...@@ -45,20 +45,7 @@ ...@@ -45,20 +45,7 @@
<item> <item>
<key> <string>text_content_warning_message</string> </key> <key> <string>text_content_warning_message</string> </key>
<value> <value>
<tuple> <tuple/>
<string>R: 33, 0: Too many ancestors (9/7) (too-many-ancestors)</string>
<string>W: 59,64: Unused argument \'sequence\' (unused-argument)</string>
<string>W: 76,42: Unused argument \'sequence\' (unused-argument)</string>
<string>W: 89,48: Unused argument \'sequence\' (unused-argument)</string>
<string>W:104,53: Unused argument \'sequence\' (unused-argument)</string>
<string>W:109,51: Unused argument \'sequence\' (unused-argument)</string>
<string>W:112,52: Unused argument \'sequence\' (unused-argument)</string>
<string>W:115,56: Unused argument \'sequence\' (unused-argument)</string>
<string>W:122,54: Unused argument \'sequence\' (unused-argument)</string>
<string>W:140,54: Unused argument \'sequence\' (unused-argument)</string>
<string>W:147,54: Unused argument \'sequence\' (unused-argument)</string>
<string>R: 33, 0: Too many public methods (136/20) (too-many-public-methods)</string>
</tuple>
</value> </value>
</item> </item>
<item> <item>
......
extension.erp5.ERP5UpgraderUtils extension.erp5.ERP5UpgraderUtils
extension.erp5.ERP5UpgraderCompatibility \ No newline at end of file
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment