chore: apply pre-commit hooks
This commit is contained in:
parent
603b9cb299
commit
a58e2c3af0
1 changed files with 15 additions and 19 deletions
|
@ -1,4 +1,4 @@
|
||||||
from typing import List, Optional
|
from typing import Dict, List, Optional
|
||||||
|
|
||||||
from ruamel.yaml import YAML
|
from ruamel.yaml import YAML
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ from compose_viz.compose import Compose, Service
|
||||||
from compose_viz.extends import Extends
|
from compose_viz.extends import Extends
|
||||||
from compose_viz.volume import Volume, VolumeType
|
from compose_viz.volume import Volume, VolumeType
|
||||||
|
|
||||||
|
|
||||||
class Parser:
|
class Parser:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
|
@ -25,7 +26,6 @@ class Parser:
|
||||||
raise RuntimeError("No services found, aborting.")
|
raise RuntimeError("No services found, aborting.")
|
||||||
|
|
||||||
# parse services data into Service objects
|
# parse services data into Service objects
|
||||||
services_data = yaml_data["services"]
|
|
||||||
services = self.parse_service_data(yaml_data["services"])
|
services = self.parse_service_data(yaml_data["services"])
|
||||||
|
|
||||||
# create Compose object
|
# create Compose object
|
||||||
|
@ -33,16 +33,15 @@ class Parser:
|
||||||
|
|
||||||
return compose
|
return compose
|
||||||
|
|
||||||
def parse_service_data(self, services_yaml_data: List):
|
def parse_service_data(self, services_yaml_data: Dict[str, dict]) -> List[Service]:
|
||||||
services = []
|
services: List[Service] = []
|
||||||
for service, service_name in zip(services_yaml_data.values(), services_yaml_data.keys()):
|
for service, service_name in zip(services_yaml_data.values(), services_yaml_data.keys()):
|
||||||
|
|
||||||
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"]
|
||||||
elif service.get("build"):
|
elif service.get("build"):
|
||||||
service_image = "build from " + service["build"]
|
service_image = "build from " + service["build"]
|
||||||
|
|
||||||
|
|
||||||
service_networks: List[str] = []
|
service_networks: List[str] = []
|
||||||
if service.get("networks"):
|
if service.get("networks"):
|
||||||
|
@ -50,12 +49,10 @@ class Parser:
|
||||||
service_networks = service["networks"]
|
service_networks = service["networks"]
|
||||||
else:
|
else:
|
||||||
service_networks = list(service["networks"].keys())
|
service_networks = list(service["networks"].keys())
|
||||||
|
|
||||||
|
|
||||||
service_extends: Optional[Extends] = None
|
service_extends: Optional[Extends] = None
|
||||||
if service.get("extends"):
|
if service.get("extends"):
|
||||||
service_extends = Extends(service_name=service["extends"]["service"])
|
service_extends = Extends(service_name=service["extends"]["service"])
|
||||||
|
|
||||||
|
|
||||||
service_ports: List[str] = []
|
service_ports: List[str] = []
|
||||||
if service.get("ports"):
|
if service.get("ports"):
|
||||||
|
@ -74,7 +71,7 @@ class Parser:
|
||||||
volume_type = VolumeType[volume_data["type"]]
|
volume_type = VolumeType[volume_data["type"]]
|
||||||
service_volumes.append(Volume(source=volume_source, target=volume_target, type=volume_type))
|
service_volumes.append(Volume(source=volume_source, target=volume_target, type=volume_type))
|
||||||
elif type(volume_data) is str:
|
elif type(volume_data) is str:
|
||||||
spilt_data = volume_data.split(":",1)
|
spilt_data = volume_data.split(":", 1)
|
||||||
volume_source = spilt_data[0]
|
volume_source = spilt_data[0]
|
||||||
volume_target = spilt_data[1]
|
volume_target = spilt_data[1]
|
||||||
service_volumes.append(Volume(source=volume_source, target=volume_target))
|
service_volumes.append(Volume(source=volume_source, target=volume_target))
|
||||||
|
@ -92,18 +89,17 @@ class Parser:
|
||||||
ports=service_ports,
|
ports=service_ports,
|
||||||
depends_on=service_depends_on,
|
depends_on=service_depends_on,
|
||||||
volumes=service_volumes,
|
volumes=service_volumes,
|
||||||
links=service_links
|
links=service_links,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
# Service print debug
|
# Service print debug
|
||||||
#print("--------------------")
|
# print("--------------------")
|
||||||
#print("Service name: {}".format(service_name))
|
# print("Service name: {}".format(service_name))
|
||||||
#print("image: {}".format(service_image))
|
# print("image: {}".format(service_image))
|
||||||
#print("networks: {}".format(service_networks))
|
# print("networks: {}".format(service_networks))
|
||||||
#print("image: {}".format(service_image))
|
# print("image: {}".format(service_image))
|
||||||
#print("extends: {}".format(service_extends))
|
# print("extends: {}".format(service_extends))
|
||||||
#print("ports: {}".format(service_ports))
|
# print("ports: {}".format(service_ports))
|
||||||
#print("depends: {}".format(service_depends_on))
|
# print("depends: {}".format(service_depends_on))
|
||||||
|
|
||||||
|
|
||||||
return services
|
return services
|
||||||
|
|
Loading…
Reference in a new issue