Skip to content

leveraged_statements

trestle.core.crm.leveraged_statements ¤

Handle writing of inherited statements to markdown.

Attributes¤

component_mapping_default: List[Dict[str, str]] = [{'name': const.REPLACE_ME}] module-attribute ¤

logger = logging.getLogger(__name__) module-attribute ¤

Classes¤

InheritanceInfo dataclass ¤

Class to capture component inheritance information.

Source code in trestle/core/crm/leveraged_statements.py
208
209
210
211
212
213
214
@dataclass
class InheritanceInfo:
    """Class to capture component inheritance information."""

    leveraging_comp_titles: List[str]
    inherited: Optional[ssp.Inherited]
    satisfied: Optional[ssp.Satisfied]
Attributes¤
inherited: Optional[ssp.Inherited] instance-attribute ¤
leveraging_comp_titles: List[str] instance-attribute ¤
satisfied: Optional[ssp.Satisfied] instance-attribute ¤
Functions¤
__init__(leveraging_comp_titles, inherited, satisfied) ¤

InheritanceMarkdownReader ¤

Class to read leveraged statement information from Markdown.

Source code in trestle/core/crm/leveraged_statements.py
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
class InheritanceMarkdownReader:
    """Class to read leveraged statement information from Markdown."""

    def __init__(self, leveraged_statement_file: pathlib.Path) -> None:
        """Initialize the class."""
        # Save the file name for logging
        self._leveraged_statement_file = leveraged_statement_file

        md_api: MarkdownAPI = MarkdownAPI()

        yaml_header, inheritance_md = md_api.processor.process_markdown(leveraged_statement_file)
        self._yaml_header: Dict[str, Any] = yaml_header
        self._inheritance_md: DocsMarkdownNode = inheritance_md

    def process_leveraged_statement_markdown(self) -> Optional[InheritanceInfo]:
        """
        Read inheritance information from Markdown.

        Returns:
            Optional InheritanceInfo - A list of mapped component titles, an optional satisfied statement and an
            optional inherited statement

        Notes:
            Returns inheritance information in the context of the leveraging SSP. If no leveraging component titles are
            mapped in the yaml header None will be returned. The satisfied and inherited fields are
            generated and returned to added information to by-component assemblies for
            the mapped leveraging components.

        """
        leveraging_comps: List[str] = []
        inherited_statement: Optional[ssp.Inherited] = None
        satisfied_statement: Optional[ssp.Satisfied] = None

        leveraging_comp_header_value: List[Dict[str, str]] = self._yaml_header[const.TRESTLE_LEVERAGING_COMP_TAG]

        # If there are no mapped components, return early
        if not leveraging_comp_header_value or leveraging_comp_header_value == component_mapping_default:
            return None
        else:
            for comp_dicts in leveraging_comp_header_value:
                for comp_title in comp_dicts.values():
                    leveraging_comps.append(comp_title)

        statement_info: Dict[str, str] = self._yaml_header[const.TRESTLE_STATEMENT_TAG]

        if const.PROVIDED_UUID in statement_info:
            # Set inherited

            provided_description = self.get_provided_description()
            if provided_description is None:
                raise TrestleError(f'Provided statement cannot be empty in {self._leveraged_statement_file}')

            inherited_statement = gens.generate_sample_model(ssp.Inherited)

            inherited_statement.description = provided_description
            inherited_statement.provided_uuid = statement_info[const.PROVIDED_UUID]

        if const.RESPONSIBILITY_UUID in statement_info:
            # Set satisfied
            satisfied_description = self.get_satisfied_description()
            if satisfied_description is None:
                raise TrestleError(f'Satisfied statement cannot be empty in {self._leveraged_statement_file}')

            satisfied_statement = gens.generate_sample_model(ssp.Satisfied)

            satisfied_statement.description = satisfied_description
            satisfied_statement.responsibility_uuid = statement_info[const.RESPONSIBILITY_UUID]

        return InheritanceInfo(leveraging_comps, inherited_statement, satisfied_statement)

    def get_leveraged_ssp_reference(self) -> str:
        """Return the leveraged SSP reference in the yaml header."""
        return self._yaml_header[const.TRESTLE_GLOBAL_TAG][const.LEVERAGED_SSP][const.HREF]

    def get_satisfied_description(self) -> Optional[str]:
        """Return the satisfied description in the Markdown."""
        node = self._inheritance_md.get_node_for_key(const.SATISFIED_STATEMENT_DESCRIPTION, False)
        if node is not None:
            return self.strip_heading_and_comments(node.content.raw_text)
        else:
            return None

    def get_provided_description(self) -> Optional[str]:
        """Return the provided description in the Markdown."""
        node = self._inheritance_md.get_node_for_key(const.PROVIDED_STATEMENT_DESCRIPTION, False)
        if node is not None:
            return self.strip_heading_and_comments(node.content.raw_text)
        else:
            return None

    def get_leveraged_component_header_value(self) -> Dict[str, str]:
        """Provide the leveraged component value in the yaml header."""
        return self._yaml_header[const.TRESTLE_LEVERAGING_COMP_TAG]

    @staticmethod
    def strip_heading_and_comments(markdown_text: str) -> str:
        """Remove the heading and comments from lines to get the multi-line paragraph."""
        lines = markdown_text.split('\n')
        non_heading_comment_lines = []
        inside_heading = False
        inside_comment = False

        for line in lines:
            if line.startswith('#'):
                inside_heading = True
            elif line.startswith('<!--'):
                inside_comment = True
                if line.rstrip().endswith('-->'):
                    inside_comment = False
                continue
            elif line.strip() == '':
                inside_heading = False
                inside_comment = False

            if not inside_heading and not inside_comment:
                non_heading_comment_lines.append(line)

        stripped_markdown = '\n'.join(non_heading_comment_lines).strip()
        return stripped_markdown
Functions¤
__init__(leveraged_statement_file) ¤

Initialize the class.

Source code in trestle/core/crm/leveraged_statements.py
220
221
222
223
224
225
226
227
228
229
def __init__(self, leveraged_statement_file: pathlib.Path) -> None:
    """Initialize the class."""
    # Save the file name for logging
    self._leveraged_statement_file = leveraged_statement_file

    md_api: MarkdownAPI = MarkdownAPI()

    yaml_header, inheritance_md = md_api.processor.process_markdown(leveraged_statement_file)
    self._yaml_header: Dict[str, Any] = yaml_header
    self._inheritance_md: DocsMarkdownNode = inheritance_md
get_leveraged_component_header_value() ¤

Provide the leveraged component value in the yaml header.

Source code in trestle/core/crm/leveraged_statements.py
307
308
309
def get_leveraged_component_header_value(self) -> Dict[str, str]:
    """Provide the leveraged component value in the yaml header."""
    return self._yaml_header[const.TRESTLE_LEVERAGING_COMP_TAG]
get_leveraged_ssp_reference() ¤

Return the leveraged SSP reference in the yaml header.

Source code in trestle/core/crm/leveraged_statements.py
287
288
289
def get_leveraged_ssp_reference(self) -> str:
    """Return the leveraged SSP reference in the yaml header."""
    return self._yaml_header[const.TRESTLE_GLOBAL_TAG][const.LEVERAGED_SSP][const.HREF]
get_provided_description() ¤

Return the provided description in the Markdown.

Source code in trestle/core/crm/leveraged_statements.py
299
300
301
302
303
304
305
def get_provided_description(self) -> Optional[str]:
    """Return the provided description in the Markdown."""
    node = self._inheritance_md.get_node_for_key(const.PROVIDED_STATEMENT_DESCRIPTION, False)
    if node is not None:
        return self.strip_heading_and_comments(node.content.raw_text)
    else:
        return None
get_satisfied_description() ¤

Return the satisfied description in the Markdown.

Source code in trestle/core/crm/leveraged_statements.py
291
292
293
294
295
296
297
def get_satisfied_description(self) -> Optional[str]:
    """Return the satisfied description in the Markdown."""
    node = self._inheritance_md.get_node_for_key(const.SATISFIED_STATEMENT_DESCRIPTION, False)
    if node is not None:
        return self.strip_heading_and_comments(node.content.raw_text)
    else:
        return None
process_leveraged_statement_markdown() ¤

Read inheritance information from Markdown.

Returns:

Type Description
Optional[InheritanceInfo]

Optional InheritanceInfo - A list of mapped component titles, an optional satisfied statement and an

Optional[InheritanceInfo]

optional inherited statement

Notes

Returns inheritance information in the context of the leveraging SSP. If no leveraging component titles are mapped in the yaml header None will be returned. The satisfied and inherited fields are generated and returned to added information to by-component assemblies for the mapped leveraging components.

Source code in trestle/core/crm/leveraged_statements.py
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
def process_leveraged_statement_markdown(self) -> Optional[InheritanceInfo]:
    """
    Read inheritance information from Markdown.

    Returns:
        Optional InheritanceInfo - A list of mapped component titles, an optional satisfied statement and an
        optional inherited statement

    Notes:
        Returns inheritance information in the context of the leveraging SSP. If no leveraging component titles are
        mapped in the yaml header None will be returned. The satisfied and inherited fields are
        generated and returned to added information to by-component assemblies for
        the mapped leveraging components.

    """
    leveraging_comps: List[str] = []
    inherited_statement: Optional[ssp.Inherited] = None
    satisfied_statement: Optional[ssp.Satisfied] = None

    leveraging_comp_header_value: List[Dict[str, str]] = self._yaml_header[const.TRESTLE_LEVERAGING_COMP_TAG]

    # If there are no mapped components, return early
    if not leveraging_comp_header_value or leveraging_comp_header_value == component_mapping_default:
        return None
    else:
        for comp_dicts in leveraging_comp_header_value:
            for comp_title in comp_dicts.values():
                leveraging_comps.append(comp_title)

    statement_info: Dict[str, str] = self._yaml_header[const.TRESTLE_STATEMENT_TAG]

    if const.PROVIDED_UUID in statement_info:
        # Set inherited

        provided_description = self.get_provided_description()
        if provided_description is None:
            raise TrestleError(f'Provided statement cannot be empty in {self._leveraged_statement_file}')

        inherited_statement = gens.generate_sample_model(ssp.Inherited)

        inherited_statement.description = provided_description
        inherited_statement.provided_uuid = statement_info[const.PROVIDED_UUID]

    if const.RESPONSIBILITY_UUID in statement_info:
        # Set satisfied
        satisfied_description = self.get_satisfied_description()
        if satisfied_description is None:
            raise TrestleError(f'Satisfied statement cannot be empty in {self._leveraged_statement_file}')

        satisfied_statement = gens.generate_sample_model(ssp.Satisfied)

        satisfied_statement.description = satisfied_description
        satisfied_statement.responsibility_uuid = statement_info[const.RESPONSIBILITY_UUID]

    return InheritanceInfo(leveraging_comps, inherited_statement, satisfied_statement)
strip_heading_and_comments(markdown_text) staticmethod ¤

Remove the heading and comments from lines to get the multi-line paragraph.

Source code in trestle/core/crm/leveraged_statements.py
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
@staticmethod
def strip_heading_and_comments(markdown_text: str) -> str:
    """Remove the heading and comments from lines to get the multi-line paragraph."""
    lines = markdown_text.split('\n')
    non_heading_comment_lines = []
    inside_heading = False
    inside_comment = False

    for line in lines:
        if line.startswith('#'):
            inside_heading = True
        elif line.startswith('<!--'):
            inside_comment = True
            if line.rstrip().endswith('-->'):
                inside_comment = False
            continue
        elif line.strip() == '':
            inside_heading = False
            inside_comment = False

        if not inside_heading and not inside_comment:
            non_heading_comment_lines.append(line)

    stripped_markdown = '\n'.join(non_heading_comment_lines).strip()
    return stripped_markdown

LeveragedStatements ¤

Bases: ABC

Abstract class for managing leveraged statements.

Source code in trestle/core/crm/leveraged_statements.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
class LeveragedStatements(ABC):
    """Abstract class for managing leveraged statements."""

    def __init__(self, leveraged_ssp_reference: str) -> None:
        """Initialize the class."""
        self._md_file: Optional[MDWriter] = None
        self.header_comment_dict: Dict[str, str] = {
            const.TRESTLE_LEVERAGING_COMP_TAG: const.YAML_LEVERAGING_COMP_COMMENT,
            const.TRESTLE_STATEMENT_TAG: const.YAML_LEVERAGED_COMMENT
        }
        self.merged_header_dict: Dict[str, Any] = {
            const.TRESTLE_STATEMENT_TAG: '',
            const.TRESTLE_LEVERAGING_COMP_TAG: component_mapping_default,
            const.TRESTLE_GLOBAL_TAG: {
                const.LEVERAGED_SSP: {
                    const.HREF: leveraged_ssp_reference
                }
            }
        }

    @abstractmethod
    def write_statement_md(self, leveraged_statement_file: pathlib.Path) -> None:
        """Write inheritance information to a single markdown file."""
Attributes¤
header_comment_dict: Dict[str, str] = {const.TRESTLE_LEVERAGING_COMP_TAG: const.YAML_LEVERAGING_COMP_COMMENT, const.TRESTLE_STATEMENT_TAG: const.YAML_LEVERAGED_COMMENT} instance-attribute ¤
merged_header_dict: Dict[str, Any] = {const.TRESTLE_STATEMENT_TAG: '', const.TRESTLE_LEVERAGING_COMP_TAG: component_mapping_default, const.TRESTLE_GLOBAL_TAG: {const.LEVERAGED_SSP: {const.HREF: leveraged_ssp_reference}}} instance-attribute ¤
Functions¤
__init__(leveraged_ssp_reference) ¤

Initialize the class.

Source code in trestle/core/crm/leveraged_statements.py
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
def __init__(self, leveraged_ssp_reference: str) -> None:
    """Initialize the class."""
    self._md_file: Optional[MDWriter] = None
    self.header_comment_dict: Dict[str, str] = {
        const.TRESTLE_LEVERAGING_COMP_TAG: const.YAML_LEVERAGING_COMP_COMMENT,
        const.TRESTLE_STATEMENT_TAG: const.YAML_LEVERAGED_COMMENT
    }
    self.merged_header_dict: Dict[str, Any] = {
        const.TRESTLE_STATEMENT_TAG: '',
        const.TRESTLE_LEVERAGING_COMP_TAG: component_mapping_default,
        const.TRESTLE_GLOBAL_TAG: {
            const.LEVERAGED_SSP: {
                const.HREF: leveraged_ssp_reference
            }
        }
    }
write_statement_md(leveraged_statement_file) abstractmethod ¤

Write inheritance information to a single markdown file.

Source code in trestle/core/crm/leveraged_statements.py
54
55
56
@abstractmethod
def write_statement_md(self, leveraged_statement_file: pathlib.Path) -> None:
    """Write inheritance information to a single markdown file."""

StatementProvided ¤

Bases: LeveragedStatements

Concrete class for managing provided statements.

Source code in trestle/core/crm/leveraged_statements.py
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
class StatementProvided(LeveragedStatements):
    """Concrete class for managing provided statements."""

    def __init__(
        self,
        provided_uuid: str,
        provided_description: str,
        leveraged_ssp_reference: str,
    ) -> None:
        """Initialize the class."""
        self.provided_uuid = provided_uuid
        self.provided_description = provided_description
        super().__init__(leveraged_ssp_reference)

    def write_statement_md(self, leveraged_statement_file: pathlib.Path) -> None:
        """Write provided statements to a markdown file."""
        self._md_file = MDWriter(leveraged_statement_file, self.header_comment_dict)

        if self._md_file.exists():
            return self.update_statement_md(leveraged_statement_file)

        self._add_generated_content()
        self._md_file.write_out()

    def update_statement_md(self, leveraged_statement_file: pathlib.Path) -> None:
        """Update provided statements in a markdown file."""
        md_reader = InheritanceMarkdownReader(leveraged_statement_file)

        self.merged_header_dict[const.TRESTLE_LEVERAGING_COMP_TAG] = md_reader.get_leveraged_component_header_value()

        self._add_generated_content()
        self._md_file.write_out()

    def _add_generated_content(self) -> None:
        self.merged_header_dict[const.TRESTLE_STATEMENT_TAG] = {const.PROVIDED_UUID: self.provided_uuid}
        self._md_file.add_yaml_header(self.merged_header_dict)

        self._md_file.new_header(level=1, title=const.PROVIDED_STATEMENT_DESCRIPTION)
        self._md_file.new_line(self.provided_description)
Attributes¤
provided_description = provided_description instance-attribute ¤
provided_uuid = provided_uuid instance-attribute ¤
Functions¤
__init__(provided_uuid, provided_description, leveraged_ssp_reference) ¤

Initialize the class.

Source code in trestle/core/crm/leveraged_statements.py
121
122
123
124
125
126
127
128
129
130
def __init__(
    self,
    provided_uuid: str,
    provided_description: str,
    leveraged_ssp_reference: str,
) -> None:
    """Initialize the class."""
    self.provided_uuid = provided_uuid
    self.provided_description = provided_description
    super().__init__(leveraged_ssp_reference)
update_statement_md(leveraged_statement_file) ¤

Update provided statements in a markdown file.

Source code in trestle/core/crm/leveraged_statements.py
142
143
144
145
146
147
148
149
def update_statement_md(self, leveraged_statement_file: pathlib.Path) -> None:
    """Update provided statements in a markdown file."""
    md_reader = InheritanceMarkdownReader(leveraged_statement_file)

    self.merged_header_dict[const.TRESTLE_LEVERAGING_COMP_TAG] = md_reader.get_leveraged_component_header_value()

    self._add_generated_content()
    self._md_file.write_out()
write_statement_md(leveraged_statement_file) ¤

Write provided statements to a markdown file.

Source code in trestle/core/crm/leveraged_statements.py
132
133
134
135
136
137
138
139
140
def write_statement_md(self, leveraged_statement_file: pathlib.Path) -> None:
    """Write provided statements to a markdown file."""
    self._md_file = MDWriter(leveraged_statement_file, self.header_comment_dict)

    if self._md_file.exists():
        return self.update_statement_md(leveraged_statement_file)

    self._add_generated_content()
    self._md_file.write_out()

StatementResponsibility ¤

Bases: LeveragedStatements

Concrete class for managing responsibility statements.

Source code in trestle/core/crm/leveraged_statements.py
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
class StatementResponsibility(LeveragedStatements):
    """Concrete class for managing responsibility statements."""

    def __init__(
        self,
        responsibility_uuid: str,
        responsibility_description: str,
        leveraged_ssp_reference: str,
    ) -> None:
        """Initialize the class."""
        self.responsibility_uuid = responsibility_uuid
        self.responsibility_description = responsibility_description
        self.satisfied_description = ''
        super().__init__(leveraged_ssp_reference)

    def write_statement_md(self, leveraged_statement_file: pathlib.Path) -> None:
        """Write responsibility statements to a markdown file."""
        self._md_file = MDWriter(leveraged_statement_file, self.header_comment_dict)

        if self._md_file.exists():
            return self.update_statement_md(leveraged_statement_file)

        self._add_generated_content()
        self._md_file.write_out()

    def update_statement_md(self, leveraged_statement_file: pathlib.Path) -> None:
        """Update responsibility statements in a markdown file."""
        md_reader = InheritanceMarkdownReader(leveraged_statement_file)

        self.merged_header_dict[const.TRESTLE_LEVERAGING_COMP_TAG] = md_reader.get_leveraged_component_header_value()

        satisfied_description = md_reader.get_satisfied_description()
        if satisfied_description is not None:
            self.satisfied_description = satisfied_description

        self._add_generated_content()
        self._md_file.write_out()

    def _add_generated_content(self) -> None:
        self.merged_header_dict[const.TRESTLE_STATEMENT_TAG] = {const.RESPONSIBILITY_UUID: self.responsibility_uuid}
        self._md_file.add_yaml_header(self.merged_header_dict)

        self._md_file.new_header(level=1, title=const.RESPONSIBILITY_STATEMENT_DESCRIPTION)
        self._md_file.new_line(self.responsibility_description)
        self._md_file.new_header(level=1, title=const.SATISFIED_STATEMENT_DESCRIPTION)
        self._md_file.new_line(const.SATISFIED_STATEMENT_COMMENT)
        self._md_file.new_line(self.satisfied_description)
Attributes¤
responsibility_description = responsibility_description instance-attribute ¤
responsibility_uuid = responsibility_uuid instance-attribute ¤
satisfied_description = '' instance-attribute ¤
Functions¤
__init__(responsibility_uuid, responsibility_description, leveraged_ssp_reference) ¤

Initialize the class.

Source code in trestle/core/crm/leveraged_statements.py
162
163
164
165
166
167
168
169
170
171
172
def __init__(
    self,
    responsibility_uuid: str,
    responsibility_description: str,
    leveraged_ssp_reference: str,
) -> None:
    """Initialize the class."""
    self.responsibility_uuid = responsibility_uuid
    self.responsibility_description = responsibility_description
    self.satisfied_description = ''
    super().__init__(leveraged_ssp_reference)
update_statement_md(leveraged_statement_file) ¤

Update responsibility statements in a markdown file.

Source code in trestle/core/crm/leveraged_statements.py
184
185
186
187
188
189
190
191
192
193
194
195
def update_statement_md(self, leveraged_statement_file: pathlib.Path) -> None:
    """Update responsibility statements in a markdown file."""
    md_reader = InheritanceMarkdownReader(leveraged_statement_file)

    self.merged_header_dict[const.TRESTLE_LEVERAGING_COMP_TAG] = md_reader.get_leveraged_component_header_value()

    satisfied_description = md_reader.get_satisfied_description()
    if satisfied_description is not None:
        self.satisfied_description = satisfied_description

    self._add_generated_content()
    self._md_file.write_out()
write_statement_md(leveraged_statement_file) ¤

Write responsibility statements to a markdown file.

Source code in trestle/core/crm/leveraged_statements.py
174
175
176
177
178
179
180
181
182
def write_statement_md(self, leveraged_statement_file: pathlib.Path) -> None:
    """Write responsibility statements to a markdown file."""
    self._md_file = MDWriter(leveraged_statement_file, self.header_comment_dict)

    if self._md_file.exists():
        return self.update_statement_md(leveraged_statement_file)

    self._add_generated_content()
    self._md_file.write_out()

StatementTree ¤

Bases: LeveragedStatements

Concrete class for managing provided and responsibility statements.

Source code in trestle/core/crm/leveraged_statements.py
 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
class StatementTree(LeveragedStatements):
    """Concrete class for managing provided and responsibility statements."""

    def __init__(
        self,
        provided_uuid: str,
        provided_description: str,
        responsibility_uuid: str,
        responsibility_description: str,
        leveraged_ssp_reference: str
    ) -> None:
        """Initialize the class."""
        self.provided_uuid = provided_uuid
        self.provided_description = provided_description
        self.responsibility_uuid = responsibility_uuid
        self.responsibility_description = responsibility_description
        self.satisfied_description = ''
        super().__init__(leveraged_ssp_reference)

    def write_statement_md(self, leveraged_statement_file: pathlib.Path) -> None:
        """Write a provided and responsibility statements to a markdown file."""
        self._md_file = MDWriter(leveraged_statement_file, self.header_comment_dict)

        if self._md_file.exists():
            return self.update_statement_md(leveraged_statement_file)

        self._add_generated_content()
        self._md_file.write_out()

    def update_statement_md(self, leveraged_statement_file: pathlib.Path) -> None:
        """Update provided and responsibility statements in a markdown file."""
        md_reader = InheritanceMarkdownReader(leveraged_statement_file)

        self.merged_header_dict[const.TRESTLE_LEVERAGING_COMP_TAG] = md_reader.get_leveraged_component_header_value()

        satisfied_description = md_reader.get_satisfied_description()
        if satisfied_description is not None:
            self.satisfied_description = satisfied_description

        self._add_generated_content()
        self._md_file.write_out()

    def _add_generated_content(self) -> None:
        statement_dict: Dict[str, str] = {
            const.PROVIDED_UUID: self.provided_uuid, const.RESPONSIBILITY_UUID: self.responsibility_uuid
        }

        self.merged_header_dict[const.TRESTLE_STATEMENT_TAG] = statement_dict
        self._md_file.add_yaml_header(self.merged_header_dict)

        self._md_file.new_header(level=1, title=const.PROVIDED_STATEMENT_DESCRIPTION)
        self._md_file.new_line(self.provided_description)
        self._md_file.new_header(level=1, title=const.RESPONSIBILITY_STATEMENT_DESCRIPTION)
        self._md_file.new_line(self.responsibility_description)
        self._md_file.new_header(level=1, title=const.SATISFIED_STATEMENT_DESCRIPTION)
        self._md_file.new_line(const.SATISFIED_STATEMENT_COMMENT)
        self._md_file.new_line(self.satisfied_description)
Attributes¤
provided_description = provided_description instance-attribute ¤
provided_uuid = provided_uuid instance-attribute ¤
responsibility_description = responsibility_description instance-attribute ¤
responsibility_uuid = responsibility_uuid instance-attribute ¤
satisfied_description = '' instance-attribute ¤
Functions¤
__init__(provided_uuid, provided_description, responsibility_uuid, responsibility_description, leveraged_ssp_reference) ¤

Initialize the class.

Source code in trestle/core/crm/leveraged_statements.py
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
def __init__(
    self,
    provided_uuid: str,
    provided_description: str,
    responsibility_uuid: str,
    responsibility_description: str,
    leveraged_ssp_reference: str
) -> None:
    """Initialize the class."""
    self.provided_uuid = provided_uuid
    self.provided_description = provided_description
    self.responsibility_uuid = responsibility_uuid
    self.responsibility_description = responsibility_description
    self.satisfied_description = ''
    super().__init__(leveraged_ssp_reference)
update_statement_md(leveraged_statement_file) ¤

Update provided and responsibility statements in a markdown file.

Source code in trestle/core/crm/leveraged_statements.py
88
89
90
91
92
93
94
95
96
97
98
99
def update_statement_md(self, leveraged_statement_file: pathlib.Path) -> None:
    """Update provided and responsibility statements in a markdown file."""
    md_reader = InheritanceMarkdownReader(leveraged_statement_file)

    self.merged_header_dict[const.TRESTLE_LEVERAGING_COMP_TAG] = md_reader.get_leveraged_component_header_value()

    satisfied_description = md_reader.get_satisfied_description()
    if satisfied_description is not None:
        self.satisfied_description = satisfied_description

    self._add_generated_content()
    self._md_file.write_out()
write_statement_md(leveraged_statement_file) ¤

Write a provided and responsibility statements to a markdown file.

Source code in trestle/core/crm/leveraged_statements.py
78
79
80
81
82
83
84
85
86
def write_statement_md(self, leveraged_statement_file: pathlib.Path) -> None:
    """Write a provided and responsibility statements to a markdown file."""
    self._md_file = MDWriter(leveraged_statement_file, self.header_comment_dict)

    if self._md_file.exists():
        return self.update_statement_md(leveraged_statement_file)

    self._add_generated_content()
    self._md_file.write_out()

handler: python