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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tatuya Kamada
erp5
Commits
5e49155a
Commit
5e49155a
authored
Jan 20, 2012
by
Arnaud Fontaine
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow to erase an existing Component before importing from filesystem.
parent
4c03bfef
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
7 deletions
+18
-7
product/ERP5Type/Core/ExtensionComponent.py
product/ERP5Type/Core/ExtensionComponent.py
+14
-5
product/ERP5Type/Tool/ComponentTool.py
product/ERP5Type/Tool/ComponentTool.py
+4
-2
No files found.
product/ERP5Type/Core/ExtensionComponent.py
View file @
5e49155a
...
...
@@ -47,7 +47,7 @@ class ExtensionComponent(DocumentComponent):
security
.
declareProtected
(
Permissions
.
ModifyPortalContent
,
'importAllFromFilesystem'
)
@
classmethod
def
importAllFromFilesystem
(
cls
,
context
):
def
importAllFromFilesystem
(
cls
,
context
,
erase_existing
=
False
):
"""
Try to import all Extensions as found in INSTANCEHOME/Extensions and
returns error as a dict if any
...
...
@@ -64,7 +64,7 @@ class ExtensionComponent(DocumentComponent):
failed_import_dict
=
{}
for
extension_path
in
glob
.
iglob
(
extension_path_pattern
):
try
:
cls
.
importFromFilesystem
(
context
,
extension_path
)
cls
.
importFromFilesystem
(
context
,
extension_path
,
erase_existing
)
except
Exception
,
e
:
failed_import_dict
[
extension_path
]
=
str
(
e
)
else
:
...
...
@@ -76,11 +76,21 @@ class ExtensionComponent(DocumentComponent):
security
.
declareProtected
(
Permissions
.
ModifyPortalContent
,
'importFromFilesystem'
)
@
classmethod
def
importFromFilesystem
(
cls
,
context
,
path
):
def
importFromFilesystem
(
cls
,
context
,
path
,
erase_existing
=
False
):
"""
Import an Extension from the given path into ZODB after checking that the
source code is valid
"""
class_name
=
os
.
path
.
basename
(
path
).
replace
(
'.py'
,
''
)
id
=
'erp5.component.extension.%s'
%
class_name
# XXX-arnau: not efficient at all
if
id
in
context
:
if
not
erase_existing
:
return
context
.
deleteContent
(
id
)
with
open
(
path
)
as
extension_file
:
source_code
=
extension_file
.
read
()
...
...
@@ -88,8 +98,7 @@ class ExtensionComponent(DocumentComponent):
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
,
return
context
.
newContent
(
id
=
id
,
# XXX-arnau: useless field?
reference
=
class_name
,
text_content
=
source_code
,
...
...
product/ERP5Type/Tool/ComponentTool.py
View file @
5e49155a
...
...
@@ -95,8 +95,10 @@ class ComponentTool(BaseTool):
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
))
failed_import_dict
.
update
(
getattr
(
erp5
.
portal_type
,
content_portal_type
).
importAllFromFilesystem
(
self
,
erase_existing
=
erase_existing
))
except
AttributeError
:
LOG
(
"ERP5Type.Tool.ComponentTool"
,
WARNING
,
"Could not import %ss"
%
\
content_portal_type
)
...
...
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