Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compose_plantuml issues with pyaml #10

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 32 additions & 11 deletions compose_plantuml/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
from yaml import load
from yaml import FullLoader


class ComposePlantuml:
Expand All @@ -8,7 +9,7 @@ def __init__(self):
pass

def parse(self, data):
return load(data)
return load(data, Loader=FullLoader)

def link_graph(self, compose, notes=False):
result = 'skinparam componentStyle uml2\n'
Expand Down Expand Up @@ -116,8 +117,13 @@ def is_volume_used(compose, volume):

for _, component in components.items():
for volume_name in component.get('volumes', {}):
if volume_name.startswith('{0}:'.format(volume)):
return True
if isinstance(volume_name, dict):
if volume_name['target'].startswith('{0}:'.format(volume)):
return True
else:
if volume_name.startswith('{0}:'.format(volume)):
return True

return False

@staticmethod
Expand Down Expand Up @@ -155,10 +161,17 @@ def has_service_volumes(compose, service):
if 'volumes' not in component:
return False
for volume in component['volumes']:
if volume.startswith('/'):
continue
if ':' in volume:
return True
if isinstance(volume, dict):
if volume['target'].startswith('/'):
continue
if ':' in volume:
return True
else:
if volume.startswith('/'):
continue
if ':' in volume:
return True

return False

@staticmethod
Expand Down Expand Up @@ -228,8 +241,12 @@ def volume_usage(compose, volume):

for component_name, component in components.items():
for volume_name in component.get('volumes', {}):
if not volume_name.startswith('{0}:'.format(volume)):
continue
if isinstance(volume_name, dict):
if not volume_name['target'].startswith('{0}:'.format(volume)):
continue
else:
if not volume_name.startswith('{0}:'.format(volume)):
continue
result.append(volume_name.split(':')[1])
return result

Expand All @@ -240,7 +257,11 @@ def service_using_path(compose, volume):

for component_name, component in components.items():
for volume_name in component.get('volumes', {}):
if not volume_name.startswith('{0}:'.format(volume)):
continue
if isinstance(volume_name, dict):
if not volume_name['target'].startswith('{0}:'.format(volume)):
continue
else:
if not volume_name.startswith('{0}:'.format(volume)):
continue
result.append((component_name, volume_name.split(':')[1]))
return result
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


def readme():
with open('README.rst') as file:
with open('README.md') as file:
return file.read()


Expand Down