diff --git a/mps-cli-py/src/mpscli/model/SRepository.py b/mps-cli-py/src/mpscli/model/SRepository.py index aa8cf9c..d1c3b52 100644 --- a/mps-cli-py/src/mpscli/model/SRepository.py +++ b/mps-cli-py/src/mpscli/model/SRepository.py @@ -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) \ No newline at end of file diff --git a/mps-cli-py/src/mpscli/model/builder/SModelBuilderFilePerRootPersistency.py b/mps-cli-py/src/mpscli/model/builder/SModelBuilderFilePerRootPersistency.py index 2e28829..9f55144 100644 --- a/mps-cli-py/src/mpscli/model/builder/SModelBuilderFilePerRootPersistency.py +++ b/mps-cli-py/src/mpscli/model/builder/SModelBuilderFilePerRootPersistency.py @@ -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) @@ -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) @@ -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) - - - diff --git a/mps-cli-py/src/mpscli/model/builder/SSolutionBuilder.py b/mps-cli-py/src/mpscli/model/builder/SSolutionBuilder.py index b50d345..8b49bb7 100644 --- a/mps-cli-py/src/mpscli/model/builder/SSolutionBuilder.py +++ b/mps-cli-py/src/mpscli/model/builder/SSolutionBuilder.py @@ -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 @@ -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) diff --git a/mps-cli-py/src/mpscli/model/builder/SSolutionsRepositoryBuilder.py b/mps-cli-py/src/mpscli/model/builder/SSolutionsRepositoryBuilder.py index 2613d10..9eff705 100644 --- a/mps-cli-py/src/mpscli/model/builder/SSolutionsRepositoryBuilder.py +++ b/mps-cli-py/src/mpscli/model/builder/SSolutionsRepositoryBuilder.py @@ -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) @@ -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: