cmd_utils
trestle.core.commands.common.cmd_utils
¤
Trestle command related utilities.
Classes¤
Functions¤
clear_folder(folder_path)
¤
Clear all contents of the specified folder.
Source code in trestle/core/commands/common/cmd_utils.py
41 42 43 44 45 46 47 48 |
|
model_type_is_too_granular(model_type)
¤
Is an model_type too fine to split.
Source code in trestle/core/commands/common/cmd_utils.py
30 31 32 33 34 35 36 37 38 |
|
parse_chain(model_obj, path_parts, relative_path=None)
¤
Parse the model chain starting from the beginning.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_obj
|
Union[OscalBaseModel, None]
|
Model to use for inspecting available elements, if available or none |
required |
path_parts
|
List[str]
|
list of string paths to parse including wildcards |
required |
relative_path
|
Optional[Path]
|
Optional relative path (w.r.t trestle workspace root directory) |
None
|
Returns:
Type | Description |
---|---|
List[ElementPath]
|
List of ElementPath |
Source code in trestle/core/commands/common/cmd_utils.py
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 |
|
parse_element_arg(model_obj, element_arg, relative_path=None)
¤
Parse an element arg string into a list of ElementPath.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_obj
|
Union[OscalBaseModel, None]
|
The OscalBaseModel being inspected to determine available elements that can be split |
required |
element_arg
|
str
|
Single element path, as a string. |
required |
relative_path
|
Optional[Path]
|
Optional relative path (from trestle root) used to validate element args are valid. |
None
|
Returns: The requested parsed list of ElementPath for use in split
Source code in trestle/core/commands/common/cmd_utils.py
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 |
|
parse_element_args(model, element_args, relative_path=None)
¤
Parse element args into a list of ElementPath.
The element paths are either simple links of two elements, or two elements followed by *. The * represents either a list of the items in that element, or a splitting of that element into its parts. The only parts split off are the non-trivial ones determined by the granularity check.
contextual_mode specifies if the path is a valid project model path or not. For example, if we are processing a metadata.parties.*, we need to know which metadata we are processing. If we pass contextual_mode=true, we can infer the root model by inspecting the file directory
If contextual_mode=False, then the path must include the full path, e.g. catalog.metadata.parties. instead of just metadata.parties.
When the * represents splitting a model rather than a list, the model is inspected for what parts are available, and for each new part two element paths are created, one for the parent to the current element, and another from the current element to the child.
A path may have multiple *'s, but only the final one can represent splitting a model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
Union[OscalBaseModel, None]
|
The OscalBaseModel being inspected to determine available elements that can be split |
required |
element_args
|
List[str]
|
List of str representing links in the chain of element paths to be parsed |
required |
relative_path
|
Optional[Path]
|
Optional relative path (from trestle root) used to validate element args are valid. |
None
|
Returns: The requested parsed list of ElementPath for use in split
Source code in trestle/core/commands/common/cmd_utils.py
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 |
|
split_is_too_fine(split_paths, model_obj)
¤
Determine if the element path list goes too fine, e.g. individual strings.
Source code in trestle/core/commands/common/cmd_utils.py
51 52 53 54 55 56 57 58 |
|
to_model_file_name(model_obj, file_prefix, content_type)
¤
Return the file name for the item.
Source code in trestle/core/commands/common/cmd_utils.py
232 233 234 235 236 237 |
|
handler: python