@@ -274,22 +274,7 @@ class Tailoring:
274
274
with open (location , "w" ) if location != "-" else sys .stdout as f :
275
275
f .write (pretty_xml )
276
276
277
- def import_json_tailoring (self , json_tailoring ):
278
- with open (json_tailoring , "r" ) as jf :
279
- all_tailorings = json .load (jf )
280
-
281
- if 'profiles' in all_tailorings and all_tailorings ['profiles' ]:
282
- if len (all_tailorings ['profiles' ]) > 1 :
283
- raise ValueError ("The autotailor tool currently does not support multi-profile JSON tailoring." )
284
- tailoring = all_tailorings ['profiles' ][0 ]
285
- else :
286
- raise ValueError ("JSON Tailoring does not define any profiles." )
287
-
288
- self .extends = tailoring ["base_profile_id" ]
289
-
290
- self .profile_id = tailoring .get ("id" , self .profile_id )
291
- self .profile_title = tailoring .get ("title" , self .profile_title )
292
-
277
+ def _import_groups_from_tailoring (self , tailoring ):
293
278
if "groups" in tailoring :
294
279
for group_id , props in tailoring ["groups" ].items ():
295
280
if "evaluate" in props :
@@ -298,6 +283,15 @@ class Tailoring:
298
283
else :
299
284
self .groups_to_unselect .append (group_id )
300
285
286
+ def _import_variables_from_tailoring (self , tailoring ):
287
+ if "variables" in tailoring :
288
+ for variable_id , props in tailoring ["variables" ].items ():
289
+ if "value" in props :
290
+ self .add_value_change (variable_id , props ["value" ])
291
+ if "option_id" in props :
292
+ self .change_value_attribute (variable_id , "selector" , props ["option_id" ])
293
+
294
+ def _import_rules_from_tailoring (self , tailoring ):
301
295
if "rules" in tailoring :
302
296
for rule_id , props in tailoring ["rules" ].items ():
303
297
if "evaluate" in props :
@@ -309,12 +303,25 @@ class Tailoring:
309
303
if attr in props :
310
304
self .change_rule_attribute (rule_id , attr , props [attr ])
311
305
312
- if "variables" in tailoring :
313
- for variable_id , props in tailoring ["variables" ].items ():
314
- if "value" in props :
315
- self .add_value_change (variable_id , props ["value" ])
316
- if "option_id" in props :
317
- self .change_value_attribute (variable_id , "selector" , props ["option_id" ])
306
+ def import_json_tailoring (self , json_tailoring ):
307
+ with open (json_tailoring , "r" ) as jf :
308
+ all_tailorings = json .load (jf )
309
+
310
+ if 'profiles' in all_tailorings and all_tailorings ['profiles' ]:
311
+ if len (all_tailorings ['profiles' ]) > 1 :
312
+ raise ValueError ("The autotailor tool currently does not support multi-profile JSON tailoring." )
313
+ tailoring = all_tailorings ['profiles' ][0 ]
314
+ else :
315
+ raise ValueError ("JSON Tailoring does not define any profiles." )
316
+
317
+ self .extends = tailoring ["base_profile_id" ]
318
+
319
+ self .profile_id = tailoring .get ("id" , self .profile_id )
320
+ self .profile_title = tailoring .get ("title" , self .profile_title )
321
+
322
+ self ._import_groups_from_tailoring (tailoring )
323
+ self ._import_rules_from_tailoring (tailoring )
324
+ self ._import_variables_from_tailoring (tailoring )
318
325
319
326
320
327
def get_parser ():
0 commit comments