More scripts
This commit is contained in:
		| @ -141,7 +141,7 @@ class Services(object): | |||||||
|             res[cat]["docs"].append(res_doc) |             res[cat]["docs"].append(res_doc) | ||||||
|         return res |         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. |         """Retrieve type and title from services and corresponding docs. | ||||||
|             As well as a list of all available doc types with title. |             As well as a list of all available doc types with title. | ||||||
|  |  | ||||||
| @ -154,6 +154,13 @@ class Services(object): | |||||||
|             if "environment" in service: |             if "environment" in service: | ||||||
|                 if service["environment"] != environment: |                 if service["environment"] != environment: | ||||||
|                     continue |                     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"]: |             if not service["service_title"]: | ||||||
|                 continue |                 continue | ||||||
|             if not service["service_type"]: |             if not service["service_type"]: | ||||||
| @ -164,6 +171,13 @@ class Services(object): | |||||||
|                 if "environment" in doc: |                 if "environment" in doc: | ||||||
|                     if doc["environment"] != environment: |                     if doc["environment"] != environment: | ||||||
|                         continue |                         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"]: |                 if doc["service_type"] == service["service_type"]: | ||||||
|                     doc_list.append({ |                     doc_list.append({ | ||||||
|                         "title": doc["title"], |                         "title": doc["title"], | ||||||
| @ -239,22 +253,31 @@ class Services(object): | |||||||
|  |  | ||||||
|     def all_docs_full(self, environment): |     def all_docs_full(self, environment): | ||||||
|         """Return list or documents with full service data""" |         """Return list or documents with full service data""" | ||||||
|  |         res = [] | ||||||
|         services = self.service_dict |         services = self.service_dict | ||||||
|         for doc in self.all_docs: |         for doc in self.all_docs: | ||||||
|             if not doc["service_type"] in services: |             cat = doc["service_type"] | ||||||
|                 print(f"No service type {doc['service_type']}") |             service = services.get(cat) | ||||||
|  |             if not service: | ||||||
|  |                 warnings.warn("No Service defition of type %s" % (cat)) | ||||||
|                 continue |                 continue | ||||||
|             service = services[doc["service_type"]] |              | ||||||
|             res_doc = copy.deepcopy(doc) |             for repositories in self.all_repositories: | ||||||
|             res_doc.update(**service) |                 if repositories["service_type"] == service["service_type"]: | ||||||
|             if environment: |                     res_doc = copy.deepcopy(doc) | ||||||
|                 for srv_env in service["repositories"]: |                     res_doc["repositories"] = repositories["repositories"] | ||||||
|                     if srv_env.get("environment") == environment: |                     res_doc.update(**service) | ||||||
|                         res_doc["repository"] = srv_env["repo"] |  | ||||||
|                 for srv_assignees in service.get("assignees", []): |                     # Get the cloud environments from the document instead of service | ||||||
|                     if srv_assignees.get("environment") == environment: |                     res_doc["cloud_environments"] = doc["cloud_environments"] | ||||||
|                         res_doc["assignees"] = srv_assignees["names"] |                     if environment: | ||||||
|             yield res_doc |                         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): |     def docs_html_by_category(self, environment, cloud_environment): | ||||||
|         """Generate structure for doc-exports repository""" |         """Generate structure for doc-exports repository""" | ||||||
|  | |||||||
| @ -60,6 +60,12 @@ def parse_args(): | |||||||
|         required=True, |         required=True, | ||||||
|         help='Password for the connection.' |         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() |     args = parser.parse_args() | ||||||
|     return args |     return args | ||||||
| @ -74,6 +80,7 @@ def main(): | |||||||
|  |  | ||||||
|     logging.debug("Obtaining data from otc_metadata") |     logging.debug("Obtaining data from otc_metadata") | ||||||
|     data = getData( |     data = getData( | ||||||
|  |         cloud_environment=args.cloud_environment, | ||||||
|         environment=args.target_environment, |         environment=args.target_environment, | ||||||
|         all_doc_types=args.all_doc_types |         all_doc_types=args.all_doc_types | ||||||
|     ) |     ) | ||||||
| @ -99,8 +106,9 @@ def filter_docs(metadata): | |||||||
|     return metadata |     return metadata | ||||||
|  |  | ||||||
|  |  | ||||||
| def getData(environment, all_doc_types): | def getData(cloud_environment, environment, all_doc_types): | ||||||
|     metadatadata = metadata.service_types_with_doc_types( |     metadatadata = metadata.service_types_with_doc_types( | ||||||
|  |         cloud_environment=cloud_environment, | ||||||
|         environment=environment |         environment=environment | ||||||
|     ) |     ) | ||||||
|     final_data = metadatadata |     final_data = metadatadata | ||||||
|  | |||||||
| @ -50,11 +50,21 @@ def main(): | |||||||
|         "--labels", |         "--labels", | ||||||
|         help="Issue labels to use (comma separated list of label IDs).", |         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() |     args = parser.parse_args() | ||||||
|     data = otc_metadata.services.Services() |     data = otc_metadata.services.Services() | ||||||
|     api_session.headers.update({"Authorization": f"token {args.token}"}) |     api_session.headers.update({"Authorization": f"token {args.token}"}) | ||||||
|  |  | ||||||
|     for doc in data.all_docs_full(environment=args.environment): |     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( |         issue_data = dict( | ||||||
|             title=args.title.format(**doc), |             title=args.title.format(**doc), | ||||||
|             body=args.body.format(**doc), |             body=args.body.format(**doc), | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user