do not replace existing doc "index" file

Reviewed-by: gtema <artem.goncharov@gmail.com>
Co-authored-by: Goncharov, Artem <artem.goncharov@t-systems.com>
Co-committed-by: Goncharov, Artem <artem.goncharov@t-systems.com>
This commit is contained in:
Goncharov, Artem 2022-07-28 14:30:40 +00:00 committed by zuul
parent 1bec551697
commit 66988fd5d1

View File

@ -447,29 +447,42 @@ class OTCDocConvertor:
title = curr['title']
page_label = curr['uri'].replace(".html", "").lower()
path = self.get_target_path(curr['code'], metadata_by_code)
with open(pathlib.Path(dest, path, "index.rst"), "w") as index:
if page_label:
index.write(f".. _{page_label}:\n\n")
index.write('=' * (len(title)) + '\n')
index.write(title + '\n')
index.write('=' * (len(title)) + '\n')
index.write('\n')
index.write('.. toctree::\n')
index.write(' :maxdepth: 1\n\n')
for child in v:
new_name = child['new_name']
if child['code'] in tree:
# If this is folder - add /index
new_name = new_name + '/index'
index.write(f" {new_name}\n")
p = pathlib.Path(dest, f"{path}.rst")
if p.exists():
logging.warning(
f"{p.resolve()} is removed in favour"
f" of result/{path}/index.rst")
p.unlink()
f"{p.resolve()} is renamed into {path}/index.rst"
)
# Update existing index file
p.rename(pathlib.Path(dest, f"{path}/index.rst"))
with open(pathlib.Path(dest, path, "index.rst"), "a") as index:
index.write('\n')
index.write('.. toctree::\n')
index.write(' :maxdepth: 1\n')
index.write(' :hidden: \n\n')
for child in v:
new_name = child['new_name']
if child['code'] in tree:
# If this is folder - add /index
new_name = new_name + '/index'
index.write(f" {new_name}\n")
else:
with open(pathlib.Path(dest, path, "index.rst"), "w") as index:
# New index file
if page_label:
index.write(f".. _{page_label}:\n\n")
index.write('=' * (len(title)) + '\n')
index.write(title + '\n')
index.write('=' * (len(title)) + '\n')
index.write('\n')
index.write('.. toctree::\n')
index.write(' :maxdepth: 1\n\n')
for child in v:
new_name = child['new_name']
if child['code'] in tree:
# If this is folder - add /index
new_name = new_name + '/index'
index.write(f" {new_name}\n")
# Copy used images
if len(self.doc_images) > 0:
logging.debug("Processing images...")