Path:
strictdoc/core/document_meta.py
Lines:
194
Non-empty lines:
173
Non-empty lines covered with requirements:
173 / 173 (100.0%)
Functions:
14
Functions covered by requirements:
14 / 14 (100.0%)
1
"""2
Class container that stores document meta information.3
4
Example explaining metadata stored by this class:.5
6
DocumentMeta(7
level = 1,8
file_tree_mount_folder = "doc_project",9
document_filename = "sample.sdoc",10
document_filename_base = "sample",11
input_doc_full_path = "/tmp/doc_project/child.sdoc",12
input_doc_rel_path = "child.sdoc",13
input_doc_dir_rel_path = "",14
input_doc_assets_dir_rel_path = "doc_project/_assets",15
output_document_dir_full_path = "/tmp/doc_project/output/html/doc_project",16
output_document_dir_rel_path = "doc_project"17
)18
19
@relation(SDOC-SRS-48, scope=file)20
"""21
22
import os
23
from typing import Optional
24
25
from strictdoc.export.html.document_type import DocumentType
26
from strictdoc.helpers.auto_described import auto_described
27
from strictdoc.helpers.paths import SDocRelativePath
28
29
30
@auto_described31
class DocumentMeta:
32
def __init__(
33
self,
34
level: int,
35
file_tree_mount_folder: str,
36
document_filename: str,
37
document_filename_base: str,
38
input_doc_full_path: str,
39
input_doc_rel_path: SDocRelativePath,
40
input_doc_dir_rel_path: SDocRelativePath,
41
input_doc_assets_dir_rel_path: SDocRelativePath,
42
output_document_dir_full_path: str,
43
output_document_dir_rel_path: SDocRelativePath,
44
) -> None:
45
assert isinstance(input_doc_rel_path, SDocRelativePath), (
46
input_doc_rel_path47
)48
assert isinstance(input_doc_dir_rel_path, SDocRelativePath), (
49
input_doc_dir_rel_path50
)51
assert isinstance(input_doc_assets_dir_rel_path, SDocRelativePath), (
52
input_doc_assets_dir_rel_path53
)54
assert isinstance(output_document_dir_rel_path, SDocRelativePath), (
55
output_document_dir_rel_path56
)57
58
self.level: int = level
59
self.file_tree_mount_folder = file_tree_mount_folder
60
self.document_filename: str = document_filename
61
self.document_filename_base: str = document_filename_base
62
self.input_doc_full_path: str = input_doc_full_path
63
self.input_doc_rel_path: SDocRelativePath = input_doc_rel_path
64
self.input_doc_dir_rel_path: SDocRelativePath = input_doc_dir_rel_path
65
self.input_doc_assets_dir_rel_path: SDocRelativePath = (
66
input_doc_assets_dir_rel_path67
)68
self.output_document_dir_full_path: str = output_document_dir_full_path
69
self.output_document_dir_rel_path: SDocRelativePath = (
70
output_document_dir_rel_path71
)72
self.output_document_full_path: str = os.path.join(
73
self.output_document_dir_full_path,
74
self.get_html_doc_path(),
75
)76
77
def get_html_doc_path(self) -> str:
78
return (
79
f"{self.output_document_dir_full_path}"
80
f"/"
81
f"{self.document_filename_base}.html"
82
)83
84
def get_html_table_path(self) -> str:
85
return (
86
f"{self.output_document_dir_full_path}"
87
f"/"
88
f"{self.document_filename_base}-TABLE.html"
89
)90
91
def get_html_traceability_path(self) -> str:
92
return (
93
f"{self.output_document_dir_full_path}"
94
f"/"
95
f"{self.document_filename_base}-TRACE.html"
96
)97
98
def get_html_deep_traceability_path(self) -> str:
99
return (
100
f"{self.output_document_dir_full_path}"
101
f"/"
102
f"{self.document_filename_base}-DEEP-TRACE.html"
103
)104
105
def get_html_pdf_path(self) -> str:
106
return (
107
f"{self.output_document_dir_full_path}"
108
f"/"
109
f"{self.document_filename_base}-PDF.html"
110
)111
112
# Links113
def get_html_doc_link(self) -> str:
114
file_name_part = f"{self.document_filename_base}.html"
115
if len(self.output_document_dir_rel_path.relative_path_posix) == 0:
116
return file_name_part
117
return (
118
f"{self.output_document_dir_rel_path.relative_path_posix}"
119
"/"120
f"{file_name_part}"
121
)122
123
def get_html_table_link(self) -> str:
124
file_name_part = f"{self.document_filename_base}-TABLE.html"
125
if len(self.output_document_dir_rel_path.relative_path_posix) == 0:
126
return file_name_part
127
return (
128
f"{self.output_document_dir_rel_path.relative_path_posix}"
129
"/"130
f"{file_name_part}"
131
)132
133
def get_html_traceability_link(self) -> str:
134
file_name_part = f"{self.document_filename_base}-TRACE.html"
135
if len(self.output_document_dir_rel_path.relative_path_posix) == 0:
136
return file_name_part
137
return (
138
f"{self.output_document_dir_rel_path.relative_path_posix}"
139
"/"140
f"{file_name_part}"
141
)142
143
def get_html_deep_traceability_link(self) -> str:
144
file_name_part = f"{self.document_filename_base}-DEEP-TRACE.html"
145
if len(self.output_document_dir_rel_path.relative_path_posix) == 0:
146
return file_name_part
147
return (
148
f"{self.output_document_dir_rel_path.relative_path_posix}"
149
"/"150
f"{file_name_part}"
151
)152
153
def get_html_pdf_link(self) -> str:
154
file_name_part = f"{self.document_filename_base}-PDF.html"
155
if len(self.output_document_dir_rel_path.relative_path_posix) == 0:
156
return file_name_part
157
return (
158
f"{self.output_document_dir_rel_path.relative_path_posix}"
159
"/"160
f"{file_name_part}"
161
)162
163
def get_html_link(
164
self,
165
document_type: DocumentType,
166
other_doc_level: Optional[int],
167
) -> str:
168
assert isinstance(document_type, DocumentType)
169
170
path_prefix: str = self.get_root_path_prefix(other_doc_level)
171
if document_type == DocumentType.DOCUMENT:
172
document_link = self.get_html_doc_link()
173
elif document_type == DocumentType.TABLE:
174
document_link = self.get_html_table_link()
175
elif document_type == DocumentType.TRACE:
176
document_link = self.get_html_traceability_link()
177
elif document_type == DocumentType.DEEPTRACE:
178
document_link = self.get_html_deep_traceability_link()
179
elif document_type == DocumentType.PDF:
180
document_link = self.get_html_pdf_link()
181
else:
182
raise NotImplementedError
183
# We reach here the document is a bundle document.184
if len(path_prefix) == 0:
185
return document_link
186
return f"{path_prefix}/{document_link}"
187
188
def get_root_path_prefix(
189
self, other_doc_level: Optional[int] = None
190
) -> str:
191
level: int = self.level if not other_doc_level else other_doc_level
192
if level == 0:
193
return ""
194
return ("../" * level)[:-1]