Commit 883748c1 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Support product generation from class tool.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@5676 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent bde0bb0c
############################################################################## ##############################################################################
# #
# Copyright (c) 2002-2004 Nexedi SARL and Contributors. All Rights Reserved. # Copyright (c) 2002-2006 Nexedi SARL and Contributors. All Rights Reserved.
# Jean-Paul Smets-Solanes <jp@nexedi.com> # Jean-Paul Smets-Solanes <jp@nexedi.com>
# #
# WARNING: This program as such is intended to be used by professional # WARNING: This program as such is intended to be used by professional
...@@ -31,6 +31,9 @@ from Products.CMFCore.utils import UniqueObject ...@@ -31,6 +31,9 @@ from Products.CMFCore.utils import UniqueObject
from Acquisition import Implicit from Acquisition import Implicit
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Globals import InitializeClass, DTMLFile from Globals import InitializeClass, DTMLFile
from App.config import getConfiguration
import os
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
from Products.ERP5Type import _dtmldir from Products.ERP5Type import _dtmldir
from Products.ERP5Type.Tool.BaseTool import BaseTool from Products.ERP5Type.Tool.BaseTool import BaseTool
...@@ -80,6 +83,9 @@ if allowClassTool(): ...@@ -80,6 +83,9 @@ if allowClassTool():
,{ 'label' : 'Tests' ,{ 'label' : 'Tests'
, 'action' : 'manage_viewTestList' , 'action' : 'manage_viewTestList'
} }
,{ 'label' : 'Product Generation'
, 'action' : 'manage_viewProductGeneration'
}
, ,
) )
+ tuple ( + tuple (
...@@ -120,6 +126,9 @@ if allowClassTool(): ...@@ -120,6 +126,9 @@ if allowClassTool():
security.declareProtected( Permissions.ManagePortal, 'manage_editPropertySheetForm' ) security.declareProtected( Permissions.ManagePortal, 'manage_editPropertySheetForm' )
manage_editPropertySheetForm = DTMLFile( 'editPropertySheetForm', _dtmldir ) manage_editPropertySheetForm = DTMLFile( 'editPropertySheetForm', _dtmldir )
security.declareProtected( Permissions.ManagePortal, 'manage_viewProductGeneration' )
manage_viewProductGeneration = DTMLFile( 'viewProductGeneration', _dtmldir )
# Clears the cache of all databases # Clears the cache of all databases
def _clearCache(self): def _clearCache(self):
database = self.Control_Panel.Database database = self.Control_Panel.Database
...@@ -582,6 +591,147 @@ class ConstraintTemplate(Constraint): ...@@ -582,6 +591,147 @@ class ConstraintTemplate(Constraint):
if REQUEST is not None: if REQUEST is not None:
REQUEST.RESPONSE.redirect('%s/manage_editConstraintForm?class_id=%s&message=Constraint+Saved' % (self.absolute_url(), class_id)) REQUEST.RESPONSE.redirect('%s/manage_editConstraintForm?class_id=%s&message=Constraint+Saved' % (self.absolute_url(), class_id))
security.declareProtected( Permissions.ManageExtensions, 'generateProduct' )
def generateProduct(self, product_id,
document_id_list=(), property_sheet_id_list=(), constraint_id_list=(),
extension_id_list=(), test_id_list=(), REQUEST=None):
"""Generate a Product
"""
# Ensure that Products exists.
product_path = os.path.join(getConfiguration().instancehome, 'Products')
if not os.path.exists(product_path):
os.mkdir(product_path)
# Make a new Product directory if not present.
base_path = os.path.join(product_path, product_id)
if not os.path.exists(base_path):
os.mkdir(base_path)
# Make sub-directories if not present.
for d in ('Interface', 'Document', 'PropertySheet', 'Extensions', 'Tool', 'Constraint',
'tests', 'help', 'skins', 'dtml', ):
path = os.path.join(base_path, d)
if not os.path.exists(path):
os.mkdir(path)
# Create an empty __init__.py.
init = os.path.join(path, '__init__.py')
if not os.path.exists(init):
f = open(init, 'w')
f.close()
# For convenience, make .cvsignore.
cvsignore = os.path.join(path, '.cvsignore')
if not os.path.exists(cvsignore):
f = open(cvsignore, 'w')
try:
f.write('*.pyc' + os.linesep)
finally:
f.close()
# Create a Permissions module for this Product.
permissions = os.path.join(base_path, 'Permissions.py')
if not os.path.exists(permissions):
f = open(permissions, 'w')
f.close()
# Make .cvsignore for convenience.
cvsignore = os.path.join(base_path, '.cvsignore')
if not os.path.exists(cvsignore):
f = open(cvsignore, 'w')
try:
f.write('*.pyc' + os.linesep)
finally:
f.close()
# Create an init file for this Product.
init = os.path.join(base_path, '__init__.py')
if not os.path.exists(init):
text = '''
##############################################################################
#
# Copyright (c) 2006 Nexedi SARL and Contributors. All Rights Reserved.
# Yoshinori Okuji <yo@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
"""
ERP5 Free Software ERP
"""
# 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 ):
import Document
initializeProduct(context, this_module, globals(),
document_module = Document,
document_classes = document_classes,
object_classes = (),
portal_tools = (),
content_constructors = (),
content_classes = ())
'''
f = open(init, 'w')
try:
f.write(text)
finally:
f.close()
# Create a skeleton README.txt.
readme = os.path.join(base_path, 'README.txt')
if not os.path.exists(readme):
text = '''
%s
%s was automatically generated by ERP5 Class Tool.
''' % (product_id, product_id)
f = open(readme, 'w')
try:
f.write(text)
finally:
f.close()
# Now, copy selected code.
for d, m, id_list in (('Document', readLocalDocument, document_id_list),
('PropertySheet', readLocalPropertySheet, property_sheet_id_list),
('Constraint', readLocalConstraint, constraint_id_list),
('tests', readLocalTest, test_id_list),
('Extensions', readLocalExtension, extension_id_list)):
for class_id in id_list:
path = os.path.join(base_path, d, class_id) + '.py'
text = m(class_id)
f = open(path, 'w')
try:
f.write(text)
finally:
f.close()
if REQUEST is not None:
REQUEST.RESPONSE.redirect('%s/manage_viewProductGeneration?message=New+Product+Saved+In+%s' % (self.absolute_url(), base_path))
else: else:
class ClassTool(BaseTool): class ClassTool(BaseTool):
...@@ -598,4 +748,3 @@ else: ...@@ -598,4 +748,3 @@ else:
manage_overview = DTMLFile( 'explainDummyClassTool', _dtmldir ) manage_overview = DTMLFile( 'explainDummyClassTool', _dtmldir )
InitializeClass(ClassTool) InitializeClass(ClassTool)
<dtml-var manage_page_header>
<dtml-var manage_tabs>
<div class="std-text"><p><strong>Product Generation</strong></p></div>
<dtml-if message><p><dtml-var message></p></dtml-if>
<form method="POST" action="generateProduct">
<table cellspacing="0" cellpadding="2" border="0">
<tr>
<td align="left" valign="top" colspan="2">
<div class="form-help">
Enter a Product name and select classes to be included in this new Product.
</div>
</td>
</tr>
<tr>
<td align="left" valign="top">
<div class="form-label">
Product Name
</div>
</td>
<td align="left" valign="top">
<input type="text" name="product_id" size="40" value="" />
</td>
</tr>
<tr>
<td align="left" valign="top">
<div class="form-label">
Documents
</div>
</td>
<td align="left" valign="top">
<dtml-in getLocalDocumentList>
<input type="checkbox" name="document_id_list:list" value="&dtml-sequence-item;" />
&dtml-sequence-item;
<br/>
</dtml-in>
</td>
</tr>
<tr>
<td align="left" valign="top">
<div class="form-label">
PropertySheets
</div>
</td>
<td align="left" valign="top">
<dtml-in getLocalPropertySheetList>
<input type="checkbox" name="document_id_list:list" value="&dtml-sequence-item;" />
&dtml-sequence-item;
<br/>
</dtml-in>
</td>
</tr>
<tr>
<td align="left" valign="top">
<div class="form-label">
Constraints
</div>
</td>
<td align="left" valign="top">
<dtml-in getLocalConstraintList>
<input type="checkbox" name="document_id_list:list" value="&dtml-sequence-item;" />
&dtml-sequence-item;
<br/>
</dtml-in>
</td>
</tr>
<tr>
<td align="left" valign="top">
<div class="form-label">
Extensions
</div>
</td>
<td align="left" valign="top">
<dtml-in getLocalExtensionList>
<input type="checkbox" name="document_id_list:list" value="&dtml-sequence-item;" />
&dtml-sequence-item;
<br/>
</dtml-in>
</td>
</tr>
<tr>
<td align="left" valign="top">
<div class="form-label">
Tests
</div>
</td>
<td align="left" valign="top">
<dtml-in getLocalTestList>
<input type="checkbox" name="document_id_list:list" value="&dtml-sequence-item;" />
&dtml-sequence-item;
<br/>
</dtml-in>
</td>
</tr>
</table>
<input type="submit" value=" Generate Product " />
</form>
<dtml-var manage_page_footer>
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