Commit a6e65ddc authored by Yoshinori Okuji's avatar Yoshinori Okuji

Import glob and urllib in the top scope.

Search Business Templates directly under bt5, first.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@8152 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 3da0cdfd
...@@ -120,6 +120,8 @@ import traceback ...@@ -120,6 +120,8 @@ import traceback
import sys import sys
import os import os
from cStringIO import StringIO from cStringIO import StringIO
from urllib import urlretrieve
from glob import glob
from Products.ERP5.ERP5Site import ERP5Site from Products.ERP5.ERP5Site import ERP5Site
...@@ -207,19 +209,29 @@ class ERP5TypeTestCase(PortalTestCase): ...@@ -207,19 +209,29 @@ class ERP5TypeTestCase(PortalTestCase):
for template in template_list: for template in template_list:
id = template id = template
try : try :
from urllib import urlretrieve
file, headers = urlretrieve(template) file, headers = urlretrieve(template)
except IOError : except IOError :
from glob import glob # First, try the bt5 directory itself.
template_list = glob(os.path.join(INSTANCE_HOME, 'bt5', '*', '%s' % template)) path = os.path.join(INSTANCE_HOME, 'bt5', template)
if os.path.exists(path):
template = 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: if len(template_list) == 0:
template_list = glob(os.path.join(INSTANCE_HOME, 'bt5', '*', '%s.bt5' % template)) template_list = glob('%s.bt5' % path)
if not (len(template_list) and template_list[0]): if len(template_list) and template_list[0]:
template = template_list[0]
else:
# The last resort is current directory.
template = '%s' % id template = '%s' % id
if not os.path.exists(template): if not os.path.exists(template):
template = '%s.bt5' % id template = '%s.bt5' % id
else:
template = template_list[0]
else: else:
template = '%s' % template template = '%s' % template
if not os.path.exists(template): if not os.path.exists(template):
......
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