Commit 79943fc0 authored by Arnaud Fontaine's avatar Arnaud Fontaine

WIP: Allow migration of {Interface,Mixin,Module,Tool} from Business Template...

WIP: Allow migration of {Interface,Mixin,Module,Tool} from Business Template UI and on all Products (not only Products.ERP5).
parent 60c4d915
......@@ -6437,30 +6437,128 @@ Business Template is a set of definitions, such as skins, portal types and categ
self.getTemplatePortalTypeIdList()))
# XXX: Only migrate Documents in ERP5 for the moment...
import Products.ERP5.Document
for name, obj in Products.ERP5.Document.__dict__.iteritems():
if not name.startswith('_') and inspect.ismodule(obj):
source_reference = obj.__name__
import os
repository_path_list = [
os.path.realpath(p)
for p in portal.portal_preferences.getPreferredWorkingCopyList() ]
def __is_product_within_working_copy_list(module):
module_path_list = module.__path__
for repository_path in repository_path_list:
for module_path in module_path_list:
if module_path.startswith(repository_path):
return True
return False
import Products
from glob import iglob
portal_type_pathname_pattern_dict = {
'Document Component': 'Document/*.py',
}
# 'Interface Component': 'interfaces/*.py',
# 'Mixin Component': 'mixin/*.py',
# 'Module Component': '*.py',
# 'Test Component': 'tests/test*.py',
# 'Tool Component': 'Tool/*Tool.py'
# }
submodule_name_info_dict = {
'Document': {'portal_type': 'Document Component'},
'interfaces': {'portal_type': 'Interface Component'},
'mixin': {'portal_type': 'Mixin Component'},
'Tool': {'portal_type': 'Tool Component',
'filename_func': lambda filename: (filename.endswith('Tool.py') or
filename.endswith('Tool.pyc'))}
}
migrate = ((name, source_reference, inspect.getfile(obj))
if not current_bt_only:
submodule_name_info_dict['tests'] = {
'portal_type': 'Test component',
'filename_func': lambda filename: filename.startswith('test')}
for product_name, product_obj in inspect.getmembers(Products,
inspect.ismodule):
if (product_name[0] == '_' or
product_name == 'this_module' or
# Bootstrap
product_name == 'ERP5Type' or
not __is_product_within_working_copy_list(product_obj)):
continue
product_base_path = inspect.getfile(product_obj).rsplit('/', 1)[0]
LOG("PRODUCT", INFO, "========= %r: %r ==============" % (product_name, product_obj))
for submodule_name, submodule_obj in inspect.getmembers(product_obj,
inspect.ismodule):
if submodule_name == 'this_module' or submodule_name[0] == '_':
continue
try:
submodule_file = inspect.getfile(submodule_obj)
except TypeError:
# No file, builtin?
continue
info_dict = submodule_name_info_dict.get(submodule_name)
if info_dict is not None:
component_portal_type = info_dict['portal_type']
filename_func = info_dict.get('filename_func')
for subsubmodule_name, subsubmodule_obj in inspect.getmembers(
submodule_obj,
inspect.ismodule):
if subsubmodule_name == 'this_module' or subsubmodule_name[0] == '_':
continue
try:
filepath = inspect.getfile(subsubmodule_obj)
except TypeError:
# No file, builtin?
continue
filename = filepath.rsplit('/', 1)[-1]
if filename_func is not None and not filename_func(filename):
LOG(component_portal_type, WARNING,
"filename_func(%r)=%r: %r: %r: %r" %
(filename, filename_func(filename),
subsubmodule_obj, subsubmodule_name, filepath))
continue
source_reference = subsubmodule_obj.__name__
migrate = ((subsubmodule_name, source_reference, filepath)
in portal_type_module_set)
if current_bt_only and not migrate:
LOG(component_portal_type, WARNING,
"current_bt_only=%r and not migrate=%r: %r: %r: %r" %
(current_bt_only, migrate,
subsubmodule_obj, subsubmodule_name, filepath))
continue
obj = __newTempComponent(portal_type='Document Component',
reference=name,
LOG(component_portal_type, INFO,
"%r: %r: %r" % (subsubmodule_obj, subsubmodule_name, filepath))
obj = __newTempComponent(portal_type=component_portal_type,
reference=subsubmodule_name,
source_reference=source_reference,
migrate=migrate)
if not current_bt_only:
import Products.ERP5.tests
from glob import iglob
for test_path in iglob("%s/test*.py" %
inspect.getfile(Products.ERP5.tests).rsplit('/', 1)[0]):
reference = test_path.rsplit('/', 1)[1][:-3]
obj = __newTempComponent(portal_type='Test Component',
reference=reference,
source_reference="Products.ERP5.tests." + reference)
# This is a module, but only handle top-level Product modules
elif (submodule_name not in ('Permissions',) and
submodule_file.rsplit('/', 1)[0] == product_base_path):
source_reference = submodule_obj.__name__
migrate = ((submodule_name, source_reference, submodule_file)
in portal_type_module_set)
if current_bt_only and not migrate:
continue
LOG('ModuleComponent', INFO,
"%r: %r: %r" % (submodule_obj, submodule_name, submodule_file))
obj = __newTempComponent(portal_type='Module Component',
reference=submodule_name,
source_reference=source_reference,
migrate=migrate)
else:
LOG('IGNORED', WARNING,
"%r: %r: %r" % (submodule_obj, submodule_name, submodule_file))
# Automatically select ZODB Components to be migrated in Migration Dialog
selection_name = kwargs.get('selection_name')
......
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