def main(): model_file, color_scheme, dot_file, options = parse_args() dot_object = None file_object = None try: try: model_type = options.format if not model_type: model_type = getModelType(model_file) if not model_type: print >>sys.stderr, "%s: Error. Unknown model type. Specify model type using '-f'" % os.path.basename(sys.argv[0]) sys.exit(1) if model_file == "-": file_object=sys.stdin else: file_object=open(model_file) if dot_file == "-": dot_object=sys.stdout else: dot_object=open(dot_file,'w') m=loadModel(model_type, file_object) visualise(m,dot_object,not options.no_stateprops, not options.no_actions, "TEMA-Model %s" % model_file, options.compact, options.colored, color_scheme ) except Exception, e: print >>sys.stderr,e sys.exit(1) finally: if file_object and model_file != "-": file_object.close() if dot_object and dot_file != "-": dot_object.close()
def main(): modelfile,options=readArgs() if options.testdata: testdata=load_testdata(options.testdata) else: testdata=None try: modeltype=options.format if not modeltype: modeltype = getModelType(modelfile) if not modeltype: print >>sys.stderr, "%s: Error. Unknown model type. Specify model type using '-f'" % os.path.basename(sys.argv[0]) sys.exit(1) if modelfile == "-": file_object=sys.stdin else: file_object=open(modelfile) m=loadModel(modeltype,file_object) except Exception, e: print >>sys.stderr,e sys.exit(1)
def main(): modelfile, options = readArgs() if options.testdata: testdata = load_testdata(options.testdata) else: testdata = None try: modeltype = options.format if not modeltype: modeltype = getModelType(modelfile) if not modeltype: print >> sys.stderr, "%s: Error. Unknown model type. Specify model type using '-f'" % os.path.basename( sys.argv[0]) sys.exit(1) if modelfile == "-": file_object = sys.stdin else: file_object = open(modelfile) m = loadModel(modeltype, file_object) except Exception, e: print >> sys.stderr, e sys.exit(1)
def convert(options, filename): format = options.format outputfilename = options.output if not format: format = getModelType(filename) if not format: print >>sys.stderr, "%s: Error. Unknown model type. Specify model type using '-f'" % os.path.basename(sys.argv[0]) sys.exit(1) if filename == "-": modelfile=sys.stdin else: modelfile=open(filename) model = None try: model = loadModel(format,modelfile) finally: modelfile.close() if outputfilename != "-": out = open(outputfilename, 'w') try: convert_to_lsts(model, out) finally: out.close() else: convert_to_lsts(model, sys.stdout)
def main(): structure, files, options = readArgs() commons = { 'multi': COMMONS_MULTITARGET, 'single': COMMONS_SINGLETARGET }[structure] models = [] for filename in files: if options.format: modelType = options.format else: modelType = getModelType(filename) if modelType is None and filename.endswith('.analysis'): file = open(filename) try: content = file.read() finally: file.close() models.append(parseresult(content)) elif modelType is None: print >> sys.stderr, "%s: Error. Unknown model type. Specify model type using '-f'" % os.path.basename( sys.argv[0]) sys.exit(1) else: model = None if filename == "-": file = sys.stdin else: file = open(filename) try: model = loadModel(modelType, file) finally: file.close() models.append(model) results = analyseModels(models, commons) print for nameresult in zip(files, results[0]): printresult(nameresult[0], nameresult[1]) print printresult('Estimated total', results[1]) print
def setParameter(self, name, value): self.log("Parameter: %s: %s" % (name, str(value))) if not name in self._allowed_parameters: print __doc__ raise AdapterError("Illegal adapter parameter: '%s'." % name) if name == "model": param = value.split(":") model_file = param[0] if len(param) == 2: model_type = param[1] else: model_type = getModelType(model_file) if model_type == None: model_type = "parallellstsmodel" adapter.Adapter.setParameter(self, name, model_file) adapter.Adapter.setParameter(self, "model_type", model_type) else: adapter.Adapter.setParameter(self, name, value)
def setParameter(self,name,value): self.log("Parameter: %s: %s" % ( name, str(value) ) ) if not name in self._allowed_parameters: print __doc__ raise AdapterError("Illegal adapter parameter: '%s'." % name) if name == "model": param = value.split(":") model_file = param[0] if len(param) == 2: model_type = param[1] else: model_type = getModelType(model_file) if model_type == None: model_type = "parallellstsmodel" adapter.Adapter.setParameter(self,name,model_file) adapter.Adapter.setParameter(self,"model_type",model_type) else: adapter.Adapter.setParameter(self,name,value)
def main(): structure,files,options = readArgs() commons = {'multi':COMMONS_MULTITARGET, 'single':COMMONS_SINGLETARGET}[structure] models = [] for filename in files: if options.format: modelType = options.format else: modelType = getModelType(filename) if modelType is None and filename.endswith('.analysis'): file = open(filename) try: content = file.read() finally: file.close() models.append(parseresult(content)) elif modelType is None: print >>sys.stderr, "%s: Error. Unknown model type. Specify model type using '-f'" % os.path.basename(sys.argv[0]) sys.exit(1) else: model = None if filename == "-": file = sys.stdin else: file = open(filename) try: model = loadModel(modelType,file) finally: file.close() models.append(model) results = analyseModels(models, commons) print for nameresult in zip(files, results[0]): printresult(nameresult[0], nameresult[1]) print printresult('Estimated total', results[1]) print
def main(): model_file, color_scheme, dot_file, options = parse_args() dot_object = None file_object = None try: try: model_type = options.format if not model_type: model_type = getModelType(model_file) if not model_type: print >> sys.stderr, "%s: Error. Unknown model type. Specify model type using '-f'" % os.path.basename( sys.argv[0]) sys.exit(1) if model_file == "-": file_object = sys.stdin else: file_object = open(model_file) if dot_file == "-": dot_object = sys.stdout else: dot_object = open(dot_file, 'w') m = loadModel(model_type, file_object) visualise(m, dot_object, not options.no_stateprops, not options.no_actions, "TEMA-Model %s" % model_file, options.compact, options.colored, color_scheme) except Exception, e: print >> sys.stderr, e sys.exit(1) finally: if file_object and model_file != "-": file_object.close() if dot_object and dot_file != "-": dot_object.close()
def validateModel(modelName, modelFormat, modelType): if not modelFormat: modelFormat = getModelType(modelName) if modelType: modelType = eval("ModelValidator.%s" % modelType.upper()) else: modelFormats = ["mdm", "lsts"] for format in modelFormats: if modelName.endswith(".refined.%s" % format): modelType = ModelValidator.REFINED_MACHINE elif modelName.endswith("-im.%s" % format): modelType = ModelValidator.INITIALIZATION_MACHINE elif modelName.endswith("-lm.%s" % format): modelType = ModelValidator.LAUNCH_MACHINE elif modelName.endswith("-rm.%s" % format): modelType = ModelValidator.REFINEMENT_MACHINE elif modelName.endswith(".%s" % format): modelType = ModelValidator.ACTION_MACHINE elif modelName.endswith(".ext") or modelName.endswith( ".parallellsts") or modelName.endswith(".parallel"): modelType = ModelValidator.COMPOSED_MACHINE if modelType is not None: break else: print 'File %s is in unknown format' % modelName print '' return model = None if modelName == "-": modelFile = sys.stdin else: modelFile = open(modelName) try: model = loadModel(modelFormat, modelFile) finally: if modelName != "-": modelFile.close() errors = [] warnings = [] validator = ModelValidator(model) lock = validator.beginValidation(modelType, errors, warnings) if lock == None: print 'Model %s is of an unknown type.' % modelName print '' return while True: sleep(0.1) if not lock.locked(): break pruneErrors(errors) pruneErrors(warnings) for i in errors + warnings: for j in i[1]: if j[:4] == 'path' and i[1][j] != None: i[1][j] = [str(k) for k in i[1][j]] if (len(errors) == 0 and len(warnings) == 0): print 'Model %s is valid.' % modelName else: if (len(errors) > 0): print 'Errors in model %s:\n' % modelName +\ str([(i[0], ModelValidator.defaultErrorMessages[i[0]] % i[1]) for i in errors]) if (len(warnings) > 0): print 'Warnings in model %s:\n' % modelName +\ str([(i[0], ModelValidator.defaultErrorMessages[i[0]] % i[1]) for i in warnings]) print ''
def validateModel(modelName,modelFormat,modelType): if not modelFormat: modelFormat = getModelType(modelName) if modelType: modelType = eval("ModelValidator.%s" % modelType.upper()) else: modelFormats = [ "mdm","lsts" ] for format in modelFormats: if modelName.endswith(".refined.%s" % format ): modelType = ModelValidator.REFINED_MACHINE elif modelName.endswith("-im.%s" % format ): modelType = ModelValidator.INITIALIZATION_MACHINE elif modelName.endswith("-lm.%s" % format ): modelType = ModelValidator.LAUNCH_MACHINE elif modelName.endswith("-rm.%s" % format ): modelType = ModelValidator.REFINEMENT_MACHINE elif modelName.endswith(".%s" % format ): modelType = ModelValidator.ACTION_MACHINE elif modelName.endswith(".ext") or modelName.endswith(".parallellsts") or modelName.endswith(".parallel"): modelType = ModelValidator.COMPOSED_MACHINE if modelType is not None: break else: print 'File %s is in unknown format' % modelName print '' return model = None if modelName == "-": modelFile = sys.stdin else: modelFile = open(modelName) try: model = loadModel(modelFormat,modelFile) finally: if modelName != "-": modelFile.close() errors = [] warnings = [] validator = ModelValidator(model) lock = validator.beginValidation(modelType, errors, warnings) if lock == None: print 'Model %s is of an unknown type.' % modelName print '' return while True: sleep(0.1) if not lock.locked(): break pruneErrors(errors) pruneErrors(warnings) for i in errors + warnings: for j in i[1]: if j[:4] == 'path' and i[1][j] != None: i[1][j] = [str(k) for k in i[1][j]] if (len(errors) == 0 and len(warnings) == 0): print 'Model %s is valid.' % modelName else: if (len(errors) > 0): print 'Errors in model %s:\n' % modelName +\ str([(i[0], ModelValidator.defaultErrorMessages[i[0]] % i[1]) for i in errors]) if (len(warnings) > 0): print 'Warnings in model %s:\n' % modelName +\ str([(i[0], ModelValidator.defaultErrorMessages[i[0]] % i[1]) for i in warnings]) print ''