Skip to content

Commit

Permalink
Merge pull request strictdoc-project#1501 from strictdoc-project/stan…
Browse files Browse the repository at this point in the history
…islaw/improve_document_meta

 document_meta: also store input doc relative path and the doc file name
  • Loading branch information
stanislaw authored Dec 10, 2023
2 parents 9068087 + 22b4ba2 commit 0364a81
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 9 deletions.
2 changes: 1 addition & 1 deletion strictdoc/core/actions/passthrough_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def passthrough(project_config: ProjectConfig):
output = writer.write(document)

path_to_output_file_dir = os.path.join(
output_dir, document.meta.input_doc_rel_path
output_dir, document.meta.input_doc_dir_rel_path
)
Path(path_to_output_file_dir).mkdir(parents=True, exist_ok=True)
path_to_output_file = os.path.join(
Expand Down
10 changes: 6 additions & 4 deletions strictdoc/core/document_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from strictdoc.core.document_meta import DocumentMeta
from strictdoc.core.document_tree import DocumentTree
from strictdoc.core.file_tree import (
File,
FileFinder,
FileTree,
PathFinder,
Expand Down Expand Up @@ -84,20 +85,20 @@ def _build_document_tree(
map_docs_by_paths[input_doc_full_path] = document
document_list.append(document)

doc_file: File
for _, doc_file, file_tree_mount_folder in file_tree_list:
input_doc_full_path = doc_file.get_full_path()
document = map_docs_by_paths[input_doc_full_path]
assert isinstance(document, Document)

doc_relative_path_folder = os.path.dirname(doc_file.rel_path)

output_document_dir_rel_path = (
f"{file_tree_mount_folder}/{doc_relative_path_folder}"
os.path.join(file_tree_mount_folder, doc_relative_path_folder)
if doc_relative_path_folder
else file_tree_mount_folder
)

document_filename = os.path.basename(input_doc_full_path)
document_filename = doc_file.file_name
document_filename_base = os.path.splitext(document_filename)[0]

output_document_dir_full_path = (
Expand All @@ -107,13 +108,14 @@ def _build_document_tree(
document_meta = DocumentMeta(
doc_file.level,
file_tree_mount_folder,
document_filename,
document_filename_base,
input_doc_full_path,
doc_file.rel_path,
doc_relative_path_folder,
output_document_dir_full_path,
output_document_dir_rel_path,
)

document.assign_meta(document_meta)

output_document_rel_path = os.path.join(
Expand Down
21 changes: 20 additions & 1 deletion strictdoc/core/document_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,36 @@ def __init__(
self,
level,
file_tree_mount_folder,
document_filename: str,
document_filename_base,
input_doc_full_path,
input_doc_rel_path: str,
input_doc_dir_rel_path,
output_document_dir_full_path,
output_document_dir_rel_path,
):
"""
Example explaining meta data stored by this class:
DocumentMeta(
level = 1,
file_tree_mount_folder = "doc_project",
document_filename = "sample.sdoc",
document_filename_base = "sample",
input_doc_full_path = "/tmp/doc_project/child.sdoc",
input_doc_rel_path = "child.sdoc",
input_doc_dir_rel_path = "",
output_document_dir_full_path = "/tmp/doc_project/output/html/doc_project",
output_document_dir_rel_path = "doc_project"
)
"""
self.level = level
self.file_tree_mount_folder = file_tree_mount_folder
self.document_filename: str = document_filename
self.document_filename_base = document_filename_base
self.input_doc_full_path = input_doc_full_path
self.input_doc_rel_path = input_doc_dir_rel_path
self.input_doc_rel_path: str = input_doc_rel_path
self.input_doc_dir_rel_path = input_doc_dir_rel_path
self.output_document_dir_full_path = output_document_dir_full_path
self.output_document_dir_rel_path = output_document_dir_rel_path

Expand Down
2 changes: 1 addition & 1 deletion strictdoc/export/rst/document_rst_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def export_tree(traceability_index: TraceabilityIndex, output_rst_root):
)

output_folder = os.path.join(
output_rst_root, document.meta.input_doc_rel_path
output_rst_root, document.meta.input_doc_dir_rel_path
)
Path(output_folder).mkdir(parents=True, exist_ok=True)

Expand Down
12 changes: 10 additions & 2 deletions strictdoc/server/routers/main_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -1669,6 +1669,8 @@ def document_tree__create_document(
full_input_path = os.path.abspath(project_config.export_input_paths[0])
doc_full_path = os.path.join(full_input_path, document_path)
doc_full_path_dir = os.path.dirname(doc_full_path)
document_file_name = os.path.basename(doc_full_path)
input_doc_dir_rel_path = os.path.dirname(document_path)

Path(doc_full_path_dir).mkdir(parents=True, exist_ok=True)
document = Document(
Expand All @@ -1679,12 +1681,15 @@ def document_tree__create_document(
free_texts=[],
section_contents=[],
)
# FIXME: Fill in the document meta correctly.
document.meta = DocumentMeta(
level=0,
file_tree_mount_folder=None,
document_filename=document_file_name,
document_filename_base=None,
input_doc_full_path=doc_full_path,
input_doc_dir_rel_path=document_path,
input_doc_rel_path=document_path,
input_doc_dir_rel_path=input_doc_dir_rel_path,
output_document_dir_full_path=None,
output_document_dir_rel_path=None,
)
Expand Down Expand Up @@ -2270,12 +2275,15 @@ async def import_document_reqif(reqif_file: UploadFile):
doc_full_path_dir = os.path.dirname(doc_full_path)
Path(doc_full_path_dir).mkdir(parents=True, exist_ok=True)

# FIXME: Fill in the meta information correctly.
document.meta = DocumentMeta(
level=0,
file_tree_mount_folder=None,
document_filename=document_path,
document_filename_base=None,
input_doc_full_path=doc_full_path,
input_doc_dir_rel_path=document_path,
input_doc_rel_path=document_path,
input_doc_dir_rel_path=os.path.dirname(document_path),
output_document_dir_full_path=None,
output_document_dir_rel_path=None,
)
Expand Down

0 comments on commit 0364a81

Please sign in to comment.