Package mrv :: Module conf :: Class ConfigDiffer
[hide private]
[frames] | no frames]

Class ConfigDiffer

source code

object --+    
         |    
  DiffData --+
             |
            ConfigDiffer

Compares two configuration objects and allows retrieval of differences

Use this class to find added/removed sections or keys or differences in values and properties.

Example Applicance:
Test use it to verify that reading and writing a (possibly) changed configuration has the expected results Programs interacting with the User by a GUI can easily determine whether the user has actually changed something, applying actions only if required alternatively, programs can simply be more efficient by acting only on items that actually changed
Data Structure:
  • DiffSection.added|removed|unchanged: Key objects that have been added, removed or kept unchanged respectively
  • DiffSection.changed: DiffKey objects that indicate the changes in the repsective key
  • DiffKey.added|removed: the key's values that have been added and/or removed respectively
  • DiffKey.properties: see DiffSection.properties
  • DiffSection.properties:None if this is a section diff, otherwise it contains a DiffSection with the respective differences
Instance Methods [hide private]
 
__str__(self)
Print its own delta information - useful for debugging purposes
source code
 
_populate(self, A, B)
Perform the acutal diffing operation to fill our data structures :note: this method directly accesses ConfigAccessors internal datastructures
source code
 
applyTo(self, ca)
Apply the stored differences in this ConfigDiffer instance to the given ConfigAccessor
source code

Inherited from DiffData: __init__, hasDifferences, toStr

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __subclasshook__

Class Methods [hide private]
 
_getMergedSections(cls, configaccessor)
within config nodes, sections must be unique, between nodes, this is not the case - sets would simply drop keys with the same name leading to invalid results - thus we have to merge equally named sections
source code
Properties [hide private]

Inherited from DiffData: added, changed, name, properties, removed, unchanged

Inherited from object: __class__

Method Details [hide private]

__str__(self)
(Informal representation operator)

source code 
Print its own delta information - useful for debugging purposes
Overrides: object.__str__

_getMergedSections(cls, configaccessor)
Class Method

source code 
within config nodes, sections must be unique, between nodes, this is not the case - sets would simply drop keys with the same name leading to invalid results - thus we have to merge equally named sections
Returns:
BasicSet with merged sections

To Do: make this algo work on sets instead of individual sections for performance

_populate(self, A, B)

source code 
Perform the acutal diffing operation to fill our data structures :note: this method directly accesses ConfigAccessors internal datastructures
Overrides: DiffData._populate

applyTo(self, ca)

source code 

Apply the stored differences in this ConfigDiffer instance to the given ConfigAccessor

If our diff contains the changes of A to B, then applying ourselves to A would make A equal B.

Parameters:
  • ca - The configacceesor to apply our differences to
Returns:

tuple of lists containing the sections that could not be added, removed or get their changes applied

  • [0] = list of Section s failed to be added
  • [1] = list of Section s failed to be removed
  • [2] = list of DiffSection s failed to apply their changes

Note: individual nodes reqpresenting an input source (like a file) can be marked read-only. This means they cannot be altered - thus it can be that section or key removal fails for them. Addition of elements normally works as long as there is one writable node.