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
alecs_myu
erp5
Commits
ce9726c9
Commit
ce9726c9
authored
Apr 27, 2017
by
Ayush Tiwari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bt5_config: Use properties of BM while updating Installation State
parent
b544ece2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
53 deletions
+50
-53
product/ERP5/Document/BusinessManager.py
product/ERP5/Document/BusinessManager.py
+15
-30
product/ERP5/Tool/TemplateTool.py
product/ERP5/Tool/TemplateTool.py
+35
-23
No files found.
product/ERP5/Document/BusinessManager.py
View file @
ce9726c9
...
...
@@ -153,7 +153,7 @@ class BusinessManager(Folder):
"""
_properties = (
{'id': '
manager
_path_list',
{'id': '
template
_path_list',
'type': 'lines',
'default': 'python: ()',
'acquisition_base_category': (),
...
...
@@ -214,26 +214,16 @@ class BusinessManager(Folder):
portal
=
self
.
getPortalObject
()
pass
def
edit
(
self
,
manager
_path_list
=
[],
**
kw
):
def
edit
(
self
,
template
_path_list
=
[],
**
kw
):
"""
Explicilty edit the class instance
XXX: No need of this class ? as we already have _edit from ERP5Type.Folder
"""
super
(
BusinessManager
,
self
).
edit
(
manager_path_list
=
manager_path_list
,
**
kw
)
def
getTemplatePathList
(
self
):
return
self
.
getProperty
(
'manager_path_list'
)
super
(
BusinessManager
,
self
).
edit
(
template_path_list
=
template_path_list
,
**
kw
)
def
getPathItemList
(
self
):
return
self
.
objectValues
()
security
.
declareProtected
(
Permissions
.
ManagePortal
,
'_getTemplatePathList'
)
def
_getTemplatePathList
(
self
):
result
=
self
.
getTemplatePathList
()
if
not
isinstance
(
result
,
tuple
):
result
=
tuple
(
result
)
return
result
# XXX: Change into property
security
.
declareProtected
(
Permissions
.
ManagePortal
,
'getTemplateFormatVersion'
)
def
getTemplateFormatVersion
(
self
):
...
...
@@ -289,15 +279,15 @@ class BusinessManager(Folder):
self
.
title
=
imported_manager
.
title
for
obj
in
imported_manager
.
objectValues
():
self
.
_setObject
(
obj
.
getId
(),
obj
)
self
.
setProperty
(
'
manager_path_list'
,
obj
.
getTemplatePathList
(
))
self
.
setProperty
(
'
template_path_list'
,
imported_manager
.
getProperty
(
'template_path_list'
))
def
__add__
(
self
,
other
):
"""
Adds the Business Item objects for the given Business Manager objects
"""
self
.
_path_item_list
.
extend
(
other
.
_path_item_list
)
manager_path_list
=
list
(
self
.
manager_path_list
)
+
list
(
other
.
manager
_path_list
)
self
.
manager_path_list
=
manager
_path_list
template_path_list
=
list
(
self
.
template_path_list
)
+
list
(
other
.
template
_path_list
)
self
.
template_path_list
=
template
_path_list
return
self
__radd__
=
__add__
...
...
@@ -330,7 +320,9 @@ class BusinessManager(Folder):
"""
portal
=
self
.
getPortalObject
()
LOG
(
'Business Manager'
,
INFO
,
'Storing Manager Data'
)
path_item_list
=
self
.
getTemplatePathList
()
path_item_list
=
self
.
getProperty
(
'template_path_list'
)
if
not
path_item_list
:
path_item_list
=
()
# Delete all the older Business Item objects while rebuilding
exisiting_path_item_id_list
=
[
l
for
l
in
self
.
objectIds
()]
self
.
manage_delObjects
(
ids
=
exisiting_path_item_id_list
)
...
...
@@ -381,7 +373,7 @@ class BusinessManager(Folder):
if
isBuild
:
# If build process, update the path list of the Business Manager
self
.
setProperty
(
'
manager
_path_list'
,
new_path_item_list
)
self
.
setProperty
(
'
template
_path_list'
,
new_path_item_list
)
def
_resolvePath
(
self
,
folder
,
relative_url_list
,
id_list
):
"""
...
...
@@ -417,21 +409,14 @@ class BusinessManager(Folder):
def
getPathList
(
self
):
path_list
=
[]
for
item
in
self
.
objectValues
():
path_list
.
append
(
item
.
getProperty
(
'path'
))
path_list
.
append
(
item
.
getProperty
(
'
item_
path'
))
return
path_list
def
getPathShaDict
(
self
):
path_sha_dict
=
{}
# TODO: Handle error for BM with multiple items at same path
for
item
in
self
.
objectValues
():
path_sha_dict
[
item
.
getProperty
(
'path'
)]
=
item
.
getProperty
(
'sha'
)
return
path_item_dict
def
getPathItemDict
(
self
):
path_item_dict
=
{}
# TODO: Handle error for BM with multiple items at same path
for
item
in
self
.
_path_item_list
:
path_item_dict
[
item
.
path
]
=
item
for
item
in
self
.
objectValues
()
:
path_item_dict
[
item
.
getProperty
(
'item_path'
)
]
=
item
return
path_item_dict
def
getBusinessItemByPath
(
self
,
path
):
...
...
@@ -794,9 +779,9 @@ class BusinessItem(XMLObject):
container
.
_delObject
(
object_id
)
# Create a new object only if sign is +1
# If sign is +1, set the new object on the container
if
self
.
sign
==
1
:
if
int
(
self
.
getProperty
(
'item_sign'
))
==
1
:
# install object
obj
=
self
.
getProperty
(
'item_value'
)
obj
=
self
.
objectValues
()[
0
]
obj
=
obj
.
_getCopy
(
container
)
container
.
_setObject
(
object_id
,
obj
)
obj
=
container
.
_getOb
(
object_id
)
...
...
product/ERP5/Tool/TemplateTool.py
View file @
ce9726c9
...
...
@@ -1692,14 +1692,15 @@ class TemplateTool (BaseTool):
installed_bm_list
=
self
.
getInstalledBusinessManagerList
()
combined_installed_path_item
=
[
item
for
bm
in
installed_bm_list
for
item
in
bm
.
_path_item_list
]
for
item
in
bm
.
objectValues
()
]
# Create BM for old installation state and update its path item list
old_installation_state
=
self
.
newContent
(
portal_type
=
'Business Manager'
,
title
=
'Old Installation State'
,
)
old_installation_state
.
_path_item_list
=
combined_installed_path_item
for
item
in
combined_installed_path_item
:
old_installation_state
.
_setObject
(
item
.
getId
(),
item
)
forbidden_bm_title_list
=
[
'Old Installation State'
,]
for
bm
in
bm_list
:
...
...
@@ -1712,14 +1713,15 @@ class TemplateTool (BaseTool):
combined_new_path_item
=
[
item
for
bm
in
new_installed_bm_list
for
item
in
bm
.
_path_item_list
]
for
item
in
bm
.
objectValues
()
]
# Create BM for new installation state and update its path item list
new_installation_state
=
self
.
newContent
(
portal_type
=
'Business Manager'
,
title
=
'New Installation State'
,
)
new_installation_state
.
_path_item_list
=
combined_new_path_item
for
item
in
combined_new_path_item
:
new_installation_state
.
_setObject
(
item
.
getId
(),
item
)
# Create installation process, which have the changes to be made in the
# OFS during installation. Importantly, it should also be a Business Manager
...
...
@@ -1742,29 +1744,34 @@ class TemplateTool (BaseTool):
# Add the removed path with negative sign in the to_install_path_item_list
for
path
in
removed_path_list
:
old_item
=
old_installation_state
.
getBusinessItemByPath
(
path
)
old_item
.
s
ign
=
-
1
old_item
.
s
etProperty
(
'item_sign'
,
'-1'
)
to_install_path_item_list
.
append
(
old_item
)
# XXX: At this point, we expect all the Business Manager objects as 'reduced',
# thus all the BusinessItem sub-objects should have single value
# Update hashes of item in old state before installation
for
item
in
old_installation_state
.
_path_item_list
:
print
item
.
value
if
item
.
value
:
item
.
s
ha
=
self
.
calculateComparableHash
(
item
.
value
)
for
item
in
old_installation_state
.
objectValues
()
:
value_list
=
item
.
objectValues
()
if
value_list
:
item
.
s
etProperty
(
'item_sha'
,
self
.
calculateComparableHash
(
value_list
[
0
])
)
# Path Item List for installation_process should be the difference between
# old and new installation state
for
item
in
new_installation_state
.
_path_item_list
:
for
item
in
new_installation_state
.
objectValues
()
:
# If the path has been removed, then add it with sign = -1
old_item
=
old_installation_state
.
getBusinessItemByPath
(
item
.
path
)
old_item
=
old_installation_state
.
getBusinessItemByPath
(
item
.
getProperty
(
'item_path'
))
# Calculate sha for the items in new_insatallation_state
item
.
setProperty
(
'item_sha'
,
self
.
calculateComparableHash
(
item
.
objectValues
()[
0
]))
if
old_item
:
# If the old_item exists, we match the hashes and if it differs, then
# add the new item
if
old_item
.
sha
!=
item
.
sha
:
if
old_item
.
getProperty
(
'item_sha'
)
!=
item
.
getProperty
(
'item_sha'
)
:
to_install_path_item_list
.
append
(
item
)
else
:
to_install_path_item_list
.
append
(
item
)
installation_process
.
_path_item_list
=
to_install_path_item_list
for
item
in
to_install_path_item_list
:
installation_process
.
_setObject
(
item
.
getId
(),
item
)
error_list
=
self
.
compareOldStateToOFS
(
installation_process
,
old_installation_state
)
...
...
@@ -1796,8 +1803,12 @@ class TemplateTool (BaseTool):
if
attr
.
startswith
(
'_v'
)]
removable_attributes
.
append
(
'uid'
)
removable_attributes
.
append
(
'_owner'
)
for
attr
in
removable_attributes
:
del
obj_dict
[
attr
]
try
:
del
obj_dict
[
attr
]
except
KeyError
:
continue
obj_sha
=
hash
(
pprint
.
pformat
(
obj_dict
))
return
obj_sha
...
...
@@ -1844,13 +1855,13 @@ class TemplateTool (BaseTool):
if
old_item
:
# Compare hash with ZODB
if
old_item
.
sha
==
obj_sha
:
if
old_item
.
getProperty
(
'item_sha'
)
==
obj_sha
:
# No change at ZODB on old item, so get the new item
new_item
=
installation_process
.
getBusinessItemByPath
(
path
)
# Compare new item hash with ZODB
if
new_item
.
sha
==
obj_sha
:
if
new_item
.
sign
==
-
1
:
if
new_item
.
getProperty
(
'item_sha'
)
==
obj_sha
:
if
int
(
new_item
.
getProperty
(
'item_sign'
))
==
-
1
:
# If the sign is negative, remove the value from the path
new_item
.
install
(
installation_process
)
else
:
...
...
@@ -1866,7 +1877,7 @@ class TemplateTool (BaseTool):
new_item
=
installation_process
.
getBusinessItemByPath
(
path
)
# Compare new item hash with ZODB
if
new_item
.
sha
==
obj_sha
:
if
new_item
.
getProperty
(
'item_sha'
)
==
obj_sha
:
# If same hash, do nothing
continue
...
...
@@ -1879,7 +1890,7 @@ class TemplateTool (BaseTool):
# Compare with the new_item
new_item
=
installation_process
.
getBusinessItemByPath
(
path
)
if
new_item
.
sha
==
obj_sha
:
if
new_item
.
getProperty
(
'item_sha'
)
==
obj_sha
:
# If same hash, do nothing
continue
...
...
@@ -1898,17 +1909,18 @@ class TemplateTool (BaseTool):
new_item
=
installation_process
.
getBusinessItemByPath
(
path
)
# Check sign of new_item
if
new_item
.
sign
==
1
:
if
int
(
new_item
.
getProperty
(
'item_sign'
))
==
1
:
error_list
.
append
(
'Object at %s removed by user'
%
path
)
else
:
# If there is no item at old state, install the new_item
new_item
=
installation_process
.
getBusinessItemByPath
(
path
)
# XXX: Hack for not trying to install the sub-objects from zexp,
# This should rather be implem
neted while exportign
the object,
# This should rather be implem
ented while exporting
the object,
# where we shouldn't export sub-objects in the zexp
value
=
new_item
.
value
if
value
is
None
:
try
:
value
=
new_item
.
objectValues
()[
0
]
except
IndexError
:
continue
if
getattr
(
value
,
'_tree'
,
None
):
# This check is required cause only after first access we get the
...
...
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