summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-04-10 18:27:28 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2018-04-10 21:02:15 +0900
commit888f0b9fda31e8a63b01b9aa5b695010249b8ffa (patch)
tree3f400bbde31bd6bf7d678924efcb9570f86d9149
parent5a36d04eb4fabef3087e4842e7340f28eca049e3 (diff)
downloadbuildstream-888f0b9fda31e8a63b01b9aa5b695010249b8ffa.tar.gz
_workspaces.py: Added Workspaces.update_workspace()
This takes a serialized workspace dictionary as understood by Workspace.from_dict() and created by Workspace.to_dict() Further, this adds a Workspace.differs() method to compare the state of two workspace instances.
-rw-r--r--buildstream/_workspaces.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/buildstream/_workspaces.py b/buildstream/_workspaces.py
index ef01f40d5..cd4448054 100644
--- a/buildstream/_workspaces.py
+++ b/buildstream/_workspaces.py
@@ -91,6 +91,27 @@ class Workspace():
# Just pass the dictionary as kwargs
return cls(project, **dictionary)
+ # differs()
+ #
+ # Checks if two workspaces are different in any way.
+ #
+ # Args:
+ # other (Workspace): Another workspace instance
+ #
+ # Returns:
+ # True if the workspace differs from 'other', otherwise False
+ #
+ def differs(self, other):
+
+ for member in _WORKSPACE_MEMBERS:
+ member_a = getattr(self, member)
+ member_b = getattr(other, member)
+
+ if member_a != member_b:
+ return True
+
+ return False
+
# invalidate_key()
#
# Invalidate the workspace key, forcing a recalculation next time
@@ -236,6 +257,27 @@ class Workspaces():
return None
return self._workspaces[element_name]
+ # update_workspace()
+ #
+ # Update the datamodel with a new Workspace instance
+ #
+ # Args:
+ # element_name (str): The name of the element to update a workspace for
+ # workspace_dict (Workspace): A serialized workspace dictionary
+ #
+ # Returns:
+ # (bool): Whether the workspace has changed as a result
+ #
+ def update_workspace(self, element_name, workspace_dict):
+ assert element_name in self._workspaces
+
+ workspace = Workspace.from_dict(self._project, workspace_dict)
+ if self._workspaces[element_name].differs(workspace):
+ self._workspaces[element_name] = workspace
+ return True
+
+ return False
+
# delete_workspace()
#
# Remove the workspace from the workspace element. Note that this