trestle.core.commands.split
trestle.core.commands.split
¤
Trestle Split Command.
Attributes¤
logger = logging.getLogger(__name__)
module-attribute
¤
trace = log.Trace(logger)
module-attribute
¤
Classes¤
AliasTracker
¤
Bases: TrestleBaseModel
Convenience class to track writing out of models.
Source code in trestle/core/commands/split.py
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 |
|
Attributes¤
aliases
instance-attribute
¤
written = False
class-attribute
instance-attribute
¤
Functions¤
add_alias(alias)
¤
Add alias.
Source code in trestle/core/commands/split.py
50 51 52 53 |
|
get_aliases()
¤
Get the list of aliases.
Source code in trestle/core/commands/split.py
55 56 57 |
|
mark_written()
¤
Mark this model as written.
Source code in trestle/core/commands/split.py
63 64 65 |
|
needs_writing()
¤
Need to write the model.
Source code in trestle/core/commands/split.py
59 60 61 |
|
SplitCmd
¤
Bases: CommandPlusDocs
Split subcomponents on a trestle model.
Source code in trestle/core/commands/split.py
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 176 177 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 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 |
|
Attributes¤
name = 'split'
class-attribute
instance-attribute
¤
Functions¤
find_aliases_to_strip(element_paths)
classmethod
¤
Find list of aliases that need to be stripped as each element written out.
Source code in trestle/core/commands/split.py
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 |
|
perform_split(effective_cwd, file_name, elements, trestle_root)
classmethod
¤
Perform the split operation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
effective_cwd | Path | effective directory in which the the split operation is performed | required |
file_name | str | file name of model to split, or '' if deduced from elements and cwd | required |
elements | str | comma separated list of paths to strip from the file, with quotes removed | required |
Returns:
Type | Description |
---|---|
int | 0 on success and 1 on failure |
Source code in trestle/core/commands/split.py
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 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
|
prepare_sub_model_split_actions(sub_model_item, sub_model_dir, file_prefix, content_type)
classmethod
¤
Create split actions of sub model.
Source code in trestle/core/commands/split.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
|
split_model(model_obj, element_paths, base_dir, content_type, root_file_name, aliases_to_strip)
classmethod
¤
Split the model at the provided element paths.
It returns a plan for the operation
Source code in trestle/core/commands/split.py
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 |
|
split_model_at_path_chain(model_obj, element_paths, base_dir, content_type, cur_path_index, split_plan, strip_root, root_file_name, aliases_to_strip, last_one=True)
classmethod
¤
Recursively split the model at the provided chain of element paths.
It assumes that a chain of element paths starts at the cur_path_index with the first path ending with a wildcard (*)
If the wildcard follows an element that is inherently a list of items, the list of items is extracted. But if the wildcard follows a generic model than members of that model class found in the model will be split off. But only the non-trivial elements are removed, i.e. not str, int, datetime, etc.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_obj | OscalBaseModel | The OscalBaseModel to be split | required |
element_paths | List[ElementPath] | The List[ElementPath] of elements to split, including embedded wildcards | required |
base_dir | Path | pathlib.Path of the file being split | required |
content_type | FileContentType | json or yaml files | required |
cur_path_index | int | Index into the list of element paths for the current split operation | required |
split_plan | Plan | The accumulated plan of actions needed to perform the split | required |
strip_root | bool | Whether to strip elements from the root object | required |
root_file_name | str | Filename of root file that gets split into a list of items | required |
aliases_to_strip | Dict[str, AliasTracker] | AliasTracker previously loaded with aliases that need to be split from each element | required |
last_one | bool | bool indicating last item in array has been split and stripped model can now be written | True |
Returns:
Type | Description |
---|---|
int | int representing the index where the chain of the path ends. |
Examples:
For example, element paths could have a list of paths as below for a ComponentDefinition
model where the first path is the start of the chain.
For each of the sub model described by the first element path (e.g component-defintion.components.) in the chain, the subsequent paths (e.g component.control-implementations.) will be applied recursively to retrieve the sub-sub models: [ 'component-definition.component.', 'component.control-implementations.' ] for a command like below: trestle split -f component.yaml -e component-definition.components..control-implementations.
Source code in trestle/core/commands/split.py
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 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 |
|
Functions¤
handler: python