#import PartSetAPI
#from salome.shaper import model
-
-if len(sys.argv) < 2:
- raise Exception("no study given to validate")
+errCode = 0
outFolder,filename = os.path.split(sys.argv[1])
base = os.path.splitext(filename)[0]
with open(os.path.join(outFolder, base+"_valid.log"), "w") as f:
- f.write("#args = {}\n".format(len(sys.argv)))
- lastIdx = len(sys.argv)-1
- f.write("#arg[{}] = {}\n".format(lastIdx, sys.argv[lastIdx]))
+ try:
+ f.write("#args = {}\n".format(len(sys.argv)))
+ lastIdx = len(sys.argv)-1
+ f.write("#arg[{}] = {}\n".format(lastIdx, sys.argv[lastIdx]))
- salome.standalone()
- f.write("initializing SALOME\n")
- salome.salome_init(sys.argv[1], embedded=True, forced=True)
- f.write("StudyName = {}\n".format(salome.myStudyName))
- f.write("Study = {}\n".format(salome.myStudy))
+ salome.standalone()
+ f.write("initializing SALOME\n")
+ salome.salome_init(sys.argv[1], embedded=True, forced=True)
+ f.write("StudyName = {}\n".format(salome.myStudyName))
+ f.write("Study = {}\n".format(salome.myStudy))
- session = salome.naming_service.Resolve('/Kernel/Session')
- f.write("session = {}\n".format(session))
- session.emitMessage("connect_to_study")
- f.write("session = {}\n".format(session))
+ session = salome.naming_service.Resolve('/Kernel/Session')
+ f.write("session = {}\n".format(session))
+ session.emitMessage("connect_to_study")
+ f.write("session = {}\n".format(session))
- sg = SalomePyQt.SalomePyQt()
- sg.activateModule("Shaper")
- session = ModelAPI.ModelAPI_Session.get()
- aFactory = session.validators()
- aPartSet = session.moduleDocument()
- numParts = aPartSet.size("Parts")
- # f.write("NumParts = {}\n".format(numParts))
- # numFeats = aPartSet.size("Features")
- # f.write("NumFeats = {}\n".format(numFeats))
- # numBodies = aPartSet.size("Bodies")
- # f.write("NumBodies = {}\n".format(numBodies))
- # numGroups = aPartSet.size("Groups")
- # f.write("NumGroups = {}\n".format(numGroups))
- # numConsts = aPartSet.size("Construction")
- # f.write("NumConstr = {}\n".format(numConsts))
- # numFolders = aPartSet.size("Folders")
- # f.write("NumFolder = {}\n".format(numFolders))
- for partIdx in range(numParts+1):
- aPart = session.document(partIdx)
- if aPart is None:
- continue
- aPart.setActive(True)
- if partIdx == 0:
- f.write("---PartSet:------------------\n")
- else:
- f.write(f"---Part_{partIdx}:------------------\n")
- for aFeat in aPart.allFeatures():
- if aFeat.isInHistory():
- f.write(" * {} --> [{}]\n".format(aFeat.getKind(), aFeat.data().name()))
+ sg = SalomePyQt.SalomePyQt()
+ sg.activateModule("Shaper")
+ session = ModelAPI.ModelAPI_Session.get()
+ aFactory = session.validators()
+ aPartSet = session.moduleDocument()
+ numParts = aPartSet.size("Parts")
+ for partIdx in range(numParts+1):
+ aPart = session.document(partIdx)
+ if aPart is None:
+ continue
+ aPart.setActive(True)
+ if partIdx == 0:
+ f.write("---PartSet:------------------\n")
else:
- f.write(" - {}\n".format(aFeat.data().name()))
+ f.write(f"---Part_{partIdx}:------------------\n")
+
+ ## Simulate an exception during execution:
+ ##raise Exception("study failed to validate")
+ ## Cause an exception
+ #x = 1/0
+
+ for aFeat in aPart.allFeatures():
+ if aFeat.isInHistory():
+ f.write(" * {} --> [{}]\n".format(aFeat.getKind(), aFeat.data().name()))
+ else:
+ f.write(" - {}\n".format(aFeat.data().name()))
+ except Exception as ex:
+ f.write("Exception caught: {}\n".format(ex))
+ errCode = 88
- f.write("done!\n")
+ f.write("errCode = {}\n".format(errCode))
+ if errCode == 0:
+ f.write("HDF Test - PASSED\n")
+ else:
+ f.write("HDF Test - FAILED\n")
-exit()
+exit(errCode)
//
#include "SHAPERGUI_CheckBackup.h"
+#include <fstream>
#include <QDir>
#include <QFileInfo>
#include <QStringList>
// * opens the previously backed up HDF study
SHOW(aProgName);
SHOW(args);
- myProcess->setStandardOutputFile((QStringList() << myFolder << myBaseName+".log").join(aSep));
+ //myProcess->setStandardOutputFile((QStringList() << myFolder << myBaseName+".log").join(aSep));
myProcess->start(aProgName, args);
myProcess->waitForFinished(300000);
int exitStat = myProcess->exitStatus();
aResult = 99;
myProcess->deleteLater();
- return 0;
+ // Check the output of the log file
+ if (exitStat == 0 && exitCode == 0)
+ {
+ std::ifstream log((QStringList() << myFolder << myBaseName+"_valid.log").join(aSep).toStdString().c_str());
+ if (log)
+ {
+ aResult = 76;
+ std::string line;
+ while (std::getline(log, line))
+ {
+ if (line.find("HDF Test - ") == 0)
+ {
+ std::string strResult = line.substr(11);
+ if (strResult.find("PASSED") == 0)
+ {
+ MSGEL("HDF Test --> PASSED");
+ aResult = 0;
+ }
+ else if (strResult.find("FAILED") == 0)
+ {
+ MSGEL("HDF Test --> FAILED");
+ aResult = 75;
+ }
+ break;
+ }
+ }
+ }
+ else
+ {
+ std::cout << "WARNING: cannot open log file from check_validity.py script" << std::endl;
+ aResult = 77; // log file not found
+ }
+ }
+
+ return aResult;
}