From 6fa5c76e94fbcc4b4b053b35ab00dd8508b7eb37 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Tue, 18 Apr 2023 11:41:06 +0000 Subject: [PATCH] Added check for index.rst --- tools/generate_doc_confpy.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/tools/generate_doc_confpy.py b/tools/generate_doc_confpy.py index 3f1d7aac..0856a74f 100644 --- a/tools/generate_doc_confpy.py +++ b/tools/generate_doc_confpy.py @@ -159,6 +159,7 @@ def process_repositories(args, service): repo_to.index.add([doc["rst_location"]]) if args.update_sbv: + copy_path = pathlib.Path(copy_to, 'doc', 'source') context = dict( repo_name=target_repo["repo"], project=service["service_title"], @@ -166,7 +167,6 @@ def process_repositories(args, service): title=f"{service['service_title']} - Service Based View", service_type=service["service_type"] ) - copy_path = pathlib.Path(copy_to, 'doc', 'source') if not copy_path.exists(): logging.info("Path for sbv does not exist") copy_path.mkdir(parents=True, exist_ok=True) @@ -190,13 +190,18 @@ def process_repositories(args, service): "w", encoding="utf-8") as out: out.write(conf_py_content) - 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, "conf.py")) - repo_to.index.add(pathlib.Path(copy_path, "index.rst")) + + 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")) + if args.update_tox: context = dict(docs=[]) @@ -313,6 +318,11 @@ def main(): 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" + ) args = parser.parse_args() logging.basicConfig(level=logging.DEBUG)