Path:
strictdoc/backend/reqif/reqif_export.py
Lines:
55
Non-empty lines:
48
Non-empty lines covered with requirements:
48 / 48 (100.0%)
Functions:
2
Functions covered by requirements:
2 / 2 (100.0%)
1
"""2
@relation(SDOC-SRS-72, scope=file)3
"""4
5
import os
6
from pathlib import Path
7
8
from reqif.reqif_bundle import ReqIFZBundle
9
from reqif.unparser import ReqIFUnparser, ReqIFZUnparser
10
11
from strictdoc.backend.reqif.p01_sdoc.sdoc_to_reqif_converter import (
12
P01_SDocToReqIFObjectConverter,
13
)14
from strictdoc.backend.reqif.sdoc_reqif_fields import ReqIFProfile
15
from strictdoc.core.project_config import ProjectConfig
16
from strictdoc.core.traceability_index import TraceabilityIndex
17
18
19
class ReqIFExport:
20
@staticmethod21
def export(
22
project_config: ProjectConfig,
23
traceability_index: TraceabilityIndex,
24
output_reqif_root: str,
25
reqifz: bool,
26
) -> None:
27
Path(output_reqif_root).mkdir(parents=True, exist_ok=True)
28
29
if project_config.reqif_profile == ReqIFProfile.P01_SDOC:
30
reqif_bundle = P01_SDocToReqIFObjectConverter.convert_document_tree(
31
document_tree=traceability_index.document_tree,
32
multiline_is_xhtml=project_config.reqif_multiline_is_xhtml,
33
enable_mid=project_config.reqif_enable_mid,
34
)35
else:
36
raise NotImplementedError(
37
f"Requirements profile does not implement the ReqIF export yet: "
38
f"{project_config.reqif_profile}."
39
)40
41
output_file_path: str
42
if not reqifz:
43
output_file_path = os.path.join(output_reqif_root, "output.reqif")
44
reqif_content: str = ReqIFUnparser.unparse(reqif_bundle)
45
with open(output_file_path, "w", encoding="utf8") as output_file:
46
output_file.write(reqif_content)
47
else:
48
output_file_path = os.path.join(output_reqif_root, "output.reqifz")
49
reqifz_bundle = ReqIFZBundle(
50
reqif_bundles={"document_tree.reqif": reqif_bundle},
51
attachments={},
52
)53
reqifz_content_bytes = ReqIFZUnparser.unparse(reqifz_bundle)
54
with open(output_file_path, "wb") as output_file:
55
output_file.write(reqifz_content_bytes)