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:
		@ -50,6 +50,7 @@ def process_repositories(args, service):
 | 
			
		||||
    )
 | 
			
		||||
    conf_py_template = env.get_template("conf.py.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")
 | 
			
		||||
 | 
			
		||||
    for repo in service["repositories"]:
 | 
			
		||||
@ -155,7 +156,62 @@ def process_repositories(args, service):
 | 
			
		||||
            out.write(conf_py_content)
 | 
			
		||||
 | 
			
		||||
        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:
 | 
			
		||||
        """Update tox.ini"""
 | 
			
		||||
        context = dict(docs=[])
 | 
			
		||||
        for doc in service_docs:
 | 
			
		||||
            if doc["type"] == "dev":
 | 
			
		||||
@ -265,10 +321,27 @@ def main():
 | 
			
		||||
    )
 | 
			
		||||
    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(
 | 
			
		||||
        "--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()
 | 
			
		||||
    logging.basicConfig(level=logging.DEBUG)
 | 
			
		||||
    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:
 | 
			
		||||
        services = [data.service_dict.get(args.service_type)]
 | 
			
		||||
    else:
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user