More scripts

This commit is contained in:
Gode, Sebastian 2025-04-16 08:42:23 +00:00
parent 8edc99df52
commit 7f1b8f4d56
3 changed files with 56 additions and 15 deletions

View File

@ -141,7 +141,7 @@ class Services(object):
res[cat]["docs"].append(res_doc)
return res
def service_types_with_doc_types(self, environment=None):
def service_types_with_doc_types(self, cloud_environment, environment=None):
"""Retrieve type and title from services and corresponding docs.
As well as a list of all available doc types with title.
@ -154,6 +154,13 @@ class Services(object):
if "environment" in service:
if service["environment"] != environment:
continue
cloud_environment_service_check = False
for cloud_environment_service in service["cloud_environments"]:
if cloud_environment_service["name"] == cloud_environment:
cloud_environment_service_check = True
break
if cloud_environment_service_check is False:
continue
if not service["service_title"]:
continue
if not service["service_type"]:
@ -164,6 +171,13 @@ class Services(object):
if "environment" in doc:
if doc["environment"] != environment:
continue
cloud_environment_doc_check = False
for cloud_environment_doc in doc["cloud_environments"]:
if cloud_environment_doc["name"] == cloud_environment:
cloud_environment_doc_check = True
break
if cloud_environment_doc_check is False:
continue
if doc["service_type"] == service["service_type"]:
doc_list.append({
"title": doc["title"],
@ -239,22 +253,31 @@ class Services(object):
def all_docs_full(self, environment):
"""Return list or documents with full service data"""
res = []
services = self.service_dict
for doc in self.all_docs:
if not doc["service_type"] in services:
print(f"No service type {doc['service_type']}")
cat = doc["service_type"]
service = services.get(cat)
if not service:
warnings.warn("No Service defition of type %s" % (cat))
continue
service = services[doc["service_type"]]
res_doc = copy.deepcopy(doc)
res_doc.update(**service)
if environment:
for srv_env in service["repositories"]:
if srv_env.get("environment") == environment:
res_doc["repository"] = srv_env["repo"]
for srv_assignees in service.get("assignees", []):
if srv_assignees.get("environment") == environment:
res_doc["assignees"] = srv_assignees["names"]
yield res_doc
for repositories in self.all_repositories:
if repositories["service_type"] == service["service_type"]:
res_doc = copy.deepcopy(doc)
res_doc["repositories"] = repositories["repositories"]
res_doc.update(**service)
# Get the cloud environments from the document instead of service
res_doc["cloud_environments"] = doc["cloud_environments"]
if environment:
repo_env_filter = []
for repo in repositories["repositories"]:
if repo["environment"] == environment:
repo_env_filter.append(repo)
res_doc["repositories"] = repo_env_filter
res.append(res_doc)
return res
def docs_html_by_category(self, environment, cloud_environment):
"""Generate structure for doc-exports repository"""

View File

@ -60,6 +60,12 @@ def parse_args():
required=True,
help='Password for the connection.'
)
parser.add_argument(
"--cloud-environment",
required=True,
default="eu_de",
help="Cloud Environment. Default: eu_de",
)
args = parser.parse_args()
return args
@ -74,6 +80,7 @@ def main():
logging.debug("Obtaining data from otc_metadata")
data = getData(
cloud_environment=args.cloud_environment,
environment=args.target_environment,
all_doc_types=args.all_doc_types
)
@ -99,8 +106,9 @@ def filter_docs(metadata):
return metadata
def getData(environment, all_doc_types):
def getData(cloud_environment, environment, all_doc_types):
metadatadata = metadata.service_types_with_doc_types(
cloud_environment=cloud_environment,
environment=environment
)
final_data = metadatadata

View File

@ -50,11 +50,21 @@ def main():
"--labels",
help="Issue labels to use (comma separated list of label IDs).",
)
parser.add_argument(
"--cloud-environment",
required=True,
default="eu_de",
help="Cloud Environment. Default: eu_de",
)
args = parser.parse_args()
data = otc_metadata.services.Services()
api_session.headers.update({"Authorization": f"token {args.token}"})
for doc in data.all_docs_full(environment=args.environment):
for repository in doc["repositories"]:
if repository["cloud_environments"][0] == args.cloud_environment:
doc["repository"] = repository
break
issue_data = dict(
title=args.title.format(**doc),
body=args.body.format(**doc),