allow manual installation and uninstallation of business templates

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@32340 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 9a8ecd58
...@@ -364,6 +364,73 @@ class ERP5TypeTestCase(backportUnittest.TestCase, PortalTestCase): ...@@ -364,6 +364,73 @@ class ERP5TypeTestCase(backportUnittest.TestCase, PortalTestCase):
self.run(*args, **kw) self.run(*args, **kw)
def _getBTPathAndIdList(self, template_list):
INSTANCE_HOME = os.environ['INSTANCE_HOME']
bt5_path = os.environ.get('erp5_tests_bt5_path',
os.path.join(INSTANCE_HOME, 'bt5'))
erp5_product_path = os.path.dirname(Products.ERP5.__file__)
bootstrap_path = os.environ.get('erp5_tests_bootstrap_path',
os.path.join(erp5_product_path,
'bootstrap'))
new_template_list = []
for template in template_list:
id = template.split('/')[-1]
try :
file, headers = urlretrieve(template)
except IOError :
# First, try the bt5 directory itself.
path = os.path.join(bt5_path, template)
alternate_path = os.path.join(bootstrap_path, template)
if os.path.exists(path):
template = path
elif os.path.exists(alternate_path):
template = alternate_path
else:
path = '%s.bt5' % path
if os.path.exists(path):
template = path
else:
# Otherwise, look at sub-directories.
# This is for backward-compatibility.
path = os.path.join(INSTANCE_HOME, 'bt5', '*', template)
template_list = glob(path)
if len(template_list) == 0:
template_list = glob('%s.bt5' % path)
if len(template_list) and template_list[0]:
template = template_list[0]
else:
# The last resort is current directory.
template = '%s' % id
if not os.path.exists(template):
template = '%s.bt5' % id
else:
template = '%s' % template
if not os.path.exists(template):
template = '%s.bt5' % template
new_template_list.append((template,id))
return new_template_list
def manuallyInstallBusinessTemplate(self, *template_list):
new_template_list = self._getBTPathAndIdList(template_list)
light_install = self.enableLightInstall()
self._installBusinessTemplateList(new_template_list,
light_install=light_install)
self.tic()
def uninstallBusinessTemplate(self, *template_list):
template_list = set(template_list)
uninstalled_list = []
portal = self.portal
for bt in portal.portal_templates.getInstalledBusinessTemplateList():
if bt.getTitle() in template_list:
bt.uninstall(remove_translations=True)
uninstalled_list.append(bt.getTitle())
getattr(portal, 'ERP5Site_updateTranslationTable', lambda: None)()
self.stepTic()
return uninstalled_list
def setUp(self): def setUp(self):
'''Sets up the fixture. Do not override, '''Sets up the fixture. Do not override,
use the hooks instead. use the hooks instead.
...@@ -384,11 +451,6 @@ class ERP5TypeTestCase(backportUnittest.TestCase, PortalTestCase): ...@@ -384,11 +451,6 @@ class ERP5TypeTestCase(backportUnittest.TestCase, PortalTestCase):
cfg = App.config.getConfiguration() cfg = App.config.getConfiguration()
cfg.instancehome = os.environ['COPY_OF_INSTANCE_HOME'] cfg.instancehome = os.environ['COPY_OF_INSTANCE_HOME']
App.config.setConfiguration(cfg) App.config.setConfiguration(cfg)
INSTANCE_HOME = os.environ['INSTANCE_HOME']
bt5_path = os.environ.get('erp5_tests_bt5_path',
os.path.join(INSTANCE_HOME, 'bt5'))
bootstrap_path = os.environ.get('erp5_tests_bootstrap_path',
os.path.join(INSTANCE_HOME, 'Products/ERP5/bootstrap'))
template_list = self.getBusinessTemplateList() template_list = self.getBusinessTemplateList()
erp5_catalog_storage = os.environ.get('erp5_catalog_storage', erp5_catalog_storage = os.environ.get('erp5_catalog_storage',
...@@ -410,42 +472,7 @@ class ERP5TypeTestCase(backportUnittest.TestCase, PortalTestCase): ...@@ -410,42 +472,7 @@ class ERP5TypeTestCase(backportUnittest.TestCase, PortalTestCase):
if re.search(expression, business_template): if re.search(expression, business_template):
matching_template_list.append(business_template) matching_template_list.append(business_template)
template_list = matching_template_list template_list = matching_template_list
new_template_list = [] new_template_list = self._getBTPathAndIdList(template_list)
for template in template_list:
id = template.split('/')[-1]
try :
file, headers = urlretrieve(template)
except IOError :
# First, try the bt5 directory itself.
path = os.path.join(bt5_path, template)
alternate_path = os.path.join(bootstrap_path, template)
if os.path.exists(path):
template = path
elif os.path.exists(alternate_path):
template = alternate_path
else:
path = '%s.bt5' % path
if os.path.exists(path):
template = path
else:
# Otherwise, look at sub-directories.
# This is for backward-compatibility.
path = os.path.join(INSTANCE_HOME, 'bt5', '*', template)
template_list = glob(path)
if len(template_list) == 0:
template_list = glob('%s.bt5' % path)
if len(template_list) and template_list[0]:
template = template_list[0]
else:
# The last resort is current directory.
template = '%s' % id
if not os.path.exists(template):
template = '%s.bt5' % id
else:
template = '%s' % template
if not os.path.exists(template):
template = '%s.bt5' % template
new_template_list.append((template,id))
# keep a mapping type info name -> property sheet list, to remove them in # keep a mapping type info name -> property sheet list, to remove them in
# tear down. # tear down.
...@@ -780,6 +807,55 @@ class ERP5TypeTestCase(backportUnittest.TestCase, PortalTestCase): ...@@ -780,6 +807,55 @@ class ERP5TypeTestCase(backportUnittest.TestCase, PortalTestCase):
" (tried ports %s)\n" % ', '.join(port_list)) " (tried ports %s)\n" % ', '.join(port_list))
return utils._Z2HOST, utils._Z2PORT return utils._Z2HOST, utils._Z2PORT
def _installBusinessTemplateList(self, business_template_list,
light_install=True,
quiet=True):
portal = self.portal
update_business_templates = os.environ.get('update_business_templates') is not None
BusinessTemplate_getModifiedObject = aq_base(getattr(portal, 'BusinessTemplate_getModifiedObject', None))
# check that all bt5 exist, saving time in case of missing bt
missing_bt_list = []
for url, bt_title in business_template_list:
# if the bt is not found, an error is raised
if not portal.portal_templates.assertBtPathExists(url):
missing_bt_list.append(bt_title)
if len(missing_bt_list):
raise RuntimeError("Some BT can't be found on your system : %s"
% ', '.join(missing_bt_list))
# Add some business templates
for url, bt_title in business_template_list:
start = time.time()
get_install_kw = False
if bt_title in [x.getTitle() for x in portal.portal_templates.getInstalledBusinessTemplateList()]:
if update_business_templates:
if not quiet:
ZopeTestCase._print('Updating %s business template ... ' % bt_title)
if BusinessTemplate_getModifiedObject is not None:
get_install_kw = True
else:
continue
else:
if not quiet:
ZopeTestCase._print('Adding %s business template ... ' % bt_title)
bt = portal.portal_templates.download(url)
if not quiet:
ZopeTestCase._print('(imported in %.3fs) ' % (time.time() - start))
install_kw = None
if get_install_kw:
install_kw = {}
listbox_object_list = BusinessTemplate_getModifiedObject.__of__(bt)()
for listbox_line in listbox_object_list:
install_kw[listbox_line.object_id] = listbox_line.choice_item_list[0][1]
bt.install(light_install=light_install,
object_to_update=install_kw,
update_translation=1)
# Release locks
transaction.commit()
if not quiet:
ZopeTestCase._print('done (%.3fs)\n' % (time.time() - start))
def setUpERP5Site(self, def setUpERP5Site(self,
business_template_list=(), business_template_list=(),
app=None, app=None,
...@@ -869,53 +945,9 @@ class ERP5TypeTestCase(backportUnittest.TestCase, PortalTestCase): ...@@ -869,53 +945,9 @@ class ERP5TypeTestCase(backportUnittest.TestCase, PortalTestCase):
self._updateConnectionStrings() self._updateConnectionStrings()
self._recreateCatalog() self._recreateCatalog()
self._installBusinessTemplateList(business_template_list,
update_business_templates = os.environ.get('update_business_templates') is not None light_install=light_install,
BusinessTemplate_getModifiedObject = aq_base(getattr(portal, 'BusinessTemplate_getModifiedObject', None)) quiet=quiet)
# check that all bt5 exist, this permit to save time in case of
# missing bt
missing_bt_list = []
for url, bt_title in business_template_list:
# if the bt is not found, an error is raised
if not portal.portal_templates.assertBtPathExists(url):
missing_bt_list.append(bt_title)
if len(missing_bt_list):
raise RuntimeError("Some BT can't be found on your system : %s"
% ', '.join(missing_bt_list))
# Add some business templates
for url, bt_title in business_template_list:
start = time.time()
get_install_kw = False
if bt_title in [x.getTitle() for x in portal.portal_templates.getInstalledBusinessTemplateList()]:
if update_business_templates:
if not quiet:
ZopeTestCase._print('Updating %s business template ... ' % bt_title)
if BusinessTemplate_getModifiedObject is not None:
get_install_kw = True
else:
continue
else:
if not quiet:
ZopeTestCase._print('Adding %s business template ... ' % bt_title)
bt = portal.portal_templates.download(url)
if not quiet:
ZopeTestCase._print('(imported in %.3fs) ' % (time.time() - start))
install_kw = None
if get_install_kw:
install_kw = {}
listbox_object_list = BusinessTemplate_getModifiedObject.__of__(bt)()
for listbox_line in listbox_object_list:
install_kw[listbox_line.object_id] = listbox_line.choice_item_list[0][1]
bt.install(light_install=light_install,
object_to_update=install_kw,
update_translation=1)
# Release locks
transaction.commit()
if not quiet:
ZopeTestCase._print('done (%.3fs)\n' % (time.time() - start))
# Create a Manager user at the Portal level # Create a Manager user at the Portal level
uf = self.getPortal().acl_users uf = self.getPortal().acl_users
uf._doAddUser('ERP5TypeTestCase', '', ['Manager', 'Member', 'Assignee', uf._doAddUser('ERP5TypeTestCase', '', ['Manager', 'Member', 'Assignee',
......
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