robustify PropertySheet lookup logic: use actual Product paths

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@31813 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent c8d98138
...@@ -32,7 +32,7 @@ from AccessControl import ClassSecurityInfo ...@@ -32,7 +32,7 @@ from AccessControl import ClassSecurityInfo
from Products.ERP5Type.Globals import InitializeClass from Products.ERP5Type.Globals import InitializeClass
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
from App.config import getConfiguration from App.config import getConfiguration
import os import os, os.path
import random import random
from Products.ERP5Type.Base import Base from Products.ERP5Type.Base import Base
from Products.ERP5Type.Utils import convertToUpperCase from Products.ERP5Type.Utils import convertToUpperCase
...@@ -156,16 +156,17 @@ class DocumentationHelper(Implicit): ...@@ -156,16 +156,17 @@ class DocumentationHelper(Implicit):
instance_home = getConfiguration().instancehome instance_home = getConfiguration().instancehome
file_name = self.uri.split('/')[-1] file_name = self.uri.split('/')[-1]
file_url = '' file_url = ''
list_path = os.listdir(instance_home+'/Products') import Products
zope_property_sheet = instance_home + '/PropertySheet' ModType = type(Products)
list_propertysheets = [zope_property_sheet,] product_paths = [os.path.dirname(getattr(Products, modname).__file__)
for path in list_path: for modname in dir(Products)
full_path = instance_home+'/Products/'+path if type(getattr(Products, modname, None)) is ModType]
if os.path.isdir(full_path) and os.path.exists(full_path+'/PropertySheet'): for path in [instance_home,] + product_paths:
list_propertysheets.append(full_path+'/PropertySheet') file_url = os.path.join(path, 'PropertySheet', file_name)
for propertysheet_directory in list_propertysheets: if os.path.isfile(file_url):
if os.path.exists(propertysheet_directory+'/'+file_name): break
file_url = propertysheet_directory+'/'+file_name else:
raise LookupError('could not find PropertySheet for %r' % (self.uri,))
documented_object = open(file_url) documented_object = open(file_url)
elif '/' in self.uri and '#' not in self.uri: elif '/' in self.uri and '#' not in self.uri:
# URI refers to a portal object # URI refers to a portal object
...@@ -176,9 +177,9 @@ class DocumentationHelper(Implicit): ...@@ -176,9 +177,9 @@ class DocumentationHelper(Implicit):
elif '/' in self.uri and '#' in self.uri: elif '/' in self.uri and '#' in self.uri:
if '?' in self.uri: if '?' in self.uri:
base_url, url = self.uri.split('?') base_url, url = self.uri.split('?')
type, name = url.split('#') type_, name = url.split('#')
parent_object = self.getPortalObject().unrestrictedTraverse(base_url, None) parent_object = self.getPortalObject().unrestrictedTraverse(base_url, None)
object_list = getattr(parent_object, type, None) object_list = getattr(parent_object, type_, None)
documented_object = None documented_object = None
if object_list is not None: if object_list is not None:
for obj in object_list: for obj in object_list:
...@@ -211,7 +212,7 @@ class DocumentationHelper(Implicit): ...@@ -211,7 +212,7 @@ class DocumentationHelper(Implicit):
for key in module_list[1:]: for key in module_list[1:]:
documented_object = getattr(documented_object, key, None) documented_object = getattr(documented_object, key, None)
else: else:
raise NotImplemented raise NotImplementedError
#fp, pathname, description = imp.find_module(base_module) #fp, pathname, description = imp.find_module(base_module)
#documented_object = imp.load_module(fp, pathname, description) #documented_object = imp.load_module(fp, pathname, description)
return documented_object return documented_object
......
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