Back to index

plone3  3.1.7
__init__.py
Go to the documentation of this file.
00001 # Interface definitions
00002 from zope.interface import Interface, Attribute
00003 
00004 # Zope2 BBB
00005 from Interface.bridge import createZope3Bridge
00006 
00007 class IDiffTool(Interface):
00008     """An interface to compute object differences via pluggable
00009        difference engine"""
00010 
00011     id = Attribute('id','Must be set to "portal_diff"')
00012 
00013 
00014     def listDiffTypes():
00015         """List the names of the available difference types"""
00016 
00017     def setDiffForPortalType(pt_name, mapping):
00018         """Set the difference type(s) for the specific portal type
00019 
00020         mapping is a dictionary where each key is an attribute or
00021         method on the given portal type, and the value is the name of
00022         a difference type."""
00023 
00024     def getDiffForPortalType(pt_name):
00025         """Returns a dictionary where each key is an attribute or
00026         method on the given portal type, and the value is the name of
00027         a difference type."""
00028     
00029     def computeDiff(ob1, ob2):
00030         """Compute the differences from ob1 to ob2 (ie. ob2 - ob1).
00031 
00032         The result will be a list of objects that implements the
00033         IDifference interface and represent the differences between
00034         ob1 and ob2."""
00035 
00036     def createChangeSet(ob1, ob2):
00037         """Returns a ChangeSet object that represents the differences
00038         between ob1 and ob2 (ie. ob2 - ob1) ."""
00039     
00040 
00041 
00042 class IDifference(Interface):
00043     """An interface for interacting with the difference between two
00044     objects"""
00045 
00046     meta_type = Attribute('title', 'A human readable name for the diff type')
00047     field = Attribute('field', 'The name of the field being compared')
00048     same = Attribute('same', 'True if the fields are the "same" (whatever that means for this difference)')
00049     oldValue = Attribute('oldValue', 'The old field value being compared')
00050     newValue = Attribute('newValue', 'The new field value being compared')
00051 
00052     def testChanges(ob):
00053         """Test the specified object to determine if the change set will apply cleanly.
00054 
00055         Returns None if there would be no erros
00056         """
00057 
00058     def applyChanges(ob):
00059         """Update the specified object with the difference"""
00060 
00061 
00062 class IStringDifference(IDifference):
00063     """An anterface for interacting with the difference between two
00064     string (text) objects"""
00065 
00066     def getLineDiffs():
00067         """Return a list of differences between the two objects on a
00068         line-by-line basis
00069 
00070         Each difference is a 5-tuple as described here:
00071         http://www.python.org/doc/2.1.3/lib/sequence-matcher.html#l2h-721
00072 
00073         The interpretation of these tuples depends on the difference class"""
00074 
00075 ##     def getCharDiffs():
00076 ##         """Return a list of character differences on a line-by-line basis.
00077         
00078 ##         For every line in the field being compared, return a list of
00079 ##         character differences """
00080 
00081 
00082 class IChangeSet(Interface):
00083     """And interface representing all of the differences between two objects"""
00084     
00085     same = Attribute('same', 'True if the fields are the "same"')
00086 
00087     def computeDiff(ob1, ob2, recursive=1, exclude=[]):
00088         """Compute the differences from ob1 to ob2 (ie. ob2 - ob1).
00089 
00090         If resursive is 1, compute differences between subobjects of
00091         ob1 and ob2 as well, excluding any subobjects whose IDs are
00092         listed in exclude
00093 
00094         The results can be accessed through getDiffs()"""
00095 
00096     def testChanges(ob):
00097         """Test the specified object to determine if the change set will apply cleanly.
00098 
00099         Returns None if there would be no erros
00100         """
00101 
00102     def applyChanges(ob):
00103         """Apply the computed changes to the specified object"""
00104         
00105     def getDiffs():
00106         """Returns the list of differences between the two objects.
00107 
00108         Each difference is a single object implementing the IDifference interface"""
00109 
00110     def getSubDiffs():
00111         """If the ChangeSet was computed recursively, returns a list
00112            of ChangeSet objects representing subobject differences
00113 
00114            Each ChangeSet will have the same ID as the objects whose
00115            difference it represents.
00116            """
00117 
00118     def getAddedItems():
00119         """If the ChangeSet was computed recursively, returns the list
00120         of IDs of items that were added.
00121 
00122         A copy of these items is available as a cubject of the ChangeSet
00123         """
00124 
00125     def getRemovedItems():
00126         """If the ChangeSet was computed recursively, returns the list
00127         of IDs of items that were removed"""
00128 
00129 import portal_diff
00130 from Products.CMFDiffTool.interfaces import IChangeSet as csmod
00131 createZope3Bridge(IDiffTool, portal_diff, 'portal_diff')
00132 createZope3Bridge(IDifference, portal_diff, 'IDifference')
00133 createZope3Bridge(IChangeSet, csmod, 'IChangeSet')