Merge pull request #9 from compose-viz/dev-parser

chore: implement service_ewtends parse
This commit is contained in:
Xyphuz 2022-05-21 15:24:10 +08:00 committed by GitHub
commit 02fda82cf6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,7 +3,7 @@ from typing import List, Optional
from ruamel.yaml import YAML from ruamel.yaml import YAML
from compose_viz.compose import Compose, Service from compose_viz.compose import Compose, Service
from compose_viz.extends import Extends
class Parser: class Parser:
def __init__(self): def __init__(self):
@ -30,12 +30,12 @@ class Parser:
services = [] services = []
for service, service_name in zip(services_data.values(), services_data.keys()): for service, service_name in zip(services_data.values(), services_data.keys()):
# print("name: {}".format(service_name)) print("name: {}".format(service_name))
service_image: Optional[str] = None service_image: Optional[str] = None
if service.get("image"): if service.get("image"):
service_image = service["image"] service_image = service["image"]
# print("image: {}".format(service_image)) print("image: {}".format(service_image))
service_networks: List[str] = [] service_networks: List[str] = []
if service.get("networks"): if service.get("networks"):
@ -43,13 +43,25 @@ class Parser:
service_networks = service["networks"] service_networks = service["networks"]
else: else:
service_networks = list(service["networks"].keys()) service_networks = list(service["networks"].keys())
# print("networks: {}".format(service_networks)) print("networks: {}".format(service_networks))
service_image: Optional[str] = None
if service.get("image"):
service_image = service["image"]
print("image: {}".format(service_image))
service_extends: Optional[Extends] = None
if service.get("extends"):
service_extends = Extends(service_name=service["extends"]["service"])
print("extends: {}".format(service_extends))
services.append( services.append(
Service( Service(
name=service_name, name=service_name,
image=service_image, image=service_image,
networks=service_networks, networks=service_networks,
extends=service_extends
) )
) )