From a6e65ddc329d136cf24e2eb1603621c749035c2c Mon Sep 17 00:00:00 2001 From: Yoshinori Okuji <yo@nexedi.com> Date: Fri, 23 Jun 2006 11:33:18 +0000 Subject: [PATCH] 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 --- product/ERP5Type/tests/ERP5TypeTestCase.py | 32 +++++++++++++++------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/product/ERP5Type/tests/ERP5TypeTestCase.py b/product/ERP5Type/tests/ERP5TypeTestCase.py index 3dbc9ac38d..3f02e730e9 100644 --- a/product/ERP5Type/tests/ERP5TypeTestCase.py +++ b/product/ERP5Type/tests/ERP5TypeTestCase.py @@ -120,6 +120,8 @@ import traceback import sys import os from cStringIO import StringIO +from urllib import urlretrieve +from glob import glob from Products.ERP5.ERP5Site import ERP5Site @@ -207,19 +209,29 @@ class ERP5TypeTestCase(PortalTestCase): for template in template_list: id = template try : - from urllib import urlretrieve file, headers = urlretrieve(template) except IOError : - from glob import glob - template_list = glob(os.path.join(INSTANCE_HOME, 'bt5', '*', '%s' % template)) - if len(template_list) == 0: - template_list = glob(os.path.join(INSTANCE_HOME, 'bt5', '*', '%s.bt5' % template)) - if not (len(template_list) and template_list[0]): - template = '%s' % id - if not os.path.exists(template): - template = '%s.bt5' % id + # First, try the bt5 directory itself. + path = os.path.join(INSTANCE_HOME, 'bt5', template) + if os.path.exists(path): + template = path else: - template = template_list[0] + 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): -- 2.30.9