Commit 4600dd9f authored by Ayush Tiwari's avatar Ayush Tiwari

bt5_config: Add function for creating snapshot

parent 71da67c2
...@@ -120,17 +120,14 @@ class BusinessCommit(Folder): ...@@ -120,17 +120,14 @@ class BusinessCommit(Folder):
return super(BusinessCommit, self).newContent(id, **kw) return super(BusinessCommit, self).newContent(id, **kw)
def install(self): def createEquivalentSnapshot(self):
""" """
Installation: This function uses the current commit to create a new snapshot
- create an empty snapshot that that's similar to a Commit
- fill it with hard links to commits and snapshots
- install it
""" """
portal_commit = self.aq_parent portal_commit = self.aq_parent
# Create empty snapshot # Create empty snapshot
snapshot = portal_commit.newContent(portal_type='Business Commit') snapshot = portal_commit.newContent(portal_type='Business Snapshot')
# Add the current commit as predecessor. This way we can have the BI # Add the current commit as predecessor. This way we can have the BI
# BPI in that commit to the Business Snapshot also. # BPI in that commit to the Business Snapshot also.
snapshot.setPredecessorValue(self) snapshot.setPredecessorValue(self)
...@@ -138,8 +135,27 @@ class BusinessCommit(Folder): ...@@ -138,8 +135,27 @@ class BusinessCommit(Folder):
# Build the snapshot # Build the snapshot
snapshot.buildSnapshot() snapshot.buildSnapshot()
for item in snapshot.item_list: return snapshot
def install(self):
"""
Installation:
- check if there is already an equivalent snapshot
- if not, create one and install it
"""
successor_list = self.getPredecessorRelatedValueList()
# Check if the successor list has a snapshot in it
try:
eqv_snapshot = [l for l
in successor_list
if l.getPortalType() == 'Business Snapshot'][0]
except IndexError:
# Create a new equivalent snapshot
eqv_snapshot = self.createEquivalentSnapshot()
for item in eqv_snapshot.item_list:
item.install(self) item.install(self)
def getPathList(self): def getItemPathList(self):
return [l.getProperty('item_path') for l in self.objectValues()] return [l.getProperty('item_path') for l in self.objectValues()]
...@@ -174,18 +174,40 @@ class BusinessSnapshot(Folder): ...@@ -174,18 +174,40 @@ class BusinessSnapshot(Folder):
# Get last created snapshot # Get last created snapshot
last_snapshot = self.getLastSnapshot() last_snapshot = self.getLastSnapshot()
# [1]: Extend the item_list with list of items from last snapshot # Commit list of all commits between the last snapshot/first commit and the
new_item_list.extend(last_snapshot.getItemList()) # current snapshot
new_item_path_list.extend(last_snapshot.getItemPathList())
successor_commit_list = [] successor_commit_list = []
# Get next predecessor commit for this snapshot using the equivalent commit # If there is last snapshot, then combine all the commit afterwards to create
# Notice that we don't use the snapshot to get the next commit as the # new snapshot
# snapshot is mere a state which uses `predecessor` just for mentioning the if last_snapshot:
# equivalent commit.
next_commit = eqv_commit.getPredecessorRelatedValue() # [1]: Extend the item_list with list of items from last snapshot
new_item_list.extend(last_snapshot.getItemList())
new_item_path_list.extend(last_snapshot.getItemPathList())
# Get next predecessor commit for this snapshot using the equivalent commit
# Notice that we don't use the snapshot to get the next commit as the
# snapshot is mere a state which uses `predecessor` just for mentioning the
# equivalent commit.
# Here the first next commit should be the commit created after last snapshot
# which we can get using the equivalent commit of last snapshot and then
# finding the next commit for it
next_commit = last_snapshot.getPredecessorValue().getPredecessorRelatedValue()
# If there is no last snapshot, create a new one by combining all the commits
else:
# Get the oldest commit and start from there to find the next commit
oldest_commit = min(
self.aq_parent.objectValues(portal_type='Business Commit'),
key=(lambda x: x.getCreationDate()))
new_item_list.extend(oldest_commit.objectValues())
new_item_path_list.extend(oldest_commit.getItemPathList())
next_commit = oldest_commit.getPredecessorRelatedValue()
# Fill sucessor commit list
while (next_commit.getId() != eqv_commit.getId()): while (next_commit.getId() != eqv_commit.getId()):
successor_commit_list.append(next_commit) successor_commit_list.append(next_commit)
next_commit = next_commit.getPredecessorRelatedValue() next_commit = next_commit.getPredecessorRelatedValue()
......
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