Skip to content

Commit

Permalink
Feature/minor improvments for python cli (#29)
Browse files Browse the repository at this point in the history
* mps-cli-py: get_property uses the get function to return None if the property is not found instead of throwing an exception

* mps-cli-py: performance optimazation: use dict for get_model_by_uuid and get_node_by_uuid to speed up the functions if there are called multiple times for big repos

* Update SRepository.py by changing "model_2_uuid" to "uuid_2_model"

---------

Co-authored-by: Michael Langhammer <[email protected]>
Co-authored-by: danielratiu <[email protected]>
  • Loading branch information
3 people authored Apr 10, 2024
1 parent 9b998c3 commit 7150c71
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
9 changes: 5 additions & 4 deletions mps-cli-py/src/mpscli/model/SModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def __init__(self, name, uuid, is_do_not_generate):
self.root_nodes = []
self.path_to_model_file = ""
self.is_do_not_generate = is_do_not_generate
self.uuid_2_nodes = {}

def get_nodes(self):
res = []
Expand All @@ -17,7 +18,7 @@ def get_nodes(self):
return res

def get_node_by_uuid(self, uuid):
for n in self.get_nodes():
if n.uuid == uuid:
return n
return None
if len(self.uuid_2_nodes) == 0:
for n in self.get_nodes():
self.uuid_2_nodes[n.uuid] = n
return self.uuid_2_nodes[uuid]
2 changes: 1 addition & 1 deletion mps-cli-py/src/mpscli/model/SNode.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def __init__(self, uuid, concept, role_in_parent):
self.children = []

def get_property(self, name):
return self.properties[name]
return self.properties.get(name)

def get_reference(self, name):
return self.references[name]
Expand Down
11 changes: 6 additions & 5 deletions mps-cli-py/src/mpscli/model/SRepository.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class SRepository:
def __init__(self):
self.solutions = []
self.languages = []
self.uuid_2_model = {}

def find_solution_by_name(self, name):
for sol in self.solutions:
Expand Down Expand Up @@ -52,8 +53,8 @@ def get_nodes_of_concept(self, concept_name):
return res

def get_model_by_uuid(self, uuid):
for sol in self.solutions:
for m in sol.models:
if m.uuid == uuid:
return m
return None
if len(self.uuid_2_model) == 0:
for sol in self.solutions:
for m in sol.models:
self.uuid_2_model[m.uuid] = m
return self.uuid_2_model.get(uuid)

0 comments on commit 7150c71

Please sign in to comment.