@@ -160,13 +160,15 @@ def _copy_rename(self, src_library, des_library, src, des, rep):
160
160
raise e
161
161
# Remove library specific documentation.
162
162
lines = self .remove_library_specific_documentation (lines , self ._new_library_name )
163
+ # Remove library specific source code.
164
+ lines = self .remove_library_specific_modelica_code (lines , self ._new_library_name )
163
165
# Write the lines to the new file
164
166
with open (des , mode = "w" , encoding = "utf-8" ) as f_des :
165
167
f_des .writelines (lines )
166
168
167
169
@staticmethod
168
170
def remove_library_specific_documentation (file_lines , library_name ):
169
- """ Remove library specific content .
171
+ """ Remove library specific documentation .
170
172
171
173
For example, for the `Buildings` and `IDEAS` libraries, include the
172
174
section in the commented block below, but keep the comment as an html-comment
@@ -202,6 +204,50 @@ def remove_library_specific_documentation(file_lines, library_name):
202
204
203
205
return lines
204
206
207
+ @staticmethod
208
+ def remove_library_specific_modelica_code (file_lines , library_name ):
209
+ """ Remove library specific Modelica code.
210
+
211
+ For example, for the `Buildings` and `IDEAS` libraries, include the
212
+ section in the commented block below, but remove the Modelica code
213
+ for other libraries.
214
+
215
+ .. code-block:: html
216
+
217
+ //@modelica_select @remove_Buildings @remove_IDEAS
218
+ some code to be removed for
219
+ Buildings and IDEAS libraries.
220
+ //@modelica_select
221
+
222
+ :param file_lines: The lines of the file to be merged.
223
+ :return: The lines of the files, with code commented removed as indicated by the tag(s) in the comment line.
224
+ """
225
+
226
+ lines = list ()
227
+ pattern_start = "//@modelica_select_start"
228
+ pattern_end = "//@modelica_select_end"
229
+ library_token = "@remove_{}" .format (library_name )
230
+ regular = True
231
+ for lin in file_lines :
232
+ if pattern_start in lin and library_token in lin :
233
+ # Found the start of the commented section for this library.
234
+ # Set flag
235
+ regular = False
236
+ # Keep line as is
237
+ lines .append (lin )
238
+ elif pattern_end in lin :
239
+ # Found the end of the line
240
+ regular = True
241
+ # Keep line as is
242
+ lines .append (lin )
243
+ else :
244
+ if regular :
245
+ lines .append (lin )
246
+ else :
247
+ lines .append (f"// removed: { lin } " )
248
+
249
+ return lines
250
+
205
251
@staticmethod
206
252
def filter_files (file_list , pattern ):
207
253
"""
0 commit comments