Skip to content
Draft
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
2 changes: 1 addition & 1 deletion mps-cli-py/src/mpscli/model/SRepository.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ def get_model_by_uuid(self, uuid):
for sol in self.solutions:
for m in sol.models:
self.uuid_2_model[m.uuid] = m
return self.uuid_2_model.get(uuid)
return self.uuid_2_model.get(uuid)
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@

from mpscli.model.builder.SModelBuilderBase import SModelBuilderBase
import xml.etree.ElementTree as ET


class MpsrFileFiler:

def is_mpsr_file_needed(self, file):
return True


class SModelBuilderFilePerRootPersistency(SModelBuilderBase):

def __init__(self, mpsr_file_filter=None):
if mpsr_file_filter is None:
self.mpsr_file_filter = MpsrFileFiler()
else:
self.mpsr_file_filter = mpsr_file_filter
super().__init__()

def build(self, path):
model_file = path / '.model'
tree = ET.parse(model_file)
Expand All @@ -13,7 +25,7 @@ def build(self, path):
model.path_to_model_file = model_file

for file in path.iterdir():
if file.suffix == '.mpsr':
if file.suffix == '.mpsr' and self.mpsr_file_filter.is_mpsr_file_needed(file):
root_node = self.extract_root_node(model, file)
model.root_nodes.append(root_node)

Expand All @@ -25,6 +37,3 @@ def extract_root_node(self, model, mpsr_file):
self.extract_imports_and_registry(model_xml_node)
root_node = model_xml_node.find("node")
return self.extract_node(model, root_node)



4 changes: 2 additions & 2 deletions mps-cli-py/src/mpscli/model/builder/SSolutionBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class SSolutionBuilder:

def build_solution(self, path_to_msd_file):
def build_solution(self, path_to_msd_file, file_filter=None):
solution = self.extract_solution_core_info(path_to_msd_file)
path_to_solution_dir = path_to_msd_file.parent
solution.path_to_solution_file = path_to_msd_file
Expand All @@ -19,7 +19,7 @@ def build_solution(self, path_to_msd_file):

for path_to_model in path_to_models_dir.iterdir():
if path_to_model.is_dir():
builder = SModelBuilderFilePerRootPersistency()
builder = SModelBuilderFilePerRootPersistency(file_filter)
else:
builder = SModelBuilderDefaultPersistency()
model = builder.build(path_to_model)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SSolutionsRepositoryBuilder:
def __init__(self):
self.repo = SRepository()

def build(self, path):
def build(self, path, file_filter=None):
if not os.path.exists(path):
print("ERROR: path", path, "does not exist!")
sys.exit(1)
Expand All @@ -24,29 +24,29 @@ def build(self, path):

print("building model from path:", path)
start = timer()
self.collect_solutions_from_sources(path)
self.collect_solutions_from_jars(path)
self.collect_solutions_from_sources(path, file_filter)
self.collect_solutions_from_jars(path, file_filter)
self.repo.languages = list(SLanguageBuilder.languages.values())
stop = timer()
duration = (stop - start)
print('duration is: ' + str(duration) + ' seconds')
return self.repo

def collect_solutions_from_sources(self, path):
def collect_solutions_from_sources(self, path, file_filter=None):
for pth in Path(path).rglob('*.msd'):
solutionBuilder = SSolutionBuilder()
solution = solutionBuilder.build_solution(pth)
solution = solutionBuilder.build_solution(pth, file_filter)
if solution is not None:
self.repo.solutions.append(solution)

def collect_solutions_from_jars(self, path):
def collect_solutions_from_jars(self, path, file_filter=None):
for jar_path in Path(path).rglob('*.jar'):
directory_where_to_extract = jar_path.parent / jar_path.name.replace(".", "_")
directory_where_to_extract.mkdir(parents=True, exist_ok=True)
with zipfile.ZipFile(jar_path) as jar:
jar.extractall(directory_where_to_extract)
print("path = ", directory_where_to_extract)
self.collect_solutions_from_sources(directory_where_to_extract)
self.collect_solutions_from_sources(directory_where_to_extract, file_filter)
try:
shutil.rmtree(directory_where_to_extract)
except OSError as e:
Expand Down