Path:
strictdoc/core/document_meta.py
Lines:
195
Non-empty lines:
174
Non-empty lines covered with requirements:
174 / 174 (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
*,
35
level: int,
36
file_tree_mount_folder: str,
37
document_filename: str,
38
document_filename_base: str,
39
input_doc_full_path: str,
40
input_doc_rel_path: SDocRelativePath,
41
input_doc_dir_rel_path: SDocRelativePath,
42
input_doc_assets_dir_rel_path: SDocRelativePath,
43
output_document_dir_full_path: str,
44
output_document_dir_rel_path: SDocRelativePath,
45
) -> None:
46
assert isinstance(input_doc_rel_path, SDocRelativePath), (
47
input_doc_rel_path48
)49
assert isinstance(input_doc_dir_rel_path, SDocRelativePath), (
50
input_doc_dir_rel_path51
)52
assert isinstance(input_doc_assets_dir_rel_path, SDocRelativePath), (
53
input_doc_assets_dir_rel_path54
)55
assert isinstance(output_document_dir_rel_path, SDocRelativePath), (
56
output_document_dir_rel_path57
)58
59
self.level: int = level
60
self.file_tree_mount_folder = file_tree_mount_folder
61
self.document_filename: str = document_filename
62
self.document_filename_base: str = document_filename_base
63
self.input_doc_full_path: str = input_doc_full_path
64
self.input_doc_rel_path: SDocRelativePath = input_doc_rel_path
65
self.input_doc_dir_rel_path: SDocRelativePath = input_doc_dir_rel_path
66
self.input_doc_assets_dir_rel_path: SDocRelativePath = (
67
input_doc_assets_dir_rel_path68
)69
self.output_document_dir_full_path: str = output_document_dir_full_path
70
self.output_document_dir_rel_path: SDocRelativePath = (
71
output_document_dir_rel_path72
)73
self.output_document_full_path: str = os.path.join(
74
self.output_document_dir_full_path,
75
self.get_html_doc_path(),
76
)77
78
def get_html_doc_path(self) -> str:
79
return (
80
f"{self.output_document_dir_full_path}"
81
f"/"
82
f"{self.document_filename_base}.html"
83
)84
85
def get_html_table_path(self) -> str:
86
return (
87
f"{self.output_document_dir_full_path}"
88
f"/"
89
f"{self.document_filename_base}-TABLE.html"
90
)91
92
def get_html_traceability_path(self) -> str:
93
return (
94
f"{self.output_document_dir_full_path}"
95
f"/"
96
f"{self.document_filename_base}-TRACE.html"
97
)98
99
def get_html_deep_traceability_path(self) -> str:
100
return (
101
f"{self.output_document_dir_full_path}"
102
f"/"
103
f"{self.document_filename_base}-DEEP-TRACE.html"
104
)105
106
def get_html_pdf_path(self) -> str:
107
return (
108
f"{self.output_document_dir_full_path}"
109
f"/"
110
f"{self.document_filename_base}-PDF.html"
111
)112
113
# Links114
def get_html_doc_link(self) -> str:
115
file_name_part = f"{self.document_filename_base}.html"
116
if len(self.output_document_dir_rel_path.relative_path_posix) == 0:
117
return file_name_part
118
return (
119
f"{self.output_document_dir_rel_path.relative_path_posix}"
120
"/"121
f"{file_name_part}"
122
)123
124
def get_html_table_link(self) -> str:
125
file_name_part = f"{self.document_filename_base}-TABLE.html"
126
if len(self.output_document_dir_rel_path.relative_path_posix) == 0:
127
return file_name_part
128
return (
129
f"{self.output_document_dir_rel_path.relative_path_posix}"
130
"/"131
f"{file_name_part}"
132
)133
134
def get_html_traceability_link(self) -> str:
135
file_name_part = f"{self.document_filename_base}-TRACE.html"
136
if len(self.output_document_dir_rel_path.relative_path_posix) == 0:
137
return file_name_part
138
return (
139
f"{self.output_document_dir_rel_path.relative_path_posix}"
140
"/"141
f"{file_name_part}"
142
)143
144
def get_html_deep_traceability_link(self) -> str:
145
file_name_part = f"{self.document_filename_base}-DEEP-TRACE.html"
146
if len(self.output_document_dir_rel_path.relative_path_posix) == 0:
147
return file_name_part
148
return (
149
f"{self.output_document_dir_rel_path.relative_path_posix}"
150
"/"151
f"{file_name_part}"
152
)153
154
def get_html_pdf_link(self) -> str:
155
file_name_part = f"{self.document_filename_base}-PDF.html"
156
if len(self.output_document_dir_rel_path.relative_path_posix) == 0:
157
return file_name_part
158
return (
159
f"{self.output_document_dir_rel_path.relative_path_posix}"
160
"/"161
f"{file_name_part}"
162
)163
164
def get_html_link(
165
self,
166
document_type: DocumentType,
167
other_doc_level: Optional[int],
168
) -> str:
169
assert isinstance(document_type, DocumentType)
170
171
path_prefix: str = self.get_root_path_prefix(other_doc_level)
172
if document_type == DocumentType.DOCUMENT:
173
document_link = self.get_html_doc_link()
174
elif document_type == DocumentType.TABLE:
175
document_link = self.get_html_table_link()
176
elif document_type == DocumentType.TRACE:
177
document_link = self.get_html_traceability_link()
178
elif document_type == DocumentType.DEEPTRACE:
179
document_link = self.get_html_deep_traceability_link()
180
elif document_type == DocumentType.PDF:
181
document_link = self.get_html_pdf_link()
182
else:
183
raise NotImplementedError
184
# We reach here the document is a bundle document.185
if len(path_prefix) == 0:
186
return document_link
187
return f"{path_prefix}/{document_link}"
188
189
def get_root_path_prefix(
190
self, other_doc_level: Optional[int] = None
191
) -> str:
192
level: int = self.level if not other_doc_level else other_doc_level
193
if level == 0:
194
return ""
195
return ("../" * level)[:-1]