forked from infra/otc-metadata
New template and options for Service-Based-View
Reviewed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com> Co-authored-by: Gode, Sebastian <sebastian.gode@t-systems.com> Co-committed-by: Gode, Sebastian <sebastian.gode@t-systems.com>
This commit is contained in:
parent
6c27e42e4b
commit
b711305a4c
@ -18,7 +18,10 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
extensions = [
|
extensions = [
|
||||||
'otcdocstheme'
|
'otcdocstheme',
|
||||||
|
{%- if otc_sbv %}
|
||||||
|
'otc_sphinx_directives'
|
||||||
|
{%- endif %}
|
||||||
]
|
]
|
||||||
|
|
||||||
otcdocs_auto_name = False
|
otcdocs_auto_name = False
|
||||||
|
@ -2,3 +2,6 @@ sphinx>=2.0.0,!=2.1.0 # BSD
|
|||||||
otcdocstheme # Apache-2.0
|
otcdocstheme # Apache-2.0
|
||||||
# releasenotes
|
# releasenotes
|
||||||
reno>=3.1.0 # Apache-2.0
|
reno>=3.1.0 # Apache-2.0
|
||||||
|
|
||||||
|
otc-sphinx-directives>=0.1.0
|
||||||
|
git+https://gitea.eco.tsi-dev.otc-service.com/infra/otc-metadata.git#egg=otc_metadata
|
7
otc_metadata/templates/index_sbv.rst.j2
Normal file
7
otc_metadata/templates/index_sbv.rst.j2
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{{ sbv_title }}
|
||||||
|
|
||||||
|
.. directive_wrapper::
|
||||||
|
:class: container-sbv
|
||||||
|
|
||||||
|
.. service_card::
|
||||||
|
:service_type: {{ service_type }}
|
@ -29,7 +29,11 @@ allowlist_externals =
|
|||||||
mkdir
|
mkdir
|
||||||
cp
|
cp
|
||||||
sh
|
sh
|
||||||
|
rm
|
||||||
|
sphinx-build
|
||||||
commands =
|
commands =
|
||||||
|
rm -rf doc/build/html doc/build/doctrees
|
||||||
|
sphinx-build -a -E -W -d doc/build/doctrees -b html doc/source doc/build/html
|
||||||
{%- for doc in docs %}
|
{%- for doc in docs %}
|
||||||
{[testenv:{{ doc.type }}]commands}
|
{[testenv:{{ doc.type }}]commands}
|
||||||
{[testenv:json-{{ doc.type }}]commands}
|
{[testenv:json-{{ doc.type }}]commands}
|
||||||
@ -115,3 +119,7 @@ commands =
|
|||||||
cp {{ loc }}/build/pdf/{{ doc.pdf_name }}.pdf doc/build/pdf/
|
cp {{ loc }}/build/pdf/{{ doc.pdf_name }}.pdf doc/build/pdf/
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
[doc8]
|
||||||
|
ignore = D001
|
||||||
|
extensions = .rst, .yaml
|
@ -50,6 +50,7 @@ def process_repositories(args, service):
|
|||||||
)
|
)
|
||||||
conf_py_template = env.get_template("conf.py.j2")
|
conf_py_template = env.get_template("conf.py.j2")
|
||||||
tox_ini_template = env.get_template("tox.ini.j2")
|
tox_ini_template = env.get_template("tox.ini.j2")
|
||||||
|
index_sbv_template = env.get_template("index_sbv.rst.j2")
|
||||||
doc_requirements_template = env.get_template("doc_requirements.txt.j2")
|
doc_requirements_template = env.get_template("doc_requirements.txt.j2")
|
||||||
|
|
||||||
for repo in service["repositories"]:
|
for repo in service["repositories"]:
|
||||||
@ -155,7 +156,62 @@ def process_repositories(args, service):
|
|||||||
out.write(conf_py_content)
|
out.write(conf_py_content)
|
||||||
|
|
||||||
repo_to.index.add([doc["rst_location"]])
|
repo_to.index.add([doc["rst_location"]])
|
||||||
|
|
||||||
|
if args.update_sbv:
|
||||||
|
"""Add or update service-based-view"""
|
||||||
|
copy_path = pathlib.Path(copy_to, 'doc', 'source')
|
||||||
|
context = dict(
|
||||||
|
repo_name=target_repo["repo"],
|
||||||
|
project=service["service_title"],
|
||||||
|
# pdf_name=doc["pdf_name"],
|
||||||
|
title=f"{service['service_title']} - Service Based View",
|
||||||
|
service_type=service["service_type"]
|
||||||
|
)
|
||||||
|
if not copy_path.exists():
|
||||||
|
logging.info("Path for sbv does not exist")
|
||||||
|
copy_path.mkdir(parents=True, exist_ok=True)
|
||||||
|
context["otc_sbv"] = True
|
||||||
|
if git_fqdn:
|
||||||
|
context["git_fqdn"] = git_fqdn
|
||||||
|
if target_repo.get("type") != "github":
|
||||||
|
context["git_type"] = target_repo["type"]
|
||||||
|
if args.target_environment == "internal":
|
||||||
|
context["html_options"] = dict(
|
||||||
|
disable_search=True,
|
||||||
|
site_name="Internal Documentation Portal",
|
||||||
|
logo_url="https://docs-int.otc-service.com",
|
||||||
|
)
|
||||||
|
sbv_title = (service["service_title"] + "\n"
|
||||||
|
+ ('=' * len(service["service_title"])))
|
||||||
|
context["sbv_title"] = sbv_title
|
||||||
|
conf_py_content = conf_py_template.render(**context)
|
||||||
|
index_sbv_content = index_sbv_template.render(**context)
|
||||||
|
with open(
|
||||||
|
pathlib.Path(copy_path, "conf.py"),
|
||||||
|
"w",
|
||||||
|
encoding="utf-8") as out:
|
||||||
|
out.write(conf_py_content)
|
||||||
|
repo_to.index.add(pathlib.Path(copy_path, "conf.py"))
|
||||||
|
|
||||||
|
if (not args.overwrite_index_sbv
|
||||||
|
and pathlib.Path(copy_path, "index.rst").exists()):
|
||||||
|
logging.info("File index.rst for sbv exists. Skipping")
|
||||||
|
else:
|
||||||
|
with open(
|
||||||
|
pathlib.Path(copy_path, "index.rst"),
|
||||||
|
"w",
|
||||||
|
encoding="utf-8") as out:
|
||||||
|
out.write(index_sbv_content)
|
||||||
|
repo_to.index.add(pathlib.Path(copy_path, "index.rst"))
|
||||||
|
|
||||||
|
placeholder_path = pathlib.Path(copy_path, "_static")
|
||||||
|
if not pathlib.Path(placeholder_path, "placeholder").exists():
|
||||||
|
placeholder_path.mkdir(parents=True, exist_ok=True)
|
||||||
|
open(pathlib.Path(placeholder_path, "placeholder"), 'a').close()
|
||||||
|
repo_to.index.add(pathlib.Path(placeholder_path, "placeholder"))
|
||||||
|
|
||||||
if args.update_tox:
|
if args.update_tox:
|
||||||
|
"""Update tox.ini"""
|
||||||
context = dict(docs=[])
|
context = dict(docs=[])
|
||||||
for doc in service_docs:
|
for doc in service_docs:
|
||||||
if doc["type"] == "dev":
|
if doc["type"] == "dev":
|
||||||
@ -265,10 +321,27 @@ def main():
|
|||||||
)
|
)
|
||||||
parser.add_argument("--token", metavar="token", help="API token")
|
parser.add_argument("--token", metavar="token", help="API token")
|
||||||
parser.add_argument("--api-url", help="API base url of the Git hoster")
|
parser.add_argument("--api-url", help="API base url of the Git hoster")
|
||||||
|
parser.add_argument(
|
||||||
|
"--update-sbv",
|
||||||
|
action="store_true",
|
||||||
|
help="Whether to update service-based-view"
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--overwrite-index-sbv",
|
||||||
|
action="store_true",
|
||||||
|
help=("Whether to overwrite index.rst for service-based-view."
|
||||||
|
+ "\nCan only be used if --update-sbv is also specified")
|
||||||
|
)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
services = []
|
services = []
|
||||||
|
if args.overwrite_index_sbv and not args.update_sbv:
|
||||||
|
logging.error(
|
||||||
|
"Cannot overwrite index.rst for service-based-view"
|
||||||
|
+ " without updating service-based-view"
|
||||||
|
)
|
||||||
|
exit(1)
|
||||||
if args.service_type:
|
if args.service_type:
|
||||||
services = [data.service_dict.get(args.service_type)]
|
services = [data.service_dict.get(args.service_type)]
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user