Skip to content

control_context

trestle.core.control_context ¤

Provide a context for control operations.

Attributes¤

Classes¤

ContextPurpose ¤

Bases: Enum

Specify the modality of the control markdown.

Source code in trestle/core/control_context.py
29
30
31
32
33
34
35
class ContextPurpose(Enum):
    """Specify the modality of the control markdown."""

    CATALOG = 0
    COMPONENT = 1
    PROFILE = 2
    SSP = 3
Attributes¤
CATALOG = 0 class-attribute instance-attribute ¤
COMPONENT = 1 class-attribute instance-attribute ¤
PROFILE = 2 class-attribute instance-attribute ¤
SSP = 3 class-attribute instance-attribute ¤

ControlContext dataclass ¤

Class encapsulating control markdown usage.

Source code in trestle/core/control_context.py
 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
@dataclass
class ControlContext:
    """Class encapsulating control markdown usage."""

    purpose: ContextPurpose
    to_markdown: bool
    trestle_root: pathlib.Path
    md_root: pathlib.Path
    prompt_responses: bool
    include_all_parts: bool
    overwrite_header_values: bool
    set_parameters_flag: bool
    cli_yaml_header: Optional[Dict[Any, Any]] = None
    sections_dict: Optional[Dict[str, str]] = None
    profile: Optional[prof.Profile] = None
    required_sections: Optional[List[str]] = None
    allowed_sections: Optional[List[str]] = None
    comp_def: Optional[comp.ComponentDefinition] = None
    comp_name: Optional[str] = None
    component: Optional[comp.DefinedComponent] = None
    comp_def_name_list: Optional[List[str]] = None
    inherited_props: Optional[Dict[str, Any]] = None
    rules_dict: Optional[Dict[str, Dict[str, Any]]] = None
    rules_params_dict: Optional[Dict[str, Dict[str, Any]]] = None
    control_implementation: Optional[comp.ControlImplementation] = None
    uri_name_map: Optional[Dict[str, str]] = None
    comp_dict: Optional[CompDict] = None
    merged_header: Optional[Dict[str, Any]] = None

    @classmethod
    def generate(
        cls,
        purpose: ContextPurpose,
        to_markdown: bool,
        trestle_root: pathlib.Path,
        md_root: pathlib.Path,
        prompt_responses: bool = False,
        include_all_parts: bool = False,
        overwrite_header_values: bool = False,
        set_parameters_flag: bool = False,
        cli_yaml_header: Optional[Dict[Any, Any]] = None,
        sections_dict: Optional[Dict[str, str]] = None,
        profile: Optional[prof.Profile] = None,
        required_sections: Optional[List[str]] = None,
        allowed_sections: Optional[List[str]] = None,
        comp_def: Optional[comp.ComponentDefinition] = None,
        comp_name: Optional[str] = None,
        component: Optional[comp.DefinedComponent] = None,
        comp_def_name_list: Optional[List[str]] = None,
        inherited_props: Optional[Dict[str, Any]] = None,
        rules_dict: Optional[Dict[str, Dict[str, Any]]] = None,
        rules_params_dict: Optional[Dict[str, Dict[str, Any]]] = None,
        control_implementation: Optional[comp.ControlImplementation] = None,
        uri_name_map: Optional[Dict[str, str]] = None,
        comp_dict: Optional[CompDict] = None,
        merged_header: Optional[Dict[str, Any]] = None
    ) -> ControlContext:
        """Generate control context of the needed type."""
        context = cls(
            purpose,
            to_markdown,
            trestle_root,
            md_root,
            prompt_responses,
            include_all_parts,
            overwrite_header_values,
            set_parameters_flag,
            cli_yaml_header=cli_yaml_header,
            sections_dict=sections_dict,
            profile=profile,
            required_sections=required_sections,
            allowed_sections=allowed_sections,
            comp_def=comp_def,
            comp_name=comp_name,
            component=component,
            comp_def_name_list=comp_def_name_list,
            inherited_props=inherited_props,
            rules_dict=rules_dict,
            rules_params_dict=rules_params_dict,
            control_implementation=control_implementation,
            uri_name_map=uri_name_map,
            comp_dict=comp_dict
        )
        context.cli_yaml_header = as_dict(cli_yaml_header)
        context.sections_dict = as_dict(sections_dict)
        context.merged_header = as_dict(merged_header)
        # catalog generate always sets params
        if to_markdown:
            context.set_parameters = True
        return context

    @classmethod
    def clone(cls, context: ControlContext) -> ControlContext:
        """Create a deep clone of the context without duplicating large objects."""
        new_context = cls(
            context.purpose,
            context.to_markdown,
            context.trestle_root,
            context.md_root,
            context.prompt_responses,
            context.include_all_parts,
            context.overwrite_header_values,
            context.set_parameters_flag,
            cli_yaml_header=copy.deepcopy(context.cli_yaml_header),
            sections_dict=copy.deepcopy(context.sections_dict),
            profile=context.profile,
            required_sections=context.required_sections,
            allowed_sections=context.allowed_sections,
            comp_def=context.comp_def,
            comp_name=context.comp_name,
            component=context.component,
            comp_def_name_list=context.comp_def_name_list,
            inherited_props=copy.deepcopy(context.inherited_props),
            rules_dict=copy.deepcopy(context.rules_dict),
            rules_params_dict=copy.deepcopy(context.rules_params_dict),
            control_implementation=copy.deepcopy(context.control_implementation),
            uri_name_map=context.uri_name_map,
            comp_dict=copy.deepcopy(context.comp_dict),
            merged_header=copy.deepcopy(context.merged_header)
        )
        return new_context
Attributes¤
allowed_sections: Optional[List[str]] = None class-attribute instance-attribute ¤
cli_yaml_header: Optional[Dict[Any, Any]] = None class-attribute instance-attribute ¤
comp_def: Optional[comp.ComponentDefinition] = None class-attribute instance-attribute ¤
comp_def_name_list: Optional[List[str]] = None class-attribute instance-attribute ¤
comp_dict: Optional[CompDict] = None class-attribute instance-attribute ¤
comp_name: Optional[str] = None class-attribute instance-attribute ¤
component: Optional[comp.DefinedComponent] = None class-attribute instance-attribute ¤
control_implementation: Optional[comp.ControlImplementation] = None class-attribute instance-attribute ¤
include_all_parts: bool instance-attribute ¤
inherited_props: Optional[Dict[str, Any]] = None class-attribute instance-attribute ¤
md_root: pathlib.Path instance-attribute ¤
merged_header: Optional[Dict[str, Any]] = None class-attribute instance-attribute ¤
overwrite_header_values: bool instance-attribute ¤
profile: Optional[prof.Profile] = None class-attribute instance-attribute ¤
prompt_responses: bool instance-attribute ¤
purpose: ContextPurpose instance-attribute ¤
required_sections: Optional[List[str]] = None class-attribute instance-attribute ¤
rules_dict: Optional[Dict[str, Dict[str, Any]]] = None class-attribute instance-attribute ¤
rules_params_dict: Optional[Dict[str, Dict[str, Any]]] = None class-attribute instance-attribute ¤
sections_dict: Optional[Dict[str, str]] = None class-attribute instance-attribute ¤
set_parameters_flag: bool instance-attribute ¤
to_markdown: bool instance-attribute ¤
trestle_root: pathlib.Path instance-attribute ¤
uri_name_map: Optional[Dict[str, str]] = None class-attribute instance-attribute ¤
Functions¤
__init__(purpose, to_markdown, trestle_root, md_root, prompt_responses, include_all_parts, overwrite_header_values, set_parameters_flag, cli_yaml_header=None, sections_dict=None, profile=None, required_sections=None, allowed_sections=None, comp_def=None, comp_name=None, component=None, comp_def_name_list=None, inherited_props=None, rules_dict=None, rules_params_dict=None, control_implementation=None, uri_name_map=None, comp_dict=None, merged_header=None) ¤
clone(context) classmethod ¤

Create a deep clone of the context without duplicating large objects.

Source code in trestle/core/control_context.py
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
@classmethod
def clone(cls, context: ControlContext) -> ControlContext:
    """Create a deep clone of the context without duplicating large objects."""
    new_context = cls(
        context.purpose,
        context.to_markdown,
        context.trestle_root,
        context.md_root,
        context.prompt_responses,
        context.include_all_parts,
        context.overwrite_header_values,
        context.set_parameters_flag,
        cli_yaml_header=copy.deepcopy(context.cli_yaml_header),
        sections_dict=copy.deepcopy(context.sections_dict),
        profile=context.profile,
        required_sections=context.required_sections,
        allowed_sections=context.allowed_sections,
        comp_def=context.comp_def,
        comp_name=context.comp_name,
        component=context.component,
        comp_def_name_list=context.comp_def_name_list,
        inherited_props=copy.deepcopy(context.inherited_props),
        rules_dict=copy.deepcopy(context.rules_dict),
        rules_params_dict=copy.deepcopy(context.rules_params_dict),
        control_implementation=copy.deepcopy(context.control_implementation),
        uri_name_map=context.uri_name_map,
        comp_dict=copy.deepcopy(context.comp_dict),
        merged_header=copy.deepcopy(context.merged_header)
    )
    return new_context
generate(purpose, to_markdown, trestle_root, md_root, prompt_responses=False, include_all_parts=False, overwrite_header_values=False, set_parameters_flag=False, cli_yaml_header=None, sections_dict=None, profile=None, required_sections=None, allowed_sections=None, comp_def=None, comp_name=None, component=None, comp_def_name_list=None, inherited_props=None, rules_dict=None, rules_params_dict=None, control_implementation=None, uri_name_map=None, comp_dict=None, merged_header=None) classmethod ¤

Generate control context of the needed type.

Source code in trestle/core/control_context.py
 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
@classmethod
def generate(
    cls,
    purpose: ContextPurpose,
    to_markdown: bool,
    trestle_root: pathlib.Path,
    md_root: pathlib.Path,
    prompt_responses: bool = False,
    include_all_parts: bool = False,
    overwrite_header_values: bool = False,
    set_parameters_flag: bool = False,
    cli_yaml_header: Optional[Dict[Any, Any]] = None,
    sections_dict: Optional[Dict[str, str]] = None,
    profile: Optional[prof.Profile] = None,
    required_sections: Optional[List[str]] = None,
    allowed_sections: Optional[List[str]] = None,
    comp_def: Optional[comp.ComponentDefinition] = None,
    comp_name: Optional[str] = None,
    component: Optional[comp.DefinedComponent] = None,
    comp_def_name_list: Optional[List[str]] = None,
    inherited_props: Optional[Dict[str, Any]] = None,
    rules_dict: Optional[Dict[str, Dict[str, Any]]] = None,
    rules_params_dict: Optional[Dict[str, Dict[str, Any]]] = None,
    control_implementation: Optional[comp.ControlImplementation] = None,
    uri_name_map: Optional[Dict[str, str]] = None,
    comp_dict: Optional[CompDict] = None,
    merged_header: Optional[Dict[str, Any]] = None
) -> ControlContext:
    """Generate control context of the needed type."""
    context = cls(
        purpose,
        to_markdown,
        trestle_root,
        md_root,
        prompt_responses,
        include_all_parts,
        overwrite_header_values,
        set_parameters_flag,
        cli_yaml_header=cli_yaml_header,
        sections_dict=sections_dict,
        profile=profile,
        required_sections=required_sections,
        allowed_sections=allowed_sections,
        comp_def=comp_def,
        comp_name=comp_name,
        component=component,
        comp_def_name_list=comp_def_name_list,
        inherited_props=inherited_props,
        rules_dict=rules_dict,
        rules_params_dict=rules_params_dict,
        control_implementation=control_implementation,
        uri_name_map=uri_name_map,
        comp_dict=comp_dict
    )
    context.cli_yaml_header = as_dict(cli_yaml_header)
    context.sections_dict = as_dict(sections_dict)
    context.merged_header = as_dict(merged_header)
    # catalog generate always sets params
    if to_markdown:
        context.set_parameters = True
    return context

Functions¤

handler: python