Commit d1a0f4aa authored by Jean-Paul Smets's avatar Jean-Paul Smets

updated for aq_dynamic code generation


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@1317 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d3e6ed38
......@@ -30,16 +30,11 @@
and extended local roles management
"""
# First import the minimal number of packages required by the code generation
from Products.ERP5Type.InitGenerator import generateInitFiles
import sys
# Update the self generated code for Document, PropertySheet and Interface
this_module = sys.modules[ __name__ ]
document_classes = generateInitFiles(this_module, globals())
# Update ERP5 Globals
from Products.ERP5Type.Utils import initializeProduct, updateGlobals
import sys, Permissions
this_module = sys.modules[ __name__ ]
document_classes = updateGlobals( this_module, globals(), permissions_module = Permissions)
# Finish installation
def initialize( context ):
......
from CategoryCore import CategoryCore
from BaseCategory import BaseCategory
\ No newline at end of file
......@@ -30,22 +30,11 @@
in the CMF. It is based on the ERP5Type RAD
"""
# First import the minimal number of packages required by the code generation
from Products.ERP5Type.InitGenerator import generateInitFiles
import sys
# Update the self generated code for Document, PropertySheet and Interface
this_module = sys.modules[ __name__ ]
document_classes = generateInitFiles(this_module, globals())
# Update ERP5 Globals
from Products.ERP5Type.Utils import initializeProduct, updateGlobals
import Interface, PropertySheet, Permissions, Constraint
updateGlobals( this_module, globals(),
property_sheet_module = PropertySheet,
interface_module = Interface,
permissions_module = Permissions,
constraint_module = Constraint)
import sys, Permissions
this_module = sys.modules[ __name__ ]
document_classes = updateGlobals( this_module, globals(), permissions_module = Permissions)
# Define object classes and tools
import Category, CategoryTool
......
......@@ -29,22 +29,11 @@
ERP5 Free Software ERP
"""
# First import the minimal number of packages required by the code generation
from Products.ERP5Type.InitGenerator import generateInitFiles
import sys
# Update the self generated code for Document, PropertySheet and Interface
this_module = sys.modules[ __name__ ]
document_classes = generateInitFiles(this_module, globals())
# Update ERP5 Globals
from Products.ERP5Type.Utils import initializeProduct, updateGlobals
import Interface, PropertySheet, Permissions, Constraint
updateGlobals( this_module, globals(),
property_sheet_module = PropertySheet,
interface_module = Interface,
permissions_module = Permissions,
constraint_module = Constraint)
import sys, Permissions
this_module = sys.modules[ __name__ ]
document_classes = updateGlobals( this_module, globals(), permissions_module = Permissions)
# Define object classes and tools
object_classes = ()
......
from Coordinate import Coordinate
from Entity import Entity
from Predicate import Predicate
from Variated import Variated
\ No newline at end of file
......@@ -29,25 +29,14 @@
ERP5 Free Software ERP
"""
# First import the minimal number of packages required by the code generation
from Products.ERP5Type.InitGenerator import generateInitFiles
import sys
# Update the self generated code for Document, PropertySheet and Interface
this_module = sys.modules[ __name__ ]
document_classes = generateInitFiles(this_module, globals())
# Update ERP5 Globals
from Products.ERP5Type.Utils import initializeProduct, updateGlobals
import Interface, PropertySheet, Permissions, Constraint
updateGlobals( this_module, globals(),
property_sheet_module = PropertySheet,
interface_module = Interface,
permissions_module = Permissions,
constraint_module = Constraint)
import sys, Permissions
this_module = sys.modules[ __name__ ]
document_classes = updateGlobals( this_module, globals(), permissions_module = Permissions)
# Define object classes and tools
from Tool import Category, CategoryTool, SimulationTool, RuleTool, IdTool, TemplateTool, TestTool
from Tool import Category, CategoryTool, SimulationTool, RuleTool, IdTool, TemplateTool, TestTool, DomainTool
import ERP5Site
object_classes = ( Category.Category,
Category.BaseCategory,
......@@ -58,6 +47,7 @@ portal_tools = ( CategoryTool.CategoryTool,
RuleTool.RuleTool,
IdTool.IdTool,
TemplateTool.TemplateTool,
DomainTool.DomainTool,
TestTool.TestTool
)
content_classes = ()
......@@ -69,6 +59,8 @@ from InteractionWorkflow import InteractionWorkflowDefinition
# Finish installation
def initialize( context ):
import Document
from zLOG import LOG
LOG('In ERP5 initialize', 0, '')
initializeProduct(context, this_module, globals(),
document_module = Document,
document_classes = document_classes,
......
......@@ -30,16 +30,11 @@
and extended local roles management
"""
# First import the minimal number of packages required by the code generation
from Products.ERP5Type.InitGenerator import generateInitFiles
import sys
# Update the self generated code for Document, PropertySheet and Interface
this_module = sys.modules[ __name__ ]
document_classes = generateInitFiles(this_module, globals())
# Update ERP5 Globals
from Products.ERP5Type.Utils import initializeProduct, updateGlobals
import sys, Permissions
this_module = sys.modules[ __name__ ]
document_classes = updateGlobals( this_module, globals(), permissions_module = Permissions)
# Define object classes and tools
import CatalogTool
......
......@@ -3,6 +3,7 @@ import Products.ERP5
import Products.ERP5.XML
import Products.ERP5.UI
import Products.ERP5.Document
import Products.ERP5.Document.SaleOpportunity
import Products.ERP5Catalog
import Products.ERP5Form
import Products.ERP5SyncML
......
......@@ -30,19 +30,11 @@
with Zope
"""
# First import the minimal number of packages required by the code generation
from Products.ERP5Type.InitGenerator import generateInitFiles
import sys
# Update the self generated code for Document, PropertySheet and Interface
this_module = sys.modules[ __name__ ]
document_classes = generateInitFiles(this_module, globals())
# Update ERP5 Globals
from Products.ERP5Type.Utils import initializeProduct, updateGlobals
import Permissions
updateGlobals( this_module, globals(),
permissions_module = Permissions)
import sys, Permissions
this_module = sys.modules[ __name__ ]
document_classes = updateGlobals( this_module, globals(), permissions_module = Permissions)
# Define object classes and tools
import Form, FSForm, ListBox, MatrixBox, SelectionTool, ZGDChart, PDFTemplate
......
......@@ -29,22 +29,11 @@
ERP5Shop Free ERP + eCommerce
"""
# First import the minimal number of packages required by the code generation
from Products.ERP5Type.InitGenerator import generateInitFiles
import sys
# Update the self generated code for Document, PropertySheet and Interface
this_module = sys.modules[ __name__ ]
document_classes = generateInitFiles(this_module, globals())
# Update ERP5 Globals
from Products.ERP5Type.Utils import initializeProduct, updateGlobals
import Interface, PropertySheet, Permissions, Constraint
updateGlobals( this_module, globals(),
property_sheet_module = PropertySheet,
interface_module = Interface,
permissions_module = Permissions,
constraint_module = Constraint)
import sys, Permissions
this_module = sys.modules[ __name__ ]
document_classes = updateGlobals( this_module, globals(), permissions_module = Permissions)
# Define object classes and tools
import ShopManager
......
......@@ -30,24 +30,11 @@
and extended local roles management
"""
# First import the minimal number of packages required by the code generation
from Products.ERP5Type.InitGenerator import generateInitFiles
import sys
# Update the self generated code for Document, PropertySheet and Interface
this_module = sys.modules[ __name__ ]
document_classes = generateInitFiles(this_module, globals())
# Update ERP5 Globals
from Products.ERP5Type.Utils import initializeProduct, updateGlobals
import Interface, PropertySheet, Permissions, Constraint
updateGlobals( this_module, globals(),
property_sheet_module = PropertySheet,
interface_module = Interface,
permissions_module = Permissions,
constraint_module = Constraint)
import sys, Permissions
this_module = sys.modules[ __name__ ]
document_classes = updateGlobals( this_module, globals(), permissions_module = Permissions)
# Define object classes and tools
import SynchronizationTool
......
......@@ -65,8 +65,17 @@ import random
from zLOG import LOG
class CallbaseError(AttributeError):
pass
# Dynamic method acquisition system (code generation)
aq_method_generated = {}
def _initializeDefaultProperties(klass):
if not aq_method_generated.has_key(klass):
LOG('in aq_method_generated %s' % id, 0, str(klass.__name__))
from Utils import initializeDefaultProperties
initializeDefaultProperties([klass])
aq_method_generated[klass] = 1
for super_klass in klass.__bases__:
_initializeDefaultProperties(super_klass)
class Base( CopyContainer, PortalContent, Base18, ActiveObject, ERP5PropertyManager ):
"""
......@@ -114,6 +123,14 @@ class Base( CopyContainer, PortalContent, Base18, ActiveObject, ERP5PropertyMana
# We want to use a default property view
manage_propertiesForm = DTMLFile( 'dtml/properties', _dtmldir )
def _aq_dynamic(self, id):
global aq_method_generated
klass = self.__class__
if not aq_method_generated.has_key(klass):
_initializeDefaultProperties(klass)
return getattr(self, id)
return None
# Constructor
def __init__(self, id, uid=None, rid=None, sid=None, **kw):
self.id = id
......
......@@ -38,9 +38,8 @@ product_document_registry = []
def InitializeDocument(document_class, document_path=None):
global product_document_registry
InitializeClass(document_class)
# Register class in ERP5Type.Document
product_document_registry.append(((document_class.__name__, document_path)))
product_document_registry.append(((document_class, document_path)))
#LOG('InitializeDocument', 0, document_class.__name__)
def initializeProductDocumentRegistry():
......@@ -51,163 +50,4 @@ def initializeProductDocumentRegistry():
#ZopeTestCase._print('Added product document to ERP5Type repository: %s (%s) \n' % (class_id, document_path))
#LOG('Added product document to ERP5Type repository: %s (%s)' % (class_id, document_path), 0, '')
#print 'Added product document to ERP5Type repository: %s (%s)' % (class_id, document_path)
# Code Generation of __init__.py files
def generateInitFiles(this_module, global_hook,
generate_document=1, generate_property_sheet=1, generate_constraint=1, generate_interface=1):
# Determine product_path
product_path = package_home( global_hook )
# Add _dtmldir
this_module._dtmldir = os.path.join( product_path, 'dtml' )
# This regular expression is used to check is a file is a python file
python_file_expr = re.compile("py$")
# Create Document __init__.py file
document_path = product_path + '/Document'
document_module_name_list = []
document_module_lines = ["from Products.ERP5Type import Document as ERP5TypeDocumentRepository\n\n"]
try:
file_list = os.listdir(document_path)
for file_name in file_list:
if file_name != '__init__.py':
if python_file_expr.search(file_name,1):
module_name = file_name[0:-3]
document_module_name_list += [module_name]
document_module_lines += ["""\
# Hide internal implementation
from Products.ERP5Type.InitGenerator import InitializeDocument
import %s as ERP5%s
if not hasattr(ERP5TypeDocumentRepository, '_override_%s'): ERP5TypeDocumentRepository.%s = ERP5%s # Never override a local Document class
# Default constructor for %s
# Can be overriden by adding a method add%s in class %s
def add%s(folder, id, REQUEST=None, **kw):
o = ERP5TypeDocumentRepository.%s.%s(id)
folder._setObject(id, o)
o.uid = folder.portal_catalog.newUid()
if kw is not None: o.__of__(folder)._edit(force_update=1, **kw)
# contentCreate already calls reindex 3 times ...
# o.reindexObject()
if REQUEST is not None:
REQUEST['RESPONSE'].redirect( 'manage_main' )
InitializeDocument(ERP5TypeDocumentRepository.%s.%s, document_path='%s')
class Temp%s(ERP5TypeDocumentRepository.%s.%s):
isIndexable = 0
def reindexObject(self, *args, **kw):
pass
def recursiveReindexObject(self, *args, **kw):
pass
def activate(self):
return self
def setUid(self, value):
self.uid = value # Make sure no casting happens when we use Temp classes to create new objects
from Products.PythonScripts.Utility import allow_class
allow_class(Temp%s)
def newTemp%s(folder, id, REQUEST=None, **kw):
o = Temp%s(id)
o = o.__of__(folder)
if kw is not None: o._edit(force_update=1, **kw)
return o
ERP5TypeDocumentRepository.newTemp%s = newTemp%s
from AccessControl import ModuleSecurityInfo
ModuleSecurityInfo('Products.ERP5Type.Document').declarePublic('newTemp%s',)
""" % (module_name, module_name,
module_name, module_name, module_name,
module_name,
module_name, module_name,
module_name,
module_name, module_name,
module_name, module_name, document_path,
module_name, module_name, module_name,
module_name,
module_name,
module_name,
module_name, module_name,
module_name,)]
if generate_document:
try:
document_init_file = open(document_path + '/__init__.py', 'w')
document_init_file.write(string.join(document_module_lines, '\n'))
document_init_file.close()
except:
LOG('ERP5Type:',0,'Could not write Document __init__.py files for %s' % product_path)
except:
LOG('ERP5Type:',0,'No Document directory in %s' % product_path)
# Create Property __init__.py file
property_path = product_path + '/PropertySheet'
property_module_name_list = []
property_module_lines = []
try:
file_list = os.listdir(property_path)
for file_name in file_list:
if file_name != '__init__.py':
if python_file_expr.search(file_name,1):
module_name = file_name[0:-3]
property_module_name_list += [module_name]
property_module_lines += ['from %s import %s' % (module_name, module_name)]
if generate_property_sheet:
try:
property_init_file = open(property_path + '/__init__.py', 'w')
property_init_file.write(string.join(property_module_lines, '\n'))
property_init_file.close()
except:
LOG('ERP5Type:',0,'Could not write PropertySheet __init__.py files for %s' % product_path)
except:
LOG('ERP5Type:',0,'No PropertySheet directory in %s' % product_path)
# Create Interface __init__.py file
interface_path = product_path + '/Interface'
interface_module_name_list = []
interface_module_lines = []
try:
file_list = os.listdir(interface_path)
for file_name in file_list:
if file_name != '__init__.py':
if python_file_expr.search(file_name,1):
module_name = file_name[0:-3]
interface_module_name_list += [module_name]
interface_module_lines += ['from %s import %s' % (module_name, module_name)]
if generate_interface:
try:
interface_init_file = open(interface_path + '/__init__.py', 'w')
interface_init_file.write(string.join(interface_module_lines, '\n'))
interface_init_file.close()
except:
LOG('ERP5Type:',0,'Could not write Interface __init__.py files for %s' % product_path)
except:
LOG('ERP5Type:',0,'No Interface directory in %s' % product_path)
# Create Constraint __init__.py file
constraint_path = product_path + '/Constraint'
constraint_module_name_list = []
constraint_module_lines = []
try:
file_list = os.listdir(constraint_path)
for file_name in file_list:
if file_name != '__init__.py':
if python_file_expr.search(file_name,1):
module_name = file_name[0:-3]
constraint_module_name_list += [module_name]
constraint_module_lines += ['from %s import %s' % (module_name, module_name)]
if generate_constraint:
try:
constraint_init_file = open(constraint_path + '/__init__.py', 'w')
constraint_init_file.write(string.join(constraint_module_lines, '\n'))
constraint_init_file.close()
except:
LOG('ERP5Type:',0,'Could not write Constraint __init__.py files for %s' % product_path)
except:
LOG('ERP5Type:',0,'No Constraint directory in %s' % product_path)
return document_module_name_list
from Base import Base
from XMLObject import XMLObject
from SimpleItem import SimpleItem
from DublinCore import DublinCore
from Folder import Folder
\ No newline at end of file
from Folder import Folder
from SimpleItem import SimpleItem
from XMLObject import XMLObject
\ No newline at end of file
......@@ -40,12 +40,6 @@ from Products.ERP5Type import Constraint
from Products.ERP5Type import Interface
from Products.ERP5Type import PropertySheet
# This is really uggly... and we want to improve it
import Products.ERP5Type.Constraint.CategoryMembershipArity
import Products.ERP5Type.Constraint.AttributeEquality
import Products.ERP5Type.Constraint.PropertyTypeValidity
import Products.ERP5Type.Constraint.CategoryRelatedMembershipArity
from zLOG import LOG
#####################################################
......@@ -149,48 +143,68 @@ def getPath(o):
# Globals initialization
#####################################################
from InitGenerator import InitializeDocument
# List Regexp
python_file_expr = re.compile("py$")
def getModuleIdList(product_path, module_id):
global python_file_expr
path = os.path.join(product_path, module_id)
module_name_list = []
module_lines = []
try:
file_list = os.listdir(path)
for file_name in file_list:
if file_name != '__init__.py':
if python_file_expr.search(file_name,1):
module_name = file_name[0:-3]
module_name_list += [module_name]
except:
LOG('ERP5Type:',0,'No PropertySheet directory in %s' % product_path)
return path, module_name_list
# EPR5Type global modules update
def updateGlobals( this_module, global_hook,
property_sheet_module = None,
interface_module = None,
permissions_module = None,
constraint_module = None):
def updateGlobals( this_module, global_hook, permissions_module = None, is_erp5_type=0):
"""
This function does all the initialization steps required
for a Zope / CMF Product
"""
product_name = this_module.__name__.split('.')[-1]
# Update PropertySheet
if property_sheet_module is not None:
for key in dir(property_sheet_module):
# Do not consider private keys
if key[0:2] != '__':
setattr(PropertySheet, key, getattr(property_sheet_module, key))
# Update Interface
if interface_module is not None:
for key in dir(interface_module):
# Do not consider private keys
if key[0:2] != '__':
setattr(Interface, key, getattr(interface_module, key))
# Update Permissions
if permissions_module is not None:
for key in dir(permissions_module):
# Do not consider private keys
if key[0:2] != '__':
setattr(Permissions, key, getattr(permissions_module, key))
# Update Constraint
if constraint_module is not None: