Skip to content

Commit a501d14

Browse files
Fix to allow yml or yaml extension (#668)
1 parent f93efcd commit a501d14

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

core/src/main/python/compare_model.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
import sys, os, traceback
1818

1919
from java.lang import System
20+
import java.io.File as JFile
2021
import java.io.FileOutputStream as JFileOutputStream
2122
import java.io.IOException as JIOException
2223
import java.io.PrintWriter as JPrintWriter
2324
import oracle.weblogic.deploy.util.TranslateException as TranslateException
2425
from oracle.weblogic.deploy.util import CLAException
26+
from oracle.weblogic.deploy.util import FileUtils
2527
from oracle.weblogic.deploy.util import VariableException
2628
from oracle.weblogic.deploy.compare import CompareException
2729
from oracle.weblogic.deploy.exception import ExceptionHelper
@@ -416,7 +418,7 @@ def compare(self):
416418
# validate models first
417419

418420
try:
419-
if os.path.splitext(self.current_dict_file)[1].lower() == ".yaml":
421+
if FileUtils.isYamlFile(JFile(os.path.splitext(self.current_dict_file)[1].lower())):
420422
model_file_name = self.current_dict_file
421423
FileToPython(model_file_name, True).parse()
422424
model_file_name = self.past_dict_file
@@ -572,21 +574,17 @@ def main():
572574
if os.path.isdir(f):
573575
raise CLAException("Model %s is a directory" % f)
574576

575-
model1_ext = os.path.splitext(model1)[1]
576-
model2_ext = os.path.splitext(model2)[1]
577+
model1_file = JFile(model1)
578+
model2_file = JFile(model2)
577579

578-
validated = False
579-
for ext in [ '.yaml', '.json' ]:
580-
if model1_ext.lower() == ext:
581-
if model2_ext.lower() != model1_ext.lower():
582-
raise CLAException("Model %s is not a %s file " % model2, ext)
583-
else:
584-
validated = True
585-
break
586-
587-
if not validated:
580+
if not (FileUtils.isYamlFile(model1_file) or FileUtils.isJsonFile(model1_file)):
588581
raise CLAException("Model extension must be either yaml or json")
589582

583+
if not (FileUtils.isYamlFile(model1_file) and FileUtils.isYamlFile(model2_file)
584+
or FileUtils.isJsonFile(model1_file) and FileUtils.isJsonFile(model2_file)):
585+
ext = os.path.splitext(model1)[1]
586+
raise CLAException("Model %s is not a %s file " % (model2, ext))
587+
590588
obj = ModelFileDiffer(model1, model2, model_context, _outputdir)
591589
rc = obj.compare()
592590
if rc == VALIDATION_FAIL:

0 commit comments

Comments
 (0)