24
24
import oracle .weblogic .deploy .util .TranslateException as TranslateException
25
25
from oracle .weblogic .deploy .util import CLAException
26
26
from oracle .weblogic .deploy .util import FileUtils
27
+ from oracle .weblogic .deploy .util import PyOrderedDict
27
28
from oracle .weblogic .deploy .util import VariableException
28
29
from oracle .weblogic .deploy .compare import CompareException
29
30
from oracle .weblogic .deploy .exception import ExceptionHelper
@@ -86,7 +87,7 @@ def __process_args(args):
86
87
class ModelDiffer :
87
88
88
89
def __init__ (self , current_dict , past_dict ):
89
- self .final_changed_model = dict ()
90
+ self .final_changed_model = PyOrderedDict ()
90
91
self .current_dict = current_dict
91
92
self .past_dict = past_dict
92
93
self .set_current = sets .Set ()
@@ -182,7 +183,7 @@ def is_dict(self,key):
182
183
:param key: key of the dictionary
183
184
:return: true if it is a dictionary otherwise false
184
185
"""
185
- if self .current_dict .has_key (key ) and isinstance (self .current_dict [key ],dict ):
186
+ if self .current_dict .has_key (key ) and isinstance (self .current_dict [key ], PyOrderedDict ):
186
187
return 1
187
188
else :
188
189
return 0
@@ -274,7 +275,7 @@ def _is_alias_folder(self, path):
274
275
275
276
return found
276
277
277
- def _add_results (self , ar_changes , is_delete = False ):
278
+ def _add_results (self , ar_changes , is_delete = False , is_change = False ):
278
279
"""
279
280
Update the differences in the final model dictionary with the changes
280
281
:param ar_changes: Array of changes in delimited format
@@ -290,40 +291,47 @@ def _add_results(self, ar_changes, is_delete=False):
290
291
if not found_in_allowable_delete :
291
292
compare_msgs .add (('WLSDPLY-05701' ,item ))
292
293
continue
293
-
294
- splitted = item .split (PATH_TOKEN ,1 )
295
- n = len (splitted )
296
- result = dict ()
297
- walked = []
294
+ splitted = item .split (PATH_TOKEN ,1 )
295
+ n = len (splitted )
296
+ result = PyOrderedDict ()
297
+ walked = []
298
298
299
299
while n > 1 :
300
- tmp = dict ()
301
- tmp [splitted [0 ]]= dict ()
300
+ tmp = PyOrderedDict ()
301
+ tmp [splitted [0 ]] = PyOrderedDict ()
302
302
if len (result ) > 0 :
303
303
# traverse to the leaf
304
- leaf = result
304
+ leaf = result
305
305
for k in walked :
306
306
leaf = leaf [k ]
307
- leaf [splitted [0 ]]= dict ()
307
+ leaf [splitted [0 ]] = PyOrderedDict ()
308
308
walked .append (splitted [0 ])
309
309
else :
310
- result = tmp
310
+ result = tmp
311
311
walked .append (splitted [0 ])
312
- splitted = splitted [1 ].split (PATH_TOKEN ,1 )
313
- n = len (splitted )
312
+ splitted = splitted [1 ].split (PATH_TOKEN ,1 )
313
+ n = len (splitted )
314
314
#
315
315
# result is the dictionary format
316
316
#
317
317
leaf = result
318
- value_tree = self .current_dict
318
+ if is_change :
319
+ value_tree = self .past_dict
320
+ else :
321
+ value_tree = self .current_dict
319
322
for k in walked :
320
323
leaf = leaf [k ]
321
- value_tree = value_tree [k ]
324
+ value_tree = value_tree [k ]
322
325
#
323
326
# walk the current dictionary and set the value
324
327
#
325
328
if value_tree :
326
- leaf [splitted [0 ]] = value_tree [splitted [0 ]]
329
+ if is_change :
330
+ leaf ['# - ' + splitted [0 ]] = value_tree [splitted [0 ]]
331
+ else :
332
+ if value_tree [splitted [0 ]] is not None and not isinstance (value_tree [splitted [0 ]], PyOrderedDict ):
333
+ self ._add_results (ar_changes , is_delete , is_change = True )
334
+ leaf [splitted [0 ]] = value_tree [splitted [0 ]]
327
335
else :
328
336
leaf [splitted [0 ]] = None
329
337
@@ -348,12 +356,12 @@ def _add_results(self, ar_changes, is_delete=False):
348
356
del pointer_dict [parent_key ][app_key ]
349
357
# Special handling for deleting all resources in high level
350
358
if split_delete_length == 2 and app_key != 'WebAppContainer' :
351
- pointer_dict [parent_key ][app_key ] = dict ()
359
+ pointer_dict [parent_key ][app_key ] = PyOrderedDict ()
352
360
old_keys = self .past_dict [parent_key ][app_key ].keys ()
353
361
for old_key in old_keys :
354
- pointer_dict [parent_key ][app_key ]['!' + old_key ] = dict ()
362
+ pointer_dict [parent_key ][app_key ]['!' + old_key ] = PyOrderedDict ()
355
363
else :
356
- pointer_dict [parent_key ]['!' + app_key ] = dict ()
364
+ pointer_dict [parent_key ]['!' + app_key ] = PyOrderedDict ()
357
365
358
366
def merge_dictionaries (self , dictionary , new_dictionary ):
359
367
"""
@@ -367,7 +375,7 @@ def merge_dictionaries(self, dictionary, new_dictionary):
367
375
dictionary [key ] = new_value
368
376
else :
369
377
value = dictionary [key ]
370
- if isinstance (value , dict ) and isinstance (new_value , dict ):
378
+ if isinstance (value , PyOrderedDict ) and isinstance (new_value , PyOrderedDict ):
371
379
self .merge_dictionaries (value , new_value )
372
380
else :
373
381
dictionary [key ] = new_value
@@ -542,6 +550,7 @@ def get_compare_msgs(self):
542
550
"""
543
551
return compare_msgs
544
552
553
+
545
554
def debug (format_string , * arguments ):
546
555
"""
547
556
Generic debug code.
@@ -553,6 +562,7 @@ def debug(format_string, *arguments):
553
562
else :
554
563
_logger .finest (format_string , arguments )
555
564
565
+
556
566
def main ():
557
567
"""
558
568
The main entry point for the discoverDomain tool.
@@ -657,6 +667,7 @@ def main():
657
667
_logger .severe ('WLSDPLY-05704' , eeString )
658
668
System .exit (2 )
659
669
670
+
660
671
def format_message (key , * args ):
661
672
"""
662
673
Get message using the bundle.
@@ -666,6 +677,7 @@ def format_message(key, *args):
666
677
"""
667
678
return ExceptionHelper .getMessage (key , list (args ))
668
679
680
+
669
681
if __name__ == "__main__" :
670
682
main ()
671
683
0 commit comments