Skip to content

Commit bb63ee5

Browse files
Merge pull request #44 from networktocode/gfm-status-logging
Model sync status reporting; logging fixes; refactoring
2 parents cbc503c + fa82b35 commit bb63ee5

File tree

9 files changed

+685
-383
lines changed

9 files changed

+685
-383
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## Unreleased
44

5+
- Now requires Pydantic 1.7.2 or later
6+
7+
- Added `set_status()` API so that DiffSyncModel implementations can provide details for create/update/delete logging
58
- `DiffSync.get_by_uids()` now raises `ObjectNotFound` if any of the provided uids cannot be located.
69
- `DiffSync.get()` raises `ObjectNotFound` or `ValueError` on failure, instead of returning `None`.
710
- #34 - in diff dicts, change keys `src`/`dst`/`_src`/`_dst` to `-` and `+`

diffsync/__init__.py

Lines changed: 48 additions & 351 deletions
Large diffs are not rendered by default.

diffsync/enum.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
"""DiffSync enums and flags.
2+
3+
Copyright (c) 2020 Network To Code, LLC <[email protected]>
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
"""
17+
18+
import enum
19+
20+
21+
class DiffSyncModelFlags(enum.Flag):
22+
"""Flags that can be set on a DiffSyncModel class or instance to affect its usage."""
23+
24+
NONE = 0
25+
26+
IGNORE = 0b1
27+
"""Do not render diffs containing this model; do not make any changes to this model when synchronizing.
28+
29+
Can be used to indicate a model instance that exists but should not be changed by DiffSync.
30+
"""
31+
32+
SKIP_CHILDREN_ON_DELETE = 0b10
33+
"""When deleting this model, do not recursively delete its children.
34+
35+
Can be used for the case where deletion of a model results in the automatic deletion of all its children.
36+
"""
37+
38+
39+
class DiffSyncFlags(enum.Flag):
40+
"""Flags that can be passed to a sync_* or diff_* call to affect its behavior."""
41+
42+
NONE = 0
43+
44+
CONTINUE_ON_FAILURE = 0b1
45+
"""Continue synchronizing even if failures are encountered when syncing individual models."""
46+
47+
SKIP_UNMATCHED_SRC = 0b10
48+
"""Ignore objects that only exist in the source/"from" DiffSync when determining diffs and syncing.
49+
50+
If this flag is set, no new objects will be created in the target/"to" DiffSync.
51+
"""
52+
53+
SKIP_UNMATCHED_DST = 0b100
54+
"""Ignore objects that only exist in the target/"to" DiffSync when determining diffs and syncing.
55+
56+
If this flag is set, no objects will be deleted from the target/"to" DiffSync.
57+
"""
58+
59+
SKIP_UNMATCHED_BOTH = SKIP_UNMATCHED_SRC | SKIP_UNMATCHED_DST
60+
61+
LOG_UNCHANGED_RECORDS = 0b1000
62+
"""If this flag is set, a log message will be generated during synchronization for each model, even unchanged ones.
63+
64+
By default, when this flag is unset, only models that have actual changes to synchronize will be logged.
65+
This flag is off by default to reduce the default verbosity of DiffSync, but can be enabled when debugging.
66+
"""
67+
68+
69+
class DiffSyncStatus(enum.Enum):
70+
"""Flag values to set as a DiffSyncModel's `_status` when performing a sync; values are logged by DiffSyncSyncer."""
71+
72+
UNKNOWN = "unknown"
73+
SUCCESS = "success"
74+
FAILURE = "failure"
75+
ERROR = "error"

0 commit comments

Comments
 (0)