mps-cli 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mps_cli-0.2.0.dist-info/METADATA +39 -0
- mps_cli-0.2.0.dist-info/RECORD +22 -0
- mps_cli-0.2.0.dist-info/WHEEL +4 -0
- mps_cli-0.2.0.dist-info/licenses/LICENSE +277 -0
- mpscli/__init__.py +0 -0
- mpscli/demo.py +6 -0
- mpscli/model/SConcept.py +22 -0
- mpscli/model/SLanguage.py +14 -0
- mpscli/model/SModel.py +24 -0
- mpscli/model/SNode.py +31 -0
- mpscli/model/SNodeRef.py +14 -0
- mpscli/model/SRepository.py +60 -0
- mpscli/model/SSolution.py +9 -0
- mpscli/model/__init__.py +0 -0
- mpscli/model/builder/NodeIdEncodingUtils.py +24 -0
- mpscli/model/builder/SLanguageBuilder.py +46 -0
- mpscli/model/builder/SModelBuilderBase.py +94 -0
- mpscli/model/builder/SModelBuilderDefaultPersistency.py +19 -0
- mpscli/model/builder/SModelBuilderFilePerRootPersistency.py +30 -0
- mpscli/model/builder/SSolutionBuilder.py +36 -0
- mpscli/model/builder/SSolutionsRepositoryBuilder.py +53 -0
- mpscli/model/builder/__init__.py +0 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: mps-cli
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: MPS Command Line Interface (MPS-CLI) is a library to parse MPS files and build the model as Python objects.
|
|
5
|
+
Project-URL: Homepage, https://github.com/mbeddr/mps-cli
|
|
6
|
+
Project-URL: Bug Tracker, https://github.com/mbeddr/mps-cli/issues
|
|
7
|
+
Author-email: Daniel Ratiu <ratiud@googlemail.com>
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: License :: OSI Approved :: Eclipse Public License 2.0 (EPL-2.0)
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Requires-Python: >=3.7
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
|
|
15
|
+
## MPS CLI Python Library
|
|
16
|
+
|
|
17
|
+
This project provides a Python library which parses MPS files and builds the object model.
|
|
18
|
+
|
|
19
|
+
### Features
|
|
20
|
+
The following features are available:
|
|
21
|
+
- load MPS files (*.mpsr, *.mps, *.jar) and expose their content as Python object model
|
|
22
|
+
- solutions, models, root nodes, nodes, children, references, properties
|
|
23
|
+
- extract the meta-information and expose it as Python object model
|
|
24
|
+
- list of languages, their concepts with information about properties, references, children
|
|
25
|
+
|
|
26
|
+
The core of the Python object model is given by the following classes:
|
|
27
|
+
- `SNode` - represents a node
|
|
28
|
+
- `SModel` - represents a model
|
|
29
|
+
- `SSolution` - represents a solution
|
|
30
|
+
- `SRepository` - the repository containing the parsed model and meta-information
|
|
31
|
+
|
|
32
|
+
### Limitations
|
|
33
|
+
The plugin has currently the following limitations:
|
|
34
|
+
- the recovered language information reflects only the used language in the loaded solutions
|
|
35
|
+
|
|
36
|
+
### Run tests
|
|
37
|
+
|
|
38
|
+
- `cd mps-cli-py`
|
|
39
|
+
- `python -m unittest discover`
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
mpscli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
mpscli/demo.py,sha256=JtEEvXlm80cuQkbch-ioahPi3nsBRgWErTGyOiia8-I,271
|
|
3
|
+
mpscli/model/SConcept.py,sha256=mZYSaoRGUviBTu3dVcFIgFH1hNV3IKQOQFyCoALqie0,608
|
|
4
|
+
mpscli/model/SLanguage.py,sha256=SomT_vsPtsbKK1oHVQ9ywadY5p6bLOcx8mEYDXHUdGk,283
|
|
5
|
+
mpscli/model/SModel.py,sha256=9GvVb_Sqpc5v4o8UXfTT2bQTTeYW1IZMmX4jjSU56oE,641
|
|
6
|
+
mpscli/model/SNode.py,sha256=09VkqEqk9OI0hLAVr7iq6if2xX7pRuxooHpHcJOoK-w,843
|
|
7
|
+
mpscli/model/SNodeRef.py,sha256=nfd8ZLRwRmC9GnMQs9LX9oUUuzNOh4_4cqZu8BD682E,329
|
|
8
|
+
mpscli/model/SRepository.py,sha256=trDtNvpQYandk2eciIR642CtRZh2JNalyqa0jgbTcf8,1640
|
|
9
|
+
mpscli/model/SSolution.py,sha256=02I2J-SKQiKUvEWQ2PKGSN7DsEdz47N8YctKePGAq7U,170
|
|
10
|
+
mpscli/model/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
|
+
mpscli/model/builder/NodeIdEncodingUtils.py,sha256=w_zcGDB_sqj8GcFZuPwS-JrLCscqH5fyUsJDKF6few0,852
|
|
12
|
+
mpscli/model/builder/SLanguageBuilder.py,sha256=tkv6X74pX6jY8jI193JAKiYwCVookARsUzxthPMJhkg,1608
|
|
13
|
+
mpscli/model/builder/SModelBuilderBase.py,sha256=JdowMDXkRq_nuYUUFghF5EfMWxA-dLOR7IZdpP40838,5043
|
|
14
|
+
mpscli/model/builder/SModelBuilderDefaultPersistency.py,sha256=AefnHg-3AqLz0ilodM3FWIZfc6RLEYJIihKDKcxGEhY,623
|
|
15
|
+
mpscli/model/builder/SModelBuilderFilePerRootPersistency.py,sha256=gcVq2D7j2nzpC_h_SG8CwQn9uILuL9rxTblo6IvPRdc,923
|
|
16
|
+
mpscli/model/builder/SSolutionBuilder.py,sha256=bNldi9BYLPWCi_tIjCuWUvY1XjTs1ORgXMBP8bCTSGs,1544
|
|
17
|
+
mpscli/model/builder/SSolutionsRepositoryBuilder.py,sha256=Phj_MMwcLHqIJKu7BIUY7FuHnWSH0ZT1_F4nfJDywwo,2040
|
|
18
|
+
mpscli/model/builder/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
19
|
+
mps_cli-0.2.0.dist-info/METADATA,sha256=RwnUo2GdRYn3VrpD67T7Wy-9bWcQ1z88nAX-_p62eao,1577
|
|
20
|
+
mps_cli-0.2.0.dist-info/WHEEL,sha256=zEMcRr9Kr03x1ozGwg5v9NQBKn3kndp6LSoSlVg-jhU,87
|
|
21
|
+
mps_cli-0.2.0.dist-info/licenses/LICENSE,sha256=jDSfgHZNBkjmRfQe8jdypwyZWgkktSNfc19KPQnfEnw,14197
|
|
22
|
+
mps_cli-0.2.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
Eclipse Public License - v 2.0
|
|
2
|
+
|
|
3
|
+
THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE
|
|
4
|
+
PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION
|
|
5
|
+
OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
|
|
6
|
+
|
|
7
|
+
1. DEFINITIONS
|
|
8
|
+
|
|
9
|
+
"Contribution" means:
|
|
10
|
+
|
|
11
|
+
a) in the case of the initial Contributor, the initial content
|
|
12
|
+
Distributed under this Agreement, and
|
|
13
|
+
|
|
14
|
+
b) in the case of each subsequent Contributor:
|
|
15
|
+
i) changes to the Program, and
|
|
16
|
+
ii) additions to the Program;
|
|
17
|
+
where such changes and/or additions to the Program originate from
|
|
18
|
+
and are Distributed by that particular Contributor. A Contribution
|
|
19
|
+
"originates" from a Contributor if it was added to the Program by
|
|
20
|
+
such Contributor itself or anyone acting on such Contributor's behalf.
|
|
21
|
+
Contributions do not include changes or additions to the Program that
|
|
22
|
+
are not Modified Works.
|
|
23
|
+
|
|
24
|
+
"Contributor" means any person or entity that Distributes the Program.
|
|
25
|
+
|
|
26
|
+
"Licensed Patents" mean patent claims licensable by a Contributor which
|
|
27
|
+
are necessarily infringed by the use or sale of its Contribution alone
|
|
28
|
+
or when combined with the Program.
|
|
29
|
+
|
|
30
|
+
"Program" means the Contributions Distributed in accordance with this
|
|
31
|
+
Agreement.
|
|
32
|
+
|
|
33
|
+
"Recipient" means anyone who receives the Program under this Agreement
|
|
34
|
+
or any Secondary License (as applicable), including Contributors.
|
|
35
|
+
|
|
36
|
+
"Derivative Works" shall mean any work, whether in Source Code or other
|
|
37
|
+
form, that is based on (or derived from) the Program and for which the
|
|
38
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
39
|
+
represent, as a whole, an original work of authorship.
|
|
40
|
+
|
|
41
|
+
"Modified Works" shall mean any work in Source Code or other form that
|
|
42
|
+
results from an addition to, deletion from, or modification of the
|
|
43
|
+
contents of the Program, including, for purposes of clarity any new file
|
|
44
|
+
in Source Code form that contains any contents of the Program. Modified
|
|
45
|
+
Works shall not include works that contain only declarations,
|
|
46
|
+
interfaces, types, classes, structures, or files of the Program solely
|
|
47
|
+
in each case in order to link to, bind by name, or subclass the Program
|
|
48
|
+
or Modified Works thereof.
|
|
49
|
+
|
|
50
|
+
"Distribute" means the acts of a) distributing or b) making available
|
|
51
|
+
in any manner that enables the transfer of a copy.
|
|
52
|
+
|
|
53
|
+
"Source Code" means the form of a Program preferred for making
|
|
54
|
+
modifications, including but not limited to software source code,
|
|
55
|
+
documentation source, and configuration files.
|
|
56
|
+
|
|
57
|
+
"Secondary License" means either the GNU General Public License,
|
|
58
|
+
Version 2.0, or any later versions of that license, including any
|
|
59
|
+
exceptions or additional permissions as identified by the initial
|
|
60
|
+
Contributor.
|
|
61
|
+
|
|
62
|
+
2. GRANT OF RIGHTS
|
|
63
|
+
|
|
64
|
+
a) Subject to the terms of this Agreement, each Contributor hereby
|
|
65
|
+
grants Recipient a non-exclusive, worldwide, royalty-free copyright
|
|
66
|
+
license to reproduce, prepare Derivative Works of, publicly display,
|
|
67
|
+
publicly perform, Distribute and sublicense the Contribution of such
|
|
68
|
+
Contributor, if any, and such Derivative Works.
|
|
69
|
+
|
|
70
|
+
b) Subject to the terms of this Agreement, each Contributor hereby
|
|
71
|
+
grants Recipient a non-exclusive, worldwide, royalty-free patent
|
|
72
|
+
license under Licensed Patents to make, use, sell, offer to sell,
|
|
73
|
+
import and otherwise transfer the Contribution of such Contributor,
|
|
74
|
+
if any, in Source Code or other form. This patent license shall
|
|
75
|
+
apply to the combination of the Contribution and the Program if, at
|
|
76
|
+
the time the Contribution is added by the Contributor, such addition
|
|
77
|
+
of the Contribution causes such combination to be covered by the
|
|
78
|
+
Licensed Patents. The patent license shall not apply to any other
|
|
79
|
+
combinations which include the Contribution. No hardware per se is
|
|
80
|
+
licensed hereunder.
|
|
81
|
+
|
|
82
|
+
c) Recipient understands that although each Contributor grants the
|
|
83
|
+
licenses to its Contributions set forth herein, no assurances are
|
|
84
|
+
provided by any Contributor that the Program does not infringe the
|
|
85
|
+
patent or other intellectual property rights of any other entity.
|
|
86
|
+
Each Contributor disclaims any liability to Recipient for claims
|
|
87
|
+
brought by any other entity based on infringement of intellectual
|
|
88
|
+
property rights or otherwise. As a condition to exercising the
|
|
89
|
+
rights and licenses granted hereunder, each Recipient hereby
|
|
90
|
+
assumes sole responsibility to secure any other intellectual
|
|
91
|
+
property rights needed, if any. For example, if a third party
|
|
92
|
+
patent license is required to allow Recipient to Distribute the
|
|
93
|
+
Program, it is Recipient's responsibility to acquire that license
|
|
94
|
+
before distributing the Program.
|
|
95
|
+
|
|
96
|
+
d) Each Contributor represents that to its knowledge it has
|
|
97
|
+
sufficient copyright rights in its Contribution, if any, to grant
|
|
98
|
+
the copyright license set forth in this Agreement.
|
|
99
|
+
|
|
100
|
+
e) Notwithstanding the terms of any Secondary License, no
|
|
101
|
+
Contributor makes additional grants to any Recipient (other than
|
|
102
|
+
those set forth in this Agreement) as a result of such Recipient's
|
|
103
|
+
receipt of the Program under the terms of a Secondary License
|
|
104
|
+
(if permitted under the terms of Section 3).
|
|
105
|
+
|
|
106
|
+
3. REQUIREMENTS
|
|
107
|
+
|
|
108
|
+
3.1 If a Contributor Distributes the Program in any form, then:
|
|
109
|
+
|
|
110
|
+
a) the Program must also be made available as Source Code, in
|
|
111
|
+
accordance with section 3.2, and the Contributor must accompany
|
|
112
|
+
the Program with a statement that the Source Code for the Program
|
|
113
|
+
is available under this Agreement, and informs Recipients how to
|
|
114
|
+
obtain it in a reasonable manner on or through a medium customarily
|
|
115
|
+
used for software exchange; and
|
|
116
|
+
|
|
117
|
+
b) the Contributor may Distribute the Program under a license
|
|
118
|
+
different than this Agreement, provided that such license:
|
|
119
|
+
i) effectively disclaims on behalf of all other Contributors all
|
|
120
|
+
warranties and conditions, express and implied, including
|
|
121
|
+
warranties or conditions of title and non-infringement, and
|
|
122
|
+
implied warranties or conditions of merchantability and fitness
|
|
123
|
+
for a particular purpose;
|
|
124
|
+
|
|
125
|
+
ii) effectively excludes on behalf of all other Contributors all
|
|
126
|
+
liability for damages, including direct, indirect, special,
|
|
127
|
+
incidental and consequential damages, such as lost profits;
|
|
128
|
+
|
|
129
|
+
iii) does not attempt to limit or alter the recipients' rights
|
|
130
|
+
in the Source Code under section 3.2; and
|
|
131
|
+
|
|
132
|
+
iv) requires any subsequent distribution of the Program by any
|
|
133
|
+
party to be under a license that satisfies the requirements
|
|
134
|
+
of this section 3.
|
|
135
|
+
|
|
136
|
+
3.2 When the Program is Distributed as Source Code:
|
|
137
|
+
|
|
138
|
+
a) it must be made available under this Agreement, or if the
|
|
139
|
+
Program (i) is combined with other material in a separate file or
|
|
140
|
+
files made available under a Secondary License, and (ii) the initial
|
|
141
|
+
Contributor attached to the Source Code the notice described in
|
|
142
|
+
Exhibit A of this Agreement, then the Program may be made available
|
|
143
|
+
under the terms of such Secondary Licenses, and
|
|
144
|
+
|
|
145
|
+
b) a copy of this Agreement must be included with each copy of
|
|
146
|
+
the Program.
|
|
147
|
+
|
|
148
|
+
3.3 Contributors may not remove or alter any copyright, patent,
|
|
149
|
+
trademark, attribution notices, disclaimers of warranty, or limitations
|
|
150
|
+
of liability ("notices") contained within the Program from any copy of
|
|
151
|
+
the Program which they Distribute, provided that Contributors may add
|
|
152
|
+
their own appropriate notices.
|
|
153
|
+
|
|
154
|
+
4. COMMERCIAL DISTRIBUTION
|
|
155
|
+
|
|
156
|
+
Commercial distributors of software may accept certain responsibilities
|
|
157
|
+
with respect to end users, business partners and the like. While this
|
|
158
|
+
license is intended to facilitate the commercial use of the Program,
|
|
159
|
+
the Contributor who includes the Program in a commercial product
|
|
160
|
+
offering should do so in a manner which does not create potential
|
|
161
|
+
liability for other Contributors. Therefore, if a Contributor includes
|
|
162
|
+
the Program in a commercial product offering, such Contributor
|
|
163
|
+
("Commercial Contributor") hereby agrees to defend and indemnify every
|
|
164
|
+
other Contributor ("Indemnified Contributor") against any losses,
|
|
165
|
+
damages and costs (collectively "Losses") arising from claims, lawsuits
|
|
166
|
+
and other legal actions brought by a third party against the Indemnified
|
|
167
|
+
Contributor to the extent caused by the acts or omissions of such
|
|
168
|
+
Commercial Contributor in connection with its distribution of the Program
|
|
169
|
+
in a commercial product offering. The obligations in this section do not
|
|
170
|
+
apply to any claims or Losses relating to any actual or alleged
|
|
171
|
+
intellectual property infringement. In order to qualify, an Indemnified
|
|
172
|
+
Contributor must: a) promptly notify the Commercial Contributor in
|
|
173
|
+
writing of such claim, and b) allow the Commercial Contributor to control,
|
|
174
|
+
and cooperate with the Commercial Contributor in, the defense and any
|
|
175
|
+
related settlement negotiations. The Indemnified Contributor may
|
|
176
|
+
participate in any such claim at its own expense.
|
|
177
|
+
|
|
178
|
+
For example, a Contributor might include the Program in a commercial
|
|
179
|
+
product offering, Product X. That Contributor is then a Commercial
|
|
180
|
+
Contributor. If that Commercial Contributor then makes performance
|
|
181
|
+
claims, or offers warranties related to Product X, those performance
|
|
182
|
+
claims and warranties are such Commercial Contributor's responsibility
|
|
183
|
+
alone. Under this section, the Commercial Contributor would have to
|
|
184
|
+
defend claims against the other Contributors related to those performance
|
|
185
|
+
claims and warranties, and if a court requires any other Contributor to
|
|
186
|
+
pay any damages as a result, the Commercial Contributor must pay
|
|
187
|
+
those damages.
|
|
188
|
+
|
|
189
|
+
5. NO WARRANTY
|
|
190
|
+
|
|
191
|
+
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT
|
|
192
|
+
PERMITTED BY APPLICABLE LAW, THE PROGRAM IS PROVIDED ON AN "AS IS"
|
|
193
|
+
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR
|
|
194
|
+
IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF
|
|
195
|
+
TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR
|
|
196
|
+
PURPOSE. Each Recipient is solely responsible for determining the
|
|
197
|
+
appropriateness of using and distributing the Program and assumes all
|
|
198
|
+
risks associated with its exercise of rights under this Agreement,
|
|
199
|
+
including but not limited to the risks and costs of program errors,
|
|
200
|
+
compliance with applicable laws, damage to or loss of data, programs
|
|
201
|
+
or equipment, and unavailability or interruption of operations.
|
|
202
|
+
|
|
203
|
+
6. DISCLAIMER OF LIABILITY
|
|
204
|
+
|
|
205
|
+
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT
|
|
206
|
+
PERMITTED BY APPLICABLE LAW, NEITHER RECIPIENT NOR ANY CONTRIBUTORS
|
|
207
|
+
SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
208
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST
|
|
209
|
+
PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
210
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
211
|
+
ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE
|
|
212
|
+
EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE
|
|
213
|
+
POSSIBILITY OF SUCH DAMAGES.
|
|
214
|
+
|
|
215
|
+
7. GENERAL
|
|
216
|
+
|
|
217
|
+
If any provision of this Agreement is invalid or unenforceable under
|
|
218
|
+
applicable law, it shall not affect the validity or enforceability of
|
|
219
|
+
the remainder of the terms of this Agreement, and without further
|
|
220
|
+
action by the parties hereto, such provision shall be reformed to the
|
|
221
|
+
minimum extent necessary to make such provision valid and enforceable.
|
|
222
|
+
|
|
223
|
+
If Recipient institutes patent litigation against any entity
|
|
224
|
+
(including a cross-claim or counterclaim in a lawsuit) alleging that the
|
|
225
|
+
Program itself (excluding combinations of the Program with other software
|
|
226
|
+
or hardware) infringes such Recipient's patent(s), then such Recipient's
|
|
227
|
+
rights granted under Section 2(b) shall terminate as of the date such
|
|
228
|
+
litigation is filed.
|
|
229
|
+
|
|
230
|
+
All Recipient's rights under this Agreement shall terminate if it
|
|
231
|
+
fails to comply with any of the material terms or conditions of this
|
|
232
|
+
Agreement and does not cure such failure in a reasonable period of
|
|
233
|
+
time after becoming aware of such noncompliance. If all Recipient's
|
|
234
|
+
rights under this Agreement terminate, Recipient agrees to cease use
|
|
235
|
+
and distribution of the Program as soon as reasonably practicable.
|
|
236
|
+
However, Recipient's obligations under this Agreement and any licenses
|
|
237
|
+
granted by Recipient relating to the Program shall continue and survive.
|
|
238
|
+
|
|
239
|
+
Everyone is permitted to copy and distribute copies of this Agreement,
|
|
240
|
+
but in order to avoid inconsistency the Agreement is copyrighted and
|
|
241
|
+
may only be modified in the following manner. The Agreement Steward
|
|
242
|
+
reserves the right to publish new versions (including revisions) of
|
|
243
|
+
this Agreement from time to time. No one other than the Agreement
|
|
244
|
+
Steward has the right to modify this Agreement. The Eclipse Foundation
|
|
245
|
+
is the initial Agreement Steward. The Eclipse Foundation may assign the
|
|
246
|
+
responsibility to serve as the Agreement Steward to a suitable separate
|
|
247
|
+
entity. Each new version of the Agreement will be given a distinguishing
|
|
248
|
+
version number. The Program (including Contributions) may always be
|
|
249
|
+
Distributed subject to the version of the Agreement under which it was
|
|
250
|
+
received. In addition, after a new version of the Agreement is published,
|
|
251
|
+
Contributor may elect to Distribute the Program (including its
|
|
252
|
+
Contributions) under the new version.
|
|
253
|
+
|
|
254
|
+
Except as expressly stated in Sections 2(a) and 2(b) above, Recipient
|
|
255
|
+
receives no rights or licenses to the intellectual property of any
|
|
256
|
+
Contributor under this Agreement, whether expressly, by implication,
|
|
257
|
+
estoppel or otherwise. All rights in the Program not expressly granted
|
|
258
|
+
under this Agreement are reserved. Nothing in this Agreement is intended
|
|
259
|
+
to be enforceable by any entity that is not a Contributor or Recipient.
|
|
260
|
+
No third-party beneficiary rights are created under this Agreement.
|
|
261
|
+
|
|
262
|
+
Exhibit A - Form of Secondary Licenses Notice
|
|
263
|
+
|
|
264
|
+
"This Source Code may also be made available under the following
|
|
265
|
+
Secondary Licenses when the conditions for such availability set forth
|
|
266
|
+
in the Eclipse Public License, v. 2.0 are satisfied: {name license(s),
|
|
267
|
+
version(s), and exceptions or additional permissions here}."
|
|
268
|
+
|
|
269
|
+
Simply including a copy of this Agreement, including this Exhibit A
|
|
270
|
+
is not sufficient to license the Source Code under Secondary Licenses.
|
|
271
|
+
|
|
272
|
+
If it is not possible or desirable to put the notice in a particular
|
|
273
|
+
file, then You may include the notice in a location (such as a LICENSE
|
|
274
|
+
file in a relevant directory) where a recipient would be likely to
|
|
275
|
+
look for such a notice.
|
|
276
|
+
|
|
277
|
+
You may add additional accurate notices of copyright ownership.
|
mpscli/__init__.py
ADDED
|
File without changes
|
mpscli/demo.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
|
|
2
|
+
from model.builder.SSolutionsRepositoryBuilder import SSolutionsRepositoryBuilder
|
|
3
|
+
|
|
4
|
+
builder = SSolutionsRepositoryBuilder()
|
|
5
|
+
#repo = builder.build('..\\..\\mps_test_projects\\mps_cli_lanuse_file_per_root')
|
|
6
|
+
repo = builder.build('..\\..\\..\\..\\E3_2.0_Solution\\solutions')
|
mpscli/model/SConcept.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
class SConcept:
|
|
3
|
+
|
|
4
|
+
def __init__(self, name, uuid):
|
|
5
|
+
self.name = name
|
|
6
|
+
self.uuid = uuid
|
|
7
|
+
self.properties = []
|
|
8
|
+
self.children = []
|
|
9
|
+
self.references = []
|
|
10
|
+
|
|
11
|
+
def print_concept_details(self):
|
|
12
|
+
print("concept: " + self.name)
|
|
13
|
+
print("\tproperties: ")
|
|
14
|
+
for property in self.properties:
|
|
15
|
+
print("\t\t" + property)
|
|
16
|
+
print("\tchildren: ")
|
|
17
|
+
for child in self.children:
|
|
18
|
+
print("\t\t" + child)
|
|
19
|
+
print("\treferences: ")
|
|
20
|
+
for reference in self.references:
|
|
21
|
+
print("\t\t" + reference)
|
|
22
|
+
print("<<<")
|
mpscli/model/SModel.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
class SModel:
|
|
4
|
+
|
|
5
|
+
def __init__(self, name, uuid, is_do_not_generate):
|
|
6
|
+
self.name = name
|
|
7
|
+
self.uuid = uuid
|
|
8
|
+
self.root_nodes = []
|
|
9
|
+
self.path_to_model_file = ""
|
|
10
|
+
self.is_do_not_generate = is_do_not_generate
|
|
11
|
+
self.uuid_2_nodes = {}
|
|
12
|
+
|
|
13
|
+
def get_nodes(self):
|
|
14
|
+
res = []
|
|
15
|
+
for r in self.root_nodes:
|
|
16
|
+
res.append(r)
|
|
17
|
+
res.extend(r.get_descendants())
|
|
18
|
+
return res
|
|
19
|
+
|
|
20
|
+
def get_node_by_uuid(self, uuid):
|
|
21
|
+
if len(self.uuid_2_nodes) == 0:
|
|
22
|
+
for n in self.get_nodes():
|
|
23
|
+
self.uuid_2_nodes[n.uuid] = n
|
|
24
|
+
return self.uuid_2_nodes[uuid]
|
mpscli/model/SNode.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
|
|
2
|
+
class SNode:
|
|
3
|
+
|
|
4
|
+
def __init__(self, uuid, concept, role_in_parent, parent):
|
|
5
|
+
self.uuid = uuid
|
|
6
|
+
self.concept = concept
|
|
7
|
+
self.role_in_parent = role_in_parent
|
|
8
|
+
self.properties = {}
|
|
9
|
+
self.references = {}
|
|
10
|
+
self.children = []
|
|
11
|
+
self.parent = parent
|
|
12
|
+
|
|
13
|
+
def get_property(self, name):
|
|
14
|
+
return self.properties.get(name)
|
|
15
|
+
|
|
16
|
+
def get_reference(self, name):
|
|
17
|
+
return self.references[name]
|
|
18
|
+
|
|
19
|
+
def get_children(self, role):
|
|
20
|
+
return list(filter(lambda c : c.role_in_parent == role, self.children))
|
|
21
|
+
|
|
22
|
+
def get_descendants(self):
|
|
23
|
+
res = []
|
|
24
|
+
self.__do_collect_descendants(self, res)
|
|
25
|
+
return res
|
|
26
|
+
|
|
27
|
+
def __do_collect_descendants(self, node, res):
|
|
28
|
+
res.extend(node.children)
|
|
29
|
+
for c in node.children:
|
|
30
|
+
self.__do_collect_descendants(c, res)
|
|
31
|
+
|
mpscli/model/SNodeRef.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
class SNodeRef:
|
|
4
|
+
|
|
5
|
+
def __init__(self, model_uuid, node_uuid):
|
|
6
|
+
self.model_uuid = model_uuid
|
|
7
|
+
self.node_uuid = node_uuid
|
|
8
|
+
|
|
9
|
+
def resolve(self, repo):
|
|
10
|
+
model = repo.get_model_by_uuid(self.model_uuid)
|
|
11
|
+
if model is None:
|
|
12
|
+
return None
|
|
13
|
+
return model.get_node_by_uuid(self.node_uuid)
|
|
14
|
+
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
|
|
2
|
+
class SRepository:
|
|
3
|
+
|
|
4
|
+
def __init__(self):
|
|
5
|
+
self.solutions = []
|
|
6
|
+
self.languages = []
|
|
7
|
+
self.uuid_2_model = {}
|
|
8
|
+
|
|
9
|
+
def find_solution_by_name(self, name):
|
|
10
|
+
for sol in self.solutions:
|
|
11
|
+
if sol.name == name:
|
|
12
|
+
return sol
|
|
13
|
+
return None
|
|
14
|
+
|
|
15
|
+
def find_model_by_name(self, name):
|
|
16
|
+
for sol in self.solutions:
|
|
17
|
+
for model in sol.models:
|
|
18
|
+
if model.name == name:
|
|
19
|
+
return model
|
|
20
|
+
return None
|
|
21
|
+
|
|
22
|
+
def find_language_by_name(self, name):
|
|
23
|
+
for lan in self.languages:
|
|
24
|
+
if lan.name == name:
|
|
25
|
+
return lan
|
|
26
|
+
return None
|
|
27
|
+
|
|
28
|
+
def find_concept_by_name(self, name):
|
|
29
|
+
for lan in self.languages:
|
|
30
|
+
for concept in lan.concepts:
|
|
31
|
+
if concept.name == name:
|
|
32
|
+
return concept
|
|
33
|
+
return None
|
|
34
|
+
|
|
35
|
+
def get_concepts(self):
|
|
36
|
+
res = []
|
|
37
|
+
for lan in self.languages:
|
|
38
|
+
res.extend(lan.concepts)
|
|
39
|
+
return res
|
|
40
|
+
|
|
41
|
+
def get_nodes(self):
|
|
42
|
+
res = []
|
|
43
|
+
for sol in self.solutions:
|
|
44
|
+
for mod in sol.models:
|
|
45
|
+
res.extend(mod.get_nodes())
|
|
46
|
+
return res
|
|
47
|
+
|
|
48
|
+
def get_nodes_of_concept(self, concept_name):
|
|
49
|
+
res = []
|
|
50
|
+
for node in self.get_nodes():
|
|
51
|
+
if node.concept.name == concept_name:
|
|
52
|
+
res.append(node)
|
|
53
|
+
return res
|
|
54
|
+
|
|
55
|
+
def get_model_by_uuid(self, uuid):
|
|
56
|
+
if len(self.uuid_2_model) == 0:
|
|
57
|
+
for sol in self.solutions:
|
|
58
|
+
for m in sol.models:
|
|
59
|
+
self.uuid_2_model[m.uuid] = m
|
|
60
|
+
return self.uuid_2_model.get(uuid)
|
mpscli/model/__init__.py
ADDED
|
File without changes
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
class NodeIdEncodingUtils:
|
|
3
|
+
|
|
4
|
+
def __init__(self):
|
|
5
|
+
self.myIndexChars = "0123456789abcdefghijklmnopqrstuvwxyz$_ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
6
|
+
self.MIN_CHAR = ord('$')
|
|
7
|
+
self.myCharToValue = {}
|
|
8
|
+
for i in range(0, len(self.myIndexChars)):
|
|
9
|
+
charValue = ord(self.myIndexChars[i])
|
|
10
|
+
self.myCharToValue[charValue - self.MIN_CHAR] = i
|
|
11
|
+
|
|
12
|
+
# transforms the node id string saved in MPS files and converts it to the proper node id as long
|
|
13
|
+
def decode_string(self, uid_string):
|
|
14
|
+
res = 0
|
|
15
|
+
c = uid_string[0]
|
|
16
|
+
value = self.myCharToValue[ord(c) - self.MIN_CHAR]
|
|
17
|
+
res = value
|
|
18
|
+
for idx in range(1, len(uid_string)):
|
|
19
|
+
res = res << 6
|
|
20
|
+
c = uid_string[idx]
|
|
21
|
+
value = self.myIndexChars.index(c)
|
|
22
|
+
res = res | value
|
|
23
|
+
return res
|
|
24
|
+
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
|
|
2
|
+
from mpscli.model.SLanguage import SLanguage
|
|
3
|
+
from mpscli.model.SConcept import SConcept
|
|
4
|
+
|
|
5
|
+
class SLanguageBuilder:
|
|
6
|
+
languages = {}
|
|
7
|
+
|
|
8
|
+
@classmethod
|
|
9
|
+
def get_language(cls, name, uuid):
|
|
10
|
+
lan = cls.languages.get(name, None)
|
|
11
|
+
if lan is None:
|
|
12
|
+
lan = SLanguage(name, uuid)
|
|
13
|
+
cls.languages[name] = lan
|
|
14
|
+
return lan
|
|
15
|
+
|
|
16
|
+
@classmethod
|
|
17
|
+
def get_concept(cls, language, concept_name, concept_uuid):
|
|
18
|
+
concept = next((c for c in language.concepts if c.name == concept_name), None)
|
|
19
|
+
if concept is None:
|
|
20
|
+
concept = SConcept(concept_name, concept_uuid)
|
|
21
|
+
language.concepts.append(concept)
|
|
22
|
+
return concept
|
|
23
|
+
|
|
24
|
+
@classmethod
|
|
25
|
+
def get_property(cls, concept, property_name):
|
|
26
|
+
node_property = next((p for p in concept.properties if p == property_name), None)
|
|
27
|
+
if node_property is None:
|
|
28
|
+
concept.properties.append(property_name)
|
|
29
|
+
node_property = property_name
|
|
30
|
+
return node_property
|
|
31
|
+
|
|
32
|
+
@classmethod
|
|
33
|
+
def get_child(cls, concept, child_name):
|
|
34
|
+
child_role = next((c for c in concept.children if c == child_name), None)
|
|
35
|
+
if child_role is None:
|
|
36
|
+
concept.children.append(child_name)
|
|
37
|
+
child_role = child_name
|
|
38
|
+
return child_role
|
|
39
|
+
|
|
40
|
+
@classmethod
|
|
41
|
+
def get_reference(cls, concept, reference_name):
|
|
42
|
+
reference_role = next((r for r in concept.references if r == reference_name), None)
|
|
43
|
+
if reference_role is None:
|
|
44
|
+
concept.references.append(reference_name)
|
|
45
|
+
reference_role = reference_name
|
|
46
|
+
return reference_role
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
from mpscli.model.SNodeRef import SNodeRef
|
|
2
|
+
from mpscli.model.SModel import SModel
|
|
3
|
+
from mpscli.model.SNode import SNode
|
|
4
|
+
from mpscli.model.builder.SLanguageBuilder import SLanguageBuilder
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class SModelBuilderBase:
|
|
8
|
+
|
|
9
|
+
def __init__(self):
|
|
10
|
+
self.index_2_concept = {}
|
|
11
|
+
self.index_2_property = {}
|
|
12
|
+
self.index_2_child_role_in_parent = {}
|
|
13
|
+
self.index_2_reference_role = {}
|
|
14
|
+
self.index_2_imported_model_uuid = {}
|
|
15
|
+
|
|
16
|
+
def extract_node(self, my_model, node_xml, parent):
|
|
17
|
+
root_node_id = node_xml.get("id")
|
|
18
|
+
root_node_concept = self.index_2_concept[node_xml.get("concept")]
|
|
19
|
+
child_role_index = node_xml.get("role")
|
|
20
|
+
if child_role_index is None:
|
|
21
|
+
child_role = None
|
|
22
|
+
else:
|
|
23
|
+
child_role = self.index_2_child_role_in_parent[child_role_index]
|
|
24
|
+
s_node = SNode(root_node_id, root_node_concept, child_role, parent)
|
|
25
|
+
for property_xml_node in node_xml.findall("property"):
|
|
26
|
+
property_role = property_xml_node.get("role")
|
|
27
|
+
property_value = property_xml_node.get("value")
|
|
28
|
+
property_name = self.index_2_property[property_role]
|
|
29
|
+
s_node.properties[property_name] = property_value
|
|
30
|
+
for ref_xml_node in node_xml.findall("ref"):
|
|
31
|
+
ref_role = ref_xml_node.get("role")
|
|
32
|
+
ref_to = ref_xml_node.get("to")
|
|
33
|
+
if ref_to is None:
|
|
34
|
+
ref_node_uuid = ref_xml_node.get("node")
|
|
35
|
+
s_node_ref = SNodeRef(my_model.uuid, ref_node_uuid)
|
|
36
|
+
else:
|
|
37
|
+
ref_model_index = ref_to[0 : ref_to.find(":")]
|
|
38
|
+
ref_node_uuid = ref_to[ref_to.find(":") + 1 : len(ref_to)]
|
|
39
|
+
s_node_ref = SNodeRef(self.index_2_imported_model_uuid[ref_model_index], ref_node_uuid)
|
|
40
|
+
ref_name = self.index_2_reference_role[ref_role]
|
|
41
|
+
s_node.references[ref_name] = s_node_ref
|
|
42
|
+
for child_node_xml in node_xml.findall("node"):
|
|
43
|
+
child_node = self.extract_node(my_model, child_node_xml, s_node)
|
|
44
|
+
s_node.children.append(child_node)
|
|
45
|
+
|
|
46
|
+
return s_node
|
|
47
|
+
@staticmethod
|
|
48
|
+
def is_model_generatable(model_xml_node):
|
|
49
|
+
return any(
|
|
50
|
+
attribute.get("name") == "doNotGenerate" and attribute.get("value") == "true"
|
|
51
|
+
for attribute in model_xml_node.findall("attribute")
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
def extract_model_core_info(self, model_xml_node):
|
|
55
|
+
model_ref = model_xml_node.get("ref")
|
|
56
|
+
model_name = model_ref[model_ref.find("(") + 1 : len(model_ref) - 1]
|
|
57
|
+
model_uuid = model_ref[0 : model_ref.find("(")]
|
|
58
|
+
model_is_do_not_generate = self.is_model_generatable(model_xml_node)
|
|
59
|
+
model = SModel(model_name, model_uuid, model_is_do_not_generate)
|
|
60
|
+
return model
|
|
61
|
+
|
|
62
|
+
def extract_imports_and_registry(self, model_xml_node):
|
|
63
|
+
imports_xml_node = model_xml_node.find("imports")
|
|
64
|
+
for import_xml_node in imports_xml_node.findall("import"):
|
|
65
|
+
import_index = import_xml_node.get("index")
|
|
66
|
+
imported_model_ref = import_xml_node.get("ref")
|
|
67
|
+
imported_model_uuid = imported_model_ref[0: imported_model_ref.find("(")]
|
|
68
|
+
self.index_2_imported_model_uuid[import_index] = imported_model_uuid
|
|
69
|
+
registry_xml_node = model_xml_node.find("registry")
|
|
70
|
+
for language_xml_node in registry_xml_node.findall("language"):
|
|
71
|
+
language_id = language_xml_node.get("id")
|
|
72
|
+
language_name = language_xml_node.get("name")
|
|
73
|
+
language = SLanguageBuilder.get_language(language_name, language_id)
|
|
74
|
+
for concept_xml_node in language_xml_node.findall("concept"):
|
|
75
|
+
concept_id = concept_xml_node.get("id")
|
|
76
|
+
concept_name = concept_xml_node.get("name")
|
|
77
|
+
concept = SLanguageBuilder.get_concept(language, concept_name, concept_id)
|
|
78
|
+
concept_index = concept_xml_node.get("index")
|
|
79
|
+
self.index_2_concept[concept_index] = concept
|
|
80
|
+
for property_xml_node in concept_xml_node.findall("property"):
|
|
81
|
+
property_name = property_xml_node.get("name")
|
|
82
|
+
property_index = property_xml_node.get("index")
|
|
83
|
+
node_property = SLanguageBuilder.get_property(concept, property_name)
|
|
84
|
+
self.index_2_property[property_index] = node_property
|
|
85
|
+
for child_xml_node in concept_xml_node.findall("child"):
|
|
86
|
+
child_name = child_xml_node.get("name")
|
|
87
|
+
child_index = child_xml_node.get("index")
|
|
88
|
+
child = SLanguageBuilder.get_child(concept, child_name)
|
|
89
|
+
self.index_2_child_role_in_parent[child_index] = child
|
|
90
|
+
for reference_xml_node in concept_xml_node.findall("reference"):
|
|
91
|
+
reference_name = reference_xml_node.get("name")
|
|
92
|
+
reference_index = reference_xml_node.get("index")
|
|
93
|
+
reference = SLanguageBuilder.get_reference(concept, reference_name)
|
|
94
|
+
self.index_2_reference_role[reference_index] = reference
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
|
|
2
|
+
import xml.etree.ElementTree as ET
|
|
3
|
+
from mpscli.model.builder.SModelBuilderBase import SModelBuilderBase
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class SModelBuilderDefaultPersistency(SModelBuilderBase):
|
|
7
|
+
|
|
8
|
+
def build(self, path):
|
|
9
|
+
tree = ET.parse(path)
|
|
10
|
+
model_xml_node = tree.getroot()
|
|
11
|
+
model = self.extract_model_core_info(model_xml_node)
|
|
12
|
+
model.path_to_model_file = path
|
|
13
|
+
self.extract_imports_and_registry(model_xml_node)
|
|
14
|
+
|
|
15
|
+
for node_xml_node in model_xml_node.findall("node"):
|
|
16
|
+
root_node = self.extract_node(model, node_xml_node, None)
|
|
17
|
+
model.root_nodes.append(root_node)
|
|
18
|
+
|
|
19
|
+
return model
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
|
|
2
|
+
from mpscli.model.builder.SModelBuilderBase import SModelBuilderBase
|
|
3
|
+
import xml.etree.ElementTree as ET
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class SModelBuilderFilePerRootPersistency(SModelBuilderBase):
|
|
7
|
+
|
|
8
|
+
def build(self, path):
|
|
9
|
+
model_file = path / '.model'
|
|
10
|
+
tree = ET.parse(model_file)
|
|
11
|
+
model_xml_node = tree.getroot()
|
|
12
|
+
model = self.extract_model_core_info(model_xml_node)
|
|
13
|
+
model.path_to_model_file = model_file
|
|
14
|
+
|
|
15
|
+
for file in path.iterdir():
|
|
16
|
+
if file.suffix == '.mpsr':
|
|
17
|
+
root_node = self.extract_root_node(model, file)
|
|
18
|
+
model.root_nodes.append(root_node)
|
|
19
|
+
|
|
20
|
+
return model
|
|
21
|
+
|
|
22
|
+
def extract_root_node(self, model, mpsr_file):
|
|
23
|
+
tree = ET.parse(mpsr_file)
|
|
24
|
+
model_xml_node = tree.getroot()
|
|
25
|
+
self.extract_imports_and_registry(model_xml_node)
|
|
26
|
+
root_node = model_xml_node.find("node")
|
|
27
|
+
return self.extract_node(model, root_node, None)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import xml.etree.ElementTree as ET
|
|
3
|
+
from mpscli.model.SSolution import SSolution
|
|
4
|
+
from mpscli.model.builder.SModelBuilderDefaultPersistency import SModelBuilderDefaultPersistency
|
|
5
|
+
from mpscli.model.builder.SModelBuilderFilePerRootPersistency import SModelBuilderFilePerRootPersistency
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class SSolutionBuilder:
|
|
9
|
+
|
|
10
|
+
def build_solution(self, path_to_msd_file):
|
|
11
|
+
solution = self.extract_solution_core_info(path_to_msd_file)
|
|
12
|
+
path_to_solution_dir = path_to_msd_file.parent
|
|
13
|
+
solution.path_to_solution_file = path_to_msd_file
|
|
14
|
+
print("building from:", path_to_solution_dir)
|
|
15
|
+
path_to_models_dir = path_to_solution_dir / 'models'
|
|
16
|
+
if not os.path.exists(path_to_models_dir):
|
|
17
|
+
print("ERROR: 'models' directory not found! No model is loaded from path: " + str(path_to_solution_dir))
|
|
18
|
+
return None
|
|
19
|
+
|
|
20
|
+
for path_to_model in path_to_models_dir.iterdir():
|
|
21
|
+
if path_to_model.is_dir():
|
|
22
|
+
builder = SModelBuilderFilePerRootPersistency()
|
|
23
|
+
else:
|
|
24
|
+
builder = SModelBuilderDefaultPersistency()
|
|
25
|
+
model = builder.build(path_to_model)
|
|
26
|
+
solution.models.append(model)
|
|
27
|
+
|
|
28
|
+
return solution
|
|
29
|
+
|
|
30
|
+
def extract_solution_core_info(self, solution_file):
|
|
31
|
+
tree = ET.parse(solution_file)
|
|
32
|
+
solution_xml_node = tree.getroot()
|
|
33
|
+
solution_name = solution_xml_node.get("name")
|
|
34
|
+
solution_uuid = solution_xml_node.get("uuid")
|
|
35
|
+
solution = SSolution(solution_name, solution_uuid)
|
|
36
|
+
return solution
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
from timeit import default_timer as timer
|
|
2
|
+
import os
|
|
3
|
+
import sys
|
|
4
|
+
import zipfile
|
|
5
|
+
import shutil
|
|
6
|
+
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from mpscli.model.SRepository import SRepository
|
|
9
|
+
from mpscli.model.builder.SLanguageBuilder import SLanguageBuilder
|
|
10
|
+
from mpscli.model.builder.SSolutionBuilder import SSolutionBuilder
|
|
11
|
+
|
|
12
|
+
class SSolutionsRepositoryBuilder:
|
|
13
|
+
|
|
14
|
+
def __init__(self):
|
|
15
|
+
self.repo = SRepository()
|
|
16
|
+
|
|
17
|
+
def build(self, path):
|
|
18
|
+
if not os.path.exists(path):
|
|
19
|
+
print("ERROR: path", path, "does not exist!")
|
|
20
|
+
sys.exit(1)
|
|
21
|
+
if not os.path.isdir(path):
|
|
22
|
+
print("ERROR: path", path, "is not a directory!")
|
|
23
|
+
sys.exit(1)
|
|
24
|
+
|
|
25
|
+
print("building model from path:", path)
|
|
26
|
+
start = timer()
|
|
27
|
+
self.collect_solutions_from_sources(path)
|
|
28
|
+
self.collect_solutions_from_jars(path)
|
|
29
|
+
self.repo.languages = list(SLanguageBuilder.languages.values())
|
|
30
|
+
stop = timer()
|
|
31
|
+
duration = (stop - start)
|
|
32
|
+
print('duration is: ' + str(duration) + ' seconds')
|
|
33
|
+
return self.repo
|
|
34
|
+
|
|
35
|
+
def collect_solutions_from_sources(self, path):
|
|
36
|
+
for pth in Path(path).rglob('*.msd'):
|
|
37
|
+
solutionBuilder = SSolutionBuilder()
|
|
38
|
+
solution = solutionBuilder.build_solution(pth)
|
|
39
|
+
if solution is not None:
|
|
40
|
+
self.repo.solutions.append(solution)
|
|
41
|
+
|
|
42
|
+
def collect_solutions_from_jars(self, path):
|
|
43
|
+
for jar_path in Path(path).rglob('*.jar'):
|
|
44
|
+
directory_where_to_extract = jar_path.parent / jar_path.name.replace(".", "_")
|
|
45
|
+
directory_where_to_extract.mkdir(parents=True, exist_ok=True)
|
|
46
|
+
with zipfile.ZipFile(jar_path) as jar:
|
|
47
|
+
jar.extractall(directory_where_to_extract)
|
|
48
|
+
print("path = ", directory_where_to_extract)
|
|
49
|
+
self.collect_solutions_from_sources(directory_where_to_extract)
|
|
50
|
+
try:
|
|
51
|
+
shutil.rmtree(directory_where_to_extract)
|
|
52
|
+
except OSError as e:
|
|
53
|
+
print("Error: %s - %s." % (e.filename, e.strerror))
|
|
File without changes
|