diffsync.helpers
¶
DiffSync helper classes for calculating and performing diff and sync operations.
Copyright (c) 2020-2021 Network To Code, LLC info@networktocode.com
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
diffsync.helpers.DiffSyncDiffer
¶
Helper class implementing diff calculation logic for DiffSync.
Independent from Diff and DiffElement as those classes are purely data objects, while this stores some state.
__init__(src_diffsync, dst_diffsync, flags, diff_class=Diff, callback=None)
¶
Create a DiffSyncDiffer for calculating diffs between the provided DiffSync instances.
calculate_diffs()
¶
Calculate diffs between the src and dst DiffSync objects and return the resulting Diff.
diff_child_objects(diff_element, src_obj, dst_obj)
¶
For all children of the given DiffSyncModel pair, diff recursively, adding diffs to the given diff_element.
Helper method to calculate_diffs, usually doesn't need to be called directly.
These helper methods work in a recursive cycle: diff_object_list -> diff_object_pair -> diff_child_objects -> diff_object_list -> etc.
diff_object_list(src, dst)
¶
Calculate diffs between two lists of like objects.
Helper method to calculate_diffs, usually doesn't need to be called directly.
These helper methods work in a recursive cycle: diff_object_list -> diff_object_pair -> diff_child_objects -> diff_object_list -> etc.
diff_object_pair(src_obj, dst_obj)
¶
Diff the two provided DiffSyncModel objects and return a DiffElement or None.
Helper method to calculate_diffs, usually doesn't need to be called directly.
These helper methods work in a recursive cycle: diff_object_list -> diff_object_pair -> diff_child_objects -> diff_object_list -> etc.
incr_models_processed(delta=1)
¶
Increment self.models_processed, then call self.callback if present.
validate_objects_for_diff(object_pairs)
staticmethod
¶
Check whether all DiffSyncModels in the given dictionary are valid for comparison to one another.
Helper method for diff_object_list.
Raises:
| Type | Description |
|---|---|
TypeError
|
If any pair of objects in the dict have differing get_type() values. |
ValueError
|
If any pair of objects in the dict have differing get_shortname() or get_identifiers() values. |
diffsync.helpers.DiffSyncSyncer
¶
Helper class implementing data synchronization logic for DiffSync.
Independent from DiffSync and DiffSyncModel as those classes are purely data objects, while this stores some state.
__init__(diff, src_diffsync, dst_diffsync, flags, callback=None)
¶
Create a DiffSyncSyncer instance, ready to call perform_sync() against.
incr_elements_processed(delta=1)
¶
Increment self.elements_processed, then call self.callback if present.
log_sync_status(action, status, message)
¶
Log the current sync status at the appropriate verbosity with appropriate context.
Helper method to sync_diff_element/sync_model.
perform_sync()
¶
Perform data synchronization based on the provided diff.
Returns:
| Type | Description |
|---|---|
bool
|
True if any changes were actually performed, else False. |
sync_diff_element(element, parent_model=None)
¶
Recursively synchronize the given DiffElement and its children, if any, into the dst_diffsync.
Helper method to perform_sync.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if this element or any of its children resulted in actual changes, else False. |
sync_model(src_model, dst_model, ids, attrs)
¶
Create/update/delete the current DiffSyncModel with current ids/attrs, and update self.status and self.message.
Helper method to sync_diff_element.
Returns:
| Type | Description |
|---|---|
Tuple[bool, Optional[DiffSyncModel]]
|
(changed, model) where model may be None if an error occurred |