diff
DiffNode ¶
Bases: BaseModel
Node representing a file, symlink or directory in a diff.
Source code in src/metador_core/util/diff.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
|
removed
class-attribute
instance-attribute
¶
removed: Dict[Path, DiffNode] = {}
Deleted files and subdirectories.
modified
class-attribute
instance-attribute
¶
modified: Dict[Path, DiffNode] = {}
Modified or replaced files and subdirectories.
added
class-attribute
instance-attribute
¶
added: Dict[Path, DiffNode] = {}
New files and subdirectories.
Status ¶
Bases: str
, Enum
Change that happened to a DiffNode.
Source code in src/metador_core/util/diff.py
21 22 23 24 25 26 27 |
|
ObjType ¶
Bases: str
, Enum
Entities represented in a DiffNode.
Source code in src/metador_core/util/diff.py
29 30 31 32 33 34 |
|
children ¶
children() -> Iterable[DiffNode]
Return immediate children in no specific order.
Source code in src/metador_core/util/diff.py
72 73 74 75 76 |
|
nodes ¶
nodes() -> List[DiffNode]
Return list of all nodes in this diff.
The order will be recursively: removed children, modified children, itself, then added children. Within the same category the children are sorted in alphabetical order.
Source code in src/metador_core/util/diff.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
|
status ¶
status() -> DiffNode.Status
Check the given path (which is assumed to be relative to this diff node).
Returns whether the path was added, removed or modified, respectively.
Source code in src/metador_core/util/diff.py
95 96 97 98 99 100 101 102 103 104 105 |
|
compare
classmethod
¶
compare(
prev: Optional[DirHashsums],
curr: Optional[DirHashsums],
path: Path,
) -> Optional[DiffNode]
Compare two nested file and directory hashsum dicts.
Returns None if no difference is found, otherwise a DiffNode tree containing only the additions, removals and changes.
Source code in src/metador_core/util/diff.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
|
DirDiff ¶
Interface to directory diffs based on comparing DirHashsums
.
An instance represents a change at the path.
Granular change inspection is accessible through the provided methods.
Typically, you will want to capture dir_hashsums
of the same dir
at two points in time and will be interested in the dict
DirDiff.compare(prev, curr).annotate(dir)
.
Source code in src/metador_core/util/diff.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
|
compare
classmethod
¶
compare(prev: DirHashsums, curr: DirHashsums) -> DirDiff
Compute a DirDiff based on two DirHashsum trees.
To be meaningful, prev
and curr
should be trees obtained from the
same directory at two points in time.
Source code in src/metador_core/util/diff.py
196 197 198 199 200 201 202 203 204 205 |
|
status ¶
status(node: Optional[DiffNode]) -> DiffNode.Status
Return the type of change that happened to a diff node.
Wraps node.status()
additionally covering the case that node
is None
.
Useful when processing possible path nodes returned by annotate
.
Source code in src/metador_core/util/diff.py
225 226 227 228 229 230 231 232 233 |
|
annotate ¶
annotate(base_dir: Path) -> Dict[Path, Optional[DiffNode]]
Return a dict of path -> status mappings based on passed directory.
The keys are all paths that exist in this diff object as well as
all paths that currently exist in the passed base_dir
.
The keys will all have base_dir
as prefix.
The values will be the corresponding DiffNodes, if there is a change. If there was no change at that path, the value will be None.
The iteration order will be such that for each entity, first the removed children, then changed subentities, then the entity itself, and finally added subentities are listed. This is useful for updating operations of directories and ensures that children can be deleted before their parents and parents can be created before their children.
Source code in src/metador_core/util/diff.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
|
dir_paths ¶
dir_paths(base_dir: Path)
Recursively list all paths in given directory, relative to itself.
Source code in src/metador_core/util/diff.py
13 14 15 |
|