Commit 5697a60d authored by Rafael Monnerat's avatar Rafael Monnerat

This utility method verify which repository (from a list) the business...

This utility method verify which repository (from a list) the business template is available, returning the appropriate url.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@35693 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 568acf12
......@@ -44,6 +44,7 @@ from tempfile import mkstemp, mkdtemp
from Products.ERP5 import _dtmldir
from cStringIO import StringIO
from urllib import pathname2url, urlopen, splittype, urlretrieve
import urllib2
import re
from xml.dom.minidom import parse
from xml.parsers.expat import ExpatError
......@@ -1051,4 +1052,36 @@ class TemplateTool (BaseTool):
opreation_log.append('Not found in repositories %s' % template_name)
return opreation_log
security.declareProtected(Permissions.ManagePortal,
'getBusinessTemplateUrl')
def getBusinessTemplateUrl(self, base_url_list, bt5_title):
"""
This method verify if the business template are available
into one url (repository).
"""
# This list could be preconfigured at some properties or
# at preferences.
for base_url in base_url_list:
url = "%s/%s" % (base_url, bt5_title)
if base_url == "INSTANCE_HOME_REPOSITORY":
url = "file://%s/bt5/%s" % (getConfiguration().instancehome,
bt5_title)
LOG('ERP5', INFO, "TemplateTool: INSTANCE_HOME_REPOSITORY is %s." \
% url)
try:
urllib2.urlopen(url)
return url
except (urllib2.HTTPError, OSError):
# XXX Try again with ".bt5" in case the folder format be used
# Instead tgz one.
url = "%s.bt5" % url
try:
urllib2.urlopen(url)
return url
except (urllib2.HTTPError, OSError):
pass
LOG('ERP5', INFO, 'TemplateTool: %s was not found into the url list: '
'%s.' % (bt5_title, base_url_list))
return None
InitializeClass(TemplateTool)
......@@ -6385,6 +6385,40 @@ class TestBusinessTemplate(ERP5TypeTestCase, LogInterceptor):
self.assertFalse(getattr(portal.some_file, 'isClassOverriden', False))
self.assertFalse(getattr(portal.another_file, 'isClassOverriden', False))
def test_getBusinessTemplateUrl(self):
""" Test if this method can find which repository is the business
template
"""
# How to define an existing and use INSTANCE_HOME_REPOSITORY?
url_list = [ 'https://svn.erp5.org/repos/public/erp5/trunk/bt5',
'http://www.erp5.org/dists/snapshot/bt5',
'http://www.erp5.org/dists/release/5.4.5/bt5',
'file:///opt/does/not/exist',
"INSTANCE_HOME_REPOSITORY"]
exist_bt5 = 'erp5_base'
not_exist_bt5 = "erp5_not_exist"
template_tool = self.portal.portal_templates
getBusinessTemplateUrl = template_tool.getBusinessTemplateUrl
# Test Exists
self.assertEquals(getBusinessTemplateUrl(url_list, exist_bt5),
'https://svn.erp5.org/repos/public/erp5/trunk/bt5/erp5_base')
self.assertEquals(getBusinessTemplateUrl(url_list[1:], exist_bt5),
'http://www.erp5.org/dists/snapshot/bt5/erp5_base.bt5')
self.assertEquals(getBusinessTemplateUrl(url_list[2:], exist_bt5),
'http://www.erp5.org/dists/release/5.4.5/bt5/erp5_base.bt5')
self.assertEquals(getBusinessTemplateUrl(url_list[3:], exist_bt5), None)
# XXX Remains test for INSTANCE_HOME_REPOSITORY and file:/// where erp5_base
# exists.
# Test Not exists
self.assertEquals(getBusinessTemplateUrl(url_list, not_exist_bt5), None)
self.assertEquals(getBusinessTemplateUrl(url_list[1:], not_exist_bt5), None)
self.assertEquals(getBusinessTemplateUrl(url_list[2:], not_exist_bt5), None)
self.assertEquals(getBusinessTemplateUrl(url_list[3:], not_exist_bt5), None)
self.assertEquals(getBusinessTemplateUrl(url_list[4:], not_exist_bt5), None)
def test_type_provider(self):
self.portal._setObject('dummy_type_provider', DummyTypeProvider())
type_provider = self.portal.dummy_type_provider
......
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