Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes
CMFDiffTool.ChangeSet.BaseChangeSet Class Reference
Inheritance diagram for CMFDiffTool.ChangeSet.BaseChangeSet:
Inheritance graph
[legend]
Collaboration diagram for CMFDiffTool.ChangeSet.BaseChangeSet:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def getId
def __getitem__
def computeDiff
def testChanges
def applyChanges
def getDiffs
def getSubDiffs
def getAddedItems
def getRemovedItems

Public Attributes

 id
 title
 ob1_path
 ob2_path
 recursive

Static Public Attributes

tuple security = ClassSecurityInfo()
tuple same = ComputedAttribute(_isSame)

Private Member Functions

def _isSame
def _addSubSet

Private Attributes

 _diffs
 _added
 _removed
 _changesets
 _changed

Static Private Attributes

tuple __implements__ = (IChangeSetZ2,)
int __allow_access_to_unprotected_subobjects__ = 1

Detailed Description

A ChangeSet represents the set of differences between two objects

Definition at line 67 of file ChangeSet.py.


Constructor & Destructor Documentation

def CMFDiffTool.ChangeSet.BaseChangeSet.__init__ (   self,
  id,
  title = '' 
)
ChangeSet constructor

Reimplemented in CMFDiffTool.ChangeSet.ChangeSet.

Definition at line 76 of file ChangeSet.py.

00076 
00077     def __init__(self, id, title=''):
00078         """ChangeSet constructor"""
00079         self.id = id
00080         self.title = title
00081         self._diffs = []
00082         self._added = []
00083         self._removed = []
00084         self.ob1_path = []
00085         self.ob2_path = []
00086         self._changesets = {}
00087         self.recursive = 0


Member Function Documentation

Reimplemented in CMFDiffTool.ChangeSet.ChangeSet.

Definition at line 93 of file ChangeSet.py.

00093 
00094     def __getitem__(self, key):
00095         return self._changesets[key]

Here is the caller graph for this function:

def CMFDiffTool.ChangeSet.BaseChangeSet._addSubSet (   self,
  id,
  ob1,
  ob2,
  exclude,
  id1,
  id2 
) [private]

Reimplemented in CMFDiffTool.ChangeSet.ChangeSet.

Definition at line 158 of file ChangeSet.py.

00158 
00159     def _addSubSet(self, id, ob1, ob2, exclude, id1, id2):
00160         cs = BaseChangeSet(id, title='Changes to: %s' % id)
00161         cs = cs.__of__(self)
00162         cs.computeDiff(ob1[id], ob2[id], exclude=exclude, id1=id1, id2=id2)
00163         self._changesets[id] = aq_base(cs)

Returns true if there are no differences between the two objects

Definition at line 96 of file ChangeSet.py.

00096 
00097     def _isSame(self):
00098         """Returns true if there are no differences between the two objects"""
00099         return reduce(lambda x, y: x and y, [d.same for d in self._diffs], 1)

Apply the change set to the specified object

Definition at line 176 of file ChangeSet.py.

00176 
00177     def applyChanges(self, ob):
00178         """Apply the change set to the specified object"""
00179         for d in self._diffs:
00180             d.applyChanges(ob)
00181 
00182         if self._removed:
00183             ob.manage_delObjects(self._removed)
00184 
00185         for id in self._added:
00186             child = self[id]
00187             ob.manage_clone(child, id)
00188 
00189         for id in self._changed:
00190             cs = self[id]
00191             child = ob[id]
00192             cs.applyChanges(child)

def CMFDiffTool.ChangeSet.BaseChangeSet.computeDiff (   self,
  ob1,
  ob2,
  recursive = 1,
  exclude = [],
  id1 = None,
  id2 = None 
)
Compute the differences from ob1 to ob2 (ie. ob2 - ob1).

The results can be accessed through getDiffs()

Reimplemented in CMFDiffTool.ChangeSet.ChangeSet.

Definition at line 104 of file ChangeSet.py.

00104 
00105     def computeDiff(self, ob1, ob2, recursive=1, exclude=[], id1=None, id2=None):
00106         """Compute the differences from ob1 to ob2 (ie. ob2 - ob1).
00107 
00108         The results can be accessed through getDiffs()"""
00109 
00110         # Reset state
00111         self._diffs = []
00112         self._added = []
00113         self._removed = []
00114         self._changed = []
00115         self._changesets = {}
00116 
00117         purl = getToolByName(self, 'portal_url', None)
00118         if purl is not None:
00119             try:
00120                 self.ob1_path = purl.getRelativeContentPath(ob1)
00121                 self.ob2_path = purl.getRelativeContentPath(ob2)
00122             except AttributeError:
00123                 # one or both of the objects may not have a path
00124                 return
00125         diff_tool = getToolByName(self, "portal_diff")
00126         self._diffs = diff_tool.computeDiff(ob1, ob2, id1=id1, id2=id2)
00127 
00128         if recursive and ob1.isPrincipiaFolderish and \
00129                                                      ob2.isPrincipiaFolderish:
00130             self.recursive = 1
00131             ids1 = set(ob1.objectIds())
00132             ids2 = set(ob2.objectIds())
00133             self._changed = ids1.intersection(ids2)
00134             self._removed = ids1.difference(ids2)
00135             self._added = ids2.difference(ids1)
00136 
00137             # Ignore any excluded items
00138             for id in exclude:
00139                 try:
00140                     self._added.remove(id)
00141                 except ValueError:
00142                     pass
00143                 try:
00144                     self._removed.remove(id)
00145                 except ValueError:
00146                     pass
00147                 try:
00148                     self._changed.remove(id)
00149                 except ValueError:
00150                     pass
00151 
00152             # Calculate a ChangeSet for every subobject that has changed
00153             # XXX this is a little strange as self._changed doesn't appear
00154             # to list changed objects, but rather objects which have been
00155             # reordered or renamed.
00156             for id in self._changed:
00157                 self._addSubSet(id, ob1, ob2, exclude, id1, id2)

If the ChangeSet was computed recursively, returns the list
of IDs of items that were added.

A copy of these items is available as a cubject of the ChangeSet

Definition at line 211 of file ChangeSet.py.

00211 
00212     def getAddedItems(self):
00213         """If the ChangeSet was computed recursively, returns the list
00214         of IDs of items that were added.
00215 
00216         A copy of these items is available as a cubject of the ChangeSet
00217         """
00218         return list(self._added)

Returns the list differences between the two objects.

Each difference is a single object implementing the IDifference interface

Definition at line 194 of file ChangeSet.py.

00194 
00195     def getDiffs(self):
00196         """Returns the list differences between the two objects.
00197 
00198         Each difference is a single object implementing the IDifference interface"""
00199         return self._diffs

ChangeSet id

Definition at line 89 of file ChangeSet.py.

00089 
00090     def getId(self):
00091         """ChangeSet id"""
00092         return self.id

If the ChangeSet was computed recursively, returns the list
of IDs of items that were removed

Definition at line 220 of file ChangeSet.py.

00220 
00221     def getRemovedItems(self):
00222         """If the ChangeSet was computed recursively, returns the list
00223         of IDs of items that were removed"""
00224         return list(self._removed)
00225 

If the ChangeSet was computed recursively, returns a list
   of ChangeSet objects representing subjects differences

   Each ChangeSet will have the same ID as the objects whose
   difference it represents.

Definition at line 201 of file ChangeSet.py.

00201 
00202     def getSubDiffs(self):
00203         """If the ChangeSet was computed recursively, returns a list
00204            of ChangeSet objects representing subjects differences
00205 
00206            Each ChangeSet will have the same ID as the objects whose
00207            difference it represents.
00208            """
00209         return [self[id] for id in self._changed]

Test the specified object to determine if the change set will apply without errors

Definition at line 165 of file ChangeSet.py.

00165 
00166     def testChanges(self, ob):
00167         """Test the specified object to determine if the change set will apply without errors"""
00168         for d in self._diffs:
00169             d.testChanges(ob)
00170 
00171         for id in self._changed:
00172             cs = self[id]
00173             child = ob[id]
00174             cs.testChanges(child)

Here is the caller graph for this function:


Member Data Documentation

Definition at line 73 of file ChangeSet.py.

tuple CMFDiffTool.ChangeSet.BaseChangeSet.__implements__ = (IChangeSetZ2,) [static, private]

Reimplemented in CMFDiffTool.ChangeSet.ChangeSet.

Definition at line 70 of file ChangeSet.py.

Definition at line 81 of file ChangeSet.py.

Definition at line 113 of file ChangeSet.py.

Definition at line 85 of file ChangeSet.py.

Definition at line 80 of file ChangeSet.py.

Definition at line 82 of file ChangeSet.py.

Definition at line 78 of file ChangeSet.py.

Definition at line 83 of file ChangeSet.py.

Definition at line 84 of file ChangeSet.py.

Definition at line 86 of file ChangeSet.py.

tuple CMFDiffTool.ChangeSet.BaseChangeSet.same = ComputedAttribute(_isSame) [static]

Definition at line 101 of file ChangeSet.py.

tuple CMFDiffTool.ChangeSet.BaseChangeSet.security = ClassSecurityInfo() [static]

Reimplemented in CMFDiffTool.ChangeSet.ChangeSet.

Definition at line 74 of file ChangeSet.py.

Definition at line 79 of file ChangeSet.py.


The documentation for this class was generated from the following file: