Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Binh
erp5
Commits
6db1ecc3
Commit
6db1ecc3
authored
Jan 19, 2012
by
Arnaud Fontaine
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow to import Extensions from filesystem into ZODB.
parent
a53c1f25
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
139 additions
and
3 deletions
+139
-3
product/ERP5/bootstrap/erp5_core/PortalTypeTemplateItem/portal_types/Extension%20Component.xml
...alTypeTemplateItem/portal_types/Extension%20Component.xml
+1
-1
product/ERP5/bootstrap/erp5_core/bt/change_log
product/ERP5/bootstrap/erp5_core/bt/change_log
+3
-0
product/ERP5/bootstrap/erp5_core/bt/revision
product/ERP5/bootstrap/erp5_core/bt/revision
+1
-1
product/ERP5Type/Core/ExtensionComponent.py
product/ERP5Type/Core/ExtensionComponent.py
+96
-0
product/ERP5Type/Tool/ComponentTool.py
product/ERP5Type/Tool/ComponentTool.py
+38
-1
No files found.
product/ERP5/bootstrap/erp5_core/PortalTypeTemplateItem/portal_types/Extension%20Component.xml
View file @
6db1ecc3
...
@@ -82,7 +82,7 @@
...
@@ -82,7 +82,7 @@
</item>
</item>
<item>
<item>
<key>
<string>
type_class
</string>
</key>
<key>
<string>
type_class
</string>
</key>
<value>
<string>
Document
Component
</string>
</value>
<value>
<string>
Extension
Component
</string>
</value>
</item>
</item>
<item>
<item>
<key>
<string>
type_interface
</string>
</key>
<key>
<string>
type_interface
</string>
</key>
...
...
product/ERP5/bootstrap/erp5_core/bt/change_log
View file @
6db1ecc3
2012-01-19 arnaud.fontaine
* Extension Component has now its own class (meaningful for importing from filesystem).
2012-01-18 arnaud.fontaine
2012-01-18 arnaud.fontaine
* Complete ComponentTool view.
* Complete ComponentTool view.
* Implement Extension Component.
* Implement Extension Component.
...
...
product/ERP5/bootstrap/erp5_core/bt/revision
View file @
6db1ecc3
40990
40991
\ No newline at end of file
\ No newline at end of file
product/ERP5Type/Core/ExtensionComponent.py
0 → 100644
View file @
6db1ecc3
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2012 Nexedi SA and Contributors. All Rights Reserved.
# Arnaud Fontaine <arnaud.fontaine@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility 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
# guarantees 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., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
#
##############################################################################
import
os.path
from
Products.ERP5Type.Core.DocumentComponent
import
DocumentComponent
from
AccessControl
import
ClassSecurityInfo
from
Products.ERP5Type
import
Permissions
from
zLOG
import
LOG
,
INFO
class
ExtensionComponent
(
DocumentComponent
):
# CMF Type Definition
meta_type
=
'ERP5 Extension Component'
portal_type
=
'Extension Component'
# Declarative security
security
=
ClassSecurityInfo
()
security
.
declareObjectProtected
(
Permissions
.
AccessContentsInformation
)
security
.
declareProtected
(
Permissions
.
ModifyPortalContent
,
'importAllFromFilesystem'
)
@
classmethod
def
importAllFromFilesystem
(
cls
,
context
):
"""
Try to import all Extensions as found in INSTANCEHOME/Extensions and
returns error as a dict if any
"""
from
App.config
import
getConfiguration
extension_path_pattern
=
"%s%s%s/*"
%
(
getConfiguration
().
instancehome
,
os
.
path
.
sep
,
'Extensions'
)
LOG
(
"ERP5Type.Core.ExtensionComponent"
,
INFO
,
"Importing from %s"
%
extension_path_pattern
)
import
glob
failed_import_dict
=
{}
for
extension_path
in
glob
.
iglob
(
extension_path_pattern
):
try
:
cls
.
importFromFilesystem
(
context
,
extension_path
)
except
Exception
,
e
:
failed_import_dict
[
extension_path
]
=
str
(
e
)
else
:
LOG
(
"ERP5Type.Core.ExtensionComponent"
,
INFO
,
"Imported %s"
%
extension_path
)
return
failed_import_dict
security
.
declareProtected
(
Permissions
.
ModifyPortalContent
,
'importFromFilesystem'
)
@
classmethod
def
importFromFilesystem
(
cls
,
context
,
path
):
"""
Import an Extension from the given path into ZODB after checking that the
source code is valid
"""
with
open
(
path
)
as
extension_file
:
source_code
=
extension_file
.
read
()
# Try to load it first
namespace_dict
=
{}
exec
source_code
in
namespace_dict
class_name
=
os
.
path
.
basename
(
path
).
replace
(
'.py'
,
''
)
return
context
.
newContent
(
id
=
'erp5.component.extension.%s'
%
class_name
,
# XXX-arnau: useless field?
reference
=
class_name
,
text_content
=
source_code
,
portal_type
=
cls
.
portal_type
)
product/ERP5Type/Tool/ComponentTool.py
View file @
6db1ecc3
...
@@ -31,7 +31,7 @@ from AccessControl import ClassSecurityInfo
...
@@ -31,7 +31,7 @@ from AccessControl import ClassSecurityInfo
from
Products.ERP5Type.Tool.BaseTool
import
BaseTool
from
Products.ERP5Type.Tool.BaseTool
import
BaseTool
from
Products.ERP5Type
import
Permissions
from
Products.ERP5Type
import
Permissions
from
zLOG
import
LOG
,
INFO
from
zLOG
import
LOG
,
INFO
,
WARNING
class
ComponentTool
(
BaseTool
):
class
ComponentTool
(
BaseTool
):
"""
"""
...
@@ -75,3 +75,40 @@ class ComponentTool(BaseTool):
...
@@ -75,3 +75,40 @@ class ComponentTool(BaseTool):
"Global reset of %s.%s"
%
(
module_name
,
name
))
"Global reset of %s.%s"
%
(
module_name
,
name
))
delattr
(
module
,
name
)
delattr
(
module
,
name
)
security
.
declareProtected
(
Permissions
.
ManagePortal
,
'createAllComponentFromFilesystem'
)
def
createAllComponentFromFilesystem
(
self
,
erase_existing
=
False
,
REQUEST
=
None
):
"""
XXX-arnau: only Extensions for now
"""
portal
=
self
.
getPortalObject
()
import
erp5.portal_type
type_tool
=
portal
.
portal_types
failed_import_dict
=
{}
for
content_portal_type
in
getattr
(
type_tool
,
self
.
portal_type
).
getTypeAllowedContentTypeList
():
try
:
failed_import_dict
.
update
(
getattr
(
erp5
.
portal_type
,
content_portal_type
).
importAllFromFilesystem
(
self
))
except
AttributeError
:
LOG
(
"ERP5Type.Tool.ComponentTool"
,
WARNING
,
"Could not import %ss"
%
\
content_portal_type
)
if
REQUEST
:
if
failed_import_dict
:
failed_import_formatted_list
=
[]
for
name
,
error
in
failed_import_dict
.
iteritems
():
failed_import_formatted_list
.
append
(
"%s (%s)"
%
(
name
,
error
))
message
=
"The following component could not be imported: %s"
%
\
', '
.
join
(
failed_import_formatted_list
)
else
:
message
=
"All components were successfully imported "
\
"from filesystem to ZODB."
return
self
.
Base_redirect
(
'view'
,
keep_items
=
{
'portal_status_message'
:
message
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment