Exemplo n.º 1
0
    def check_libraries(self):
        """Build Dymola model according to the settings"""
        temporary_directory = self.generate_fs()

        model_build_queue = ModelBuildQueue(self.model_name_list, self.__libraries_required,
                                      __env_configuration__.build_dir, temporary_directory)

        model_build_queue.initialize()
        # dymola.ExecuteCommand(u"Advanced.TranslationInCommandLog=true;\n")
        dymola = None
        try:
            dymola = DymolaInterface(__env_configuration__.dymola_path)
            self.load_libraries_mos(dymola)
            errorLog = ''
            for library in self.__libraries_required:
                dymola.checkModel(self.__get_modelica_lib_name(library["library"]))
                errorLog += dymola.getLastError()
            if errorLog != '':
                raise Exception(errorLog)
        except Exception as exception:
            raise exception
        finally:
            if dymola is not None:
                dymola.close()
                dymola = None
Exemplo n.º 2
0
	def _CreateIBPSALog(self):
		from dymola.dymola_interface import DymolaInterface
		from dymola.dymola_exception import DymolaException
		import buildingspy.development.regressiontest as u
		
		""" Check the IBPSA Model Automatical """	
		cmd = "git clone https://github.com/ibpsa/modelica-ibpsa.git"
		returned_value = os.system(cmd)  # returns the exit code in unix
		print('returned value:', returned_value)
		cmd = "cd modelica-ibpsa-master"
		os.system(cmd)
		Library = IBPSA/package.mo
		ut = u.Tester(tool = self.tool)
		### Set Number of Threads
		ut.setNumberOfThreads(self.n_pro)
		### Set GUI Show
		ut.showGUI(self.show_gui)
		### Set in Batch Mode
		ut.batchMode(self.batch)
		### Sets the Dymola path to activate the GUI
		
		dymola = DymolaInterface(dymolapath="/usr/local/bin/dymola")
		### Writes all information in the log file, not only the last entries
		dymola.ExecuteCommand("Advanced.TranslationInCommandLog:=true;")
		dym_sta_lic_available = dymola.ExecuteCommand('RequestOption("Standard");')
		if not dym_sta_lic_available:
			dymola.ExecuteCommand('DymolaCommands.System.savelog("Log_NO_DYM_STANDARD_LIC_AVAILABLE.txt");')
			print("No Dymola License is available")
			dymola.close()
			exit(1)
		else:
			print("Dymola License is available")
	
		
		PackageCheck = dymola.openModel(Library)
		if PackageCheck == True:
			print("Found AixLib Library and start Checkmodel Tests \n Check Package " + self.Package+" \n")
		elif PackageCheck == None:
			print("Library Path is wrong. Please Check Path of AixLib Library Path")
			exit(1)
		result=dymola.checkModel(self.Package)
		dymola.savelog(self.Package+"-log.txt")
		Log = dymola.getLastError()
		if result == True:
			print('\n Check of Package '+self.Package+' was Successful! \n')
			dymola.close()
			#exit(0)
		if result == False:
			print('\n ModelCheck Failed in Package ' + self.Package+ ' Show Savelog \n')
			print(Log)
			dymola.clearlog()
			dymola.close()
Exemplo n.º 3
0
def _python_Interface():
    from dymola.dymola_interface import DymolaInterface
    from dymola.dymola_exception import DymolaException

    dymola = DymolaInterface(showwindow=True)
    dymola.openModel("D:/Gitlab/GitLabCI/AixLib/package.mo")

    result = dymola.checkModel(
        "AixLib.Fluid.Actuators.Valves.ExpansionValves.SimpleExpansionValves.IsenthalpicExpansionValve"
    )
    print(result)
    Log = dymola.getLastError()
    print(Log)
    #Errorlog = dymola.getLastErrorLog()
    #print(Errorlog)
    dymola.savelog("Fluid-log.txt")
    dymola.close()
    if result == True:
        print('\n Check was Successful! \n')
        exit(0)
    if result == False:
        print('\n Error: Look in Savelog \n')
        exit(1)
Exemplo n.º 4
0
	def _WriteWhiteList(self):
		#_listAllModel
		#rootdir = r"D:\Gitlab\modelica-ibpsa\IBPSA"
		Package = self.Package.replace("AixLib","IBPSA")
		Package = Package.split(".")[0]
		Package = Package.replace(".",os.sep)
		rootdir = "IBPSA"+os.sep+Package
		
		ModelList = []
		for subdir, dirs, files in os.walk(rootdir):
			for file in files:
				filepath = subdir + os.sep + file
				if filepath.endswith(".mo") and file != "package.mo":
					model = filepath
					model = model.replace(os.sep,".")
					model = model[model.rfind("IBPSA"):model.rfind(".mo")]
					ModelList.append(model)
		#_CheckModel
		from dymola.dymola_interface import DymolaInterface
		from dymola.dymola_exception import DymolaException
		import buildingspy.development.regressiontest as u
			
		ut = u.Tester(tool = self.tool)
		### Set Number of Threads
		ut.setNumberOfThreads(self.n_pro)
		### Set GUI Show
		ut.showGUI(self.show_gui)
		### Set in Batch Mode
		ut.batchMode(self.batch)
		### Sets the Dymola path to activate the GUI
		if platform.system()  == "Windows":
			dymola = DymolaInterface()
		else:
			dymola = DymolaInterface(dymolapath="/usr/local/bin/dymola")
		### Writes all information in the log file, not only the last entries
		#dymola.ExecuteCommand("Advanced.TranslationInCommandLog:=true;")
		Library = "IBPSA"+os.sep+"IBPSA"+os.sep+"package.mo"
		dymola.ExecuteCommand("Advanced.TranslationInCommandLog:=true;")
		dym_sta_lic_available = dymola.ExecuteCommand('RequestOption("Standard");')
		if not dym_sta_lic_available:
			dymola.ExecuteCommand('DymolaCommands.System.savelog("Log_NO_DYM_STANDARD_LIC_AVAILABLE.txt");')
			print("No Dymola License is available")
			dymola.close()
			exit(1)
		else:
			print("Dymola License is available")
	
		PackageCheck = dymola.openModel(Library)
		
		if PackageCheck == True:
			print("Found IBPSA Library and start Checkmodel Tests \n Check Package " + self.Package+" \n")
		elif PackageCheck == False:
			print("Library Path is wrong. Please Check Path of IBPSA Library Path")
			exit(1)
		## Check the Package
		if len(ModelList) == 0:
			print("Wrong path")
			exit(1)
		ErrorList = []	
		for i in ModelList:
			result=dymola.checkModel(i)
			if result == True:
				print('\n Successful: '+i+'\n')
			if result == False:
				print('\ Error: '+i+'\n')
				Log = dymola.getLastError()
				print(Log)
				ErrorList.append(i)
		dymola.savelog("IBPSA-log.txt")
		dymola.close()
		IBPSA_PackageName = []
		### Write the Package Names of IBPSA
		for i in ModelList:
			i = i.split(".")
			i = i[1]
			if i not in IBPSA_PackageName:
				IBPSA_PackageName.append(i)
		filename= "bin"+os.sep+"03_WhiteLists"+os.sep+"WhiteList_CheckModel.txt"
		file = open(filename,"w")
		
		
		for i in IBPSA_PackageName:
			List  = []
			for l in ErrorList:
				Package = l.split(".")[1]
				if Package == i:
					List.append(l)
			file.write(i+"\n"+str(List)+"\n"+"\n")
		file.close()
		print("Write Whitelist")
Exemplo n.º 5
0
	def _SimulateModel(self):
		from dymola.dymola_interface import DymolaInterface
		from dymola.dymola_exception import DymolaException
		import buildingspy.development.regressiontest as u
		ut = u.Tester(tool = self.tool)
		### Set Number of Threads
		ut.setNumberOfThreads(self.n_pro)
		### Set GUI Show
		ut.showGUI(self.show_gui)
		### Set in Batch Mode
		ut.batchMode(self.batch)
		### Sets the Dymola path to activate the GUI
		if platform.system()  == "Windows":
			dymola = DymolaInterface()
		else:
			dymola = DymolaInterface(dymolapath="/usr/local/bin/dymola")
		### Writes all information in the log file, not only the last entries
		dymola.ExecuteCommand("Advanced.TranslationInCommandLog:=true;")
		dym_sta_lic_available = dymola.ExecuteCommand('RequestOption("Standard");')
		if not dym_sta_lic_available:
			dymola.ExecuteCommand('DymolaCommands.System.savelog("Log_NO_DYM_STANDARD_LIC_AVAILABLE.txt");')
			print("No Dymola License is available")
			dymola.close()
			exit(1)
		else:
			print("Dymola License is available")
	
		
		PackageCheck = dymola.openModel(self.Library)
		if PackageCheck == True:
			print("Found AixLib Library and start Checkmodel Tests \n Check Package " + self.Package+" \n")
		elif PackageCheck == None:
			print("Library Path is wrong. Please Check Path of AixLib Library Path")
			exit(1)
		
		ErrorList = []
		if self.Changedmodels == False:	
			ModelList = ValidateTest._listAllExamples(self)
			if len(ModelList) == 0:
				print("Wrong Path")
				exit(0)
			for i in ModelList:
				result=dymola.checkModel(i,simulate=True)
				if result == True:
					print('\n Successful: '+i+'\n')
				if result == False:
					print("Second Check Test")
					result=dymola.checkModel(i,simulate=True)
					if result == True:
						print('\n Successful: '+i+'\n')
					if result == False:
						ErrorList.append(i)
						Log = dymola.getLastError()
						print('\n Error: '+i+'\n')
						print(Log)
		
		if self.Changedmodels == True:
			list_path = 'bin'+os.sep+'03_WhiteLists'+os.sep+'changedmodels.txt'
			list_mo_models = git_models(".mo",self.Package, list_path)
			model_list= list_mo_models.sort_mo_models()
			ErrorList = []
			for i in model_list:
				result=dymola.checkModel(i,simulate=True)
				if result == True:
					print('\n Successful: '+i+'\n')
				if result == False:
					print("Second Check Test")
					result=dymola.checkModel(i,simulate=True)
					if result == True:
						print('\n Successful: '+i+'\n')
					if result == False:
						ErrorList.append(i)
						Log = dymola.getLastError()
						print('\n Error: '+i+'\n')
						print(Log)		
		dymola.savelog(self.Package+"-log.txt")
		dymola.close()
		logfile = self.Package+"-log.txt"
		ValidateTest._WriteErrorlog(self,logfile)
		return ErrorList
Exemplo n.º 6
0
def _WriteWhiteList():
    #_listAllModel
    rootdir = r"D:\Gitlab\modelica-ibpsa\IBPSA"
    #rootdir = self.Package
    ModelList = []

    for subdir, dirs, files in os.walk(rootdir):
        for file in files:
            filepath = subdir + os.sep + file
            if filepath.endswith(".mo") and file != "package.mo":
                model = filepath
                if platform.system() == "Windows":
                    model = model.replace("\\", ".")
                else:
                    model = model.replace("//", ".")

                model = model[model.rfind("IBPSA"):model.rfind(".mo")]
                ModelList.append(model)

    #_CheckModel
    from dymola.dymola_interface import DymolaInterface
    from dymola.dymola_exception import DymolaException
    import buildingspy.development.regressiontest as u

    #ut = u.Tester(tool = self.tool)
    ### Set Number of Threads
    #ut.setNumberOfThreads(self.n_pro)
    ### Set GUI Show
    #ut.showGUI(self.show_gui)
    ### Set in Batch Mode
    #ut.batchMode(self.batch)
    ### Sets the Dymola path to activate the GUI
    if platform.system() == "Windows":
        dymola = DymolaInterface()
    else:
        dymola = DymolaInterface(dymolapath="/usr/local/bin/dymola")
    ### Writes all information in the log file, not only the last entries
    dymola.ExecuteCommand("Advanced.TranslationInCommandLog:=true;")
    Library = "IBPSA/package.mo"
    PackageCheck = dymola.openModel(Library)
    if PackageCheck == True:
        print(
            "Found AixLib Library and start Checkmodel Tests \n Check Package "
            + self.Package + " \n")
    elif PackageCheck == None:
        print(
            "Library Path is wrong. Please Check Path of AixLib Library Path")
        exit(1)
    ## Check the Package

    ErrorList = []

    for i in ModelList:
        result = dymola.checkModel(i)

        if result == True:
            print('\n Check of Package ' + i + ' was Successful! \n')

            #dymola.close()
            #return 0
            #exit(0)

        if result == False:
            #print('\n ModelCheck Failed in Package ' + i + ' Show Savelog \n')
            ErrorList.append(i)
            #print(Log)

            #dymola.clearlog()
            #dymola.close()
            #return 1
            #exit(1)"""
    dymola.close()
    IBPSA_PackageName = []
    ### Write the Package Names of IBPSA
    for i in ModelList:
        i = i.split(".")
        i = i[1]
        if i not in IBPSA_PackageName:
            IBPSA_PackageName.append(i)

    filename = r"D:\Gitlab\GitLabCI\WhiteLists\CheckModel\WhiteList_CheckModel.txt"

    file = open(filename, "w")

    for i in IBPSA_PackageName:
        List = []
        for l in ModelList:
            Package = l.split(".")[1]

            if Package == i:
                List.append(l)

        file.write(i + "\n" + str(List) + "\n" + "\n")

    file.close()

    print("Write Whitelist")