Skip to content

Commit

Permalink
fix issue where connection paths were not being parsed correctly and …
Browse files Browse the repository at this point in the history
…modified some of the naming of arguments
  • Loading branch information
rkrishnasanka committed Aug 13, 2021
1 parent 43be1aa commit 9f532e9
Showing 1 changed file with 30 additions and 24 deletions.
54 changes: 30 additions & 24 deletions parchmint/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(
source: Target = None,
sink: Target = None,
waypoints: List[Tuple[int, int]] = None,
json=None,
json_data=None,
) -> None:
"""Creates a new connection path object
Expand All @@ -34,8 +34,8 @@ def __init__(
self.__sink: Optional[Target] = sink
self.__waypoints: List[Tuple[int, int]] = waypoints

if json is not None:
self.parse_parchmint_v1(json)
if json_data is not None:
self.parse_parchmint_v1(json_data)

@property
def source(self) -> Target:
Expand Down Expand Up @@ -97,10 +97,14 @@ def to_parchmint_v1(self):
"wayPoints": [list(wp) for wp in self.__waypoints],
}

def parse_parchmint_v1(self, json) -> None:
self.__source = Target(json=json["source"])
self.__sink = Target(json=json["sink"])
self.__waypoints = [(wp[0], wp[1]) for wp in json["wayPoints"]]
def parse_parchmint_v1(self, json_data) -> None:
self.__source = Target(json=json_data["source"])
self.__sink = Target(json=json_data["sink"])
self.__waypoints = (
[(wp[0], wp[1]) for wp in json_data["wayPoints"]]
if json_data["wayPoints"] is not None
else []
)


class Connection:
Expand All @@ -111,7 +115,7 @@ class Connection:
"""

def __init__(self, json=None, device_ref=None):
def __init__(self, json_data=None, device_ref=None):
"""[summary]
Args:
Expand All @@ -131,13 +135,13 @@ def __init__(self, json=None, device_ref=None):
self._paths: List[ConnectionPath] = []
self.features: List[str] = []

if json:
if json_data:
if device_ref is None:
raise Exception(
"Cannot Parse Connection from JSON with no Device Reference, check device_ref parameter in constructor "
)

self.parse_from_json_v1_x(json, device_ref)
self.parse_from_json_v1_x(json_data, device_ref)

def parse_from_json(self, json, device_ref=None):
"""Parses from the json dict
Expand Down Expand Up @@ -167,7 +171,7 @@ def parse_from_json(self, json, device_ref=None):
for target in json["sinks"]:
self.sinks.append(Target(target))

def parse_from_json_v1_x(self, json, device_ref=None):
def parse_from_json_v1_x(self, json_data, device_ref=None):
"""Parses from the json dict - v1_x
Args:
Expand All @@ -177,31 +181,33 @@ def parse_from_json_v1_x(self, json, device_ref=None):
raise Exception(
"Cannot Parse Connection from JSON with no Device Reference, check device_ref parameter in constructor "
)
self.name = json["name"]
self.ID = json["id"]
self.layer = device_ref.get_layer(json["layer"])
self.name = json_data["name"]
self.ID = json_data["id"]
self.layer = device_ref.get_layer(json_data["layer"])

# Pull out the paths
if "paths" in json["params"].keys():
json_paths = json["params"]["paths"]
if "paths" in json_data.keys():
json_paths = json_data["paths"]
for json_path in json_paths:
self._paths.append(ConnectionPath(json_path))
self._paths.append(ConnectionPath(json_data=json_path))
else:
print("No path data found for connection {}".format(self.ID))

self.params = Params(json["params"])
self.params = Params(json_data["params"])

self.source = Target(json["source"])
self.source = Target(json_data["source"])

if "sinks" in json.keys():
if json["sinks"]:
for target in json["sinks"]:
if "sinks" in json_data.keys():
if json_data["sinks"]:
for target in json_data["sinks"]:
self.sinks.append(Target(target))
else:
print("connection", self.name, "does not have any sinks")
else:
print("connection", self.name, "does not have any sinks")

if "features" in json.keys():
self.features = json["features"]
if "features" in json_data.keys():
self.features = json_data["features"]

def __str__(self):
return str(self.__dict__)
Expand Down

0 comments on commit 9f532e9

Please sign in to comment.