Beispiel #1
0
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()
Beispiel #2
0
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)
Beispiel #3
0
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)
Beispiel #4
0
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)
Beispiel #5
0
    def prepareForRun(self):
        self._is_running=True
        self.log("OK to rock")
        self._delay = int(self.getParameter("delay",0))
        if self.getParameter("model"):
            Adapter.sendInput = DelayedExecution(self,Adapter._model_guess, self._delay)
            self.log("Checking from the model")
#            from tema.model.parallellstsmodel import ParallelLstsModel as Oraakkeli
#            self._oraakkeli = Oraakkeli()
#            self._oraakkeli.loadFromFile(open(self.getParameter("model"),"r"))
            self._oraakkeli = loadModel(self.getParameter("model_type"),open(self.getParameter("model"),"r"))
            self._current_state = [self._oraakkeli.getInitialState()]
        else:
            Adapter.sendInput = DelayedExecution(self,Adapter._wild_guess, self._delay)
            self.log("Taking a guess")
Beispiel #6
0
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
Beispiel #7
0
 def prepareForRun(self):
     self._is_running = True
     self.log("OK to rock")
     self._delay = int(self.getParameter("delay", 0))
     if self.getParameter("model"):
         Adapter.sendInput = DelayedExecution(self, Adapter._model_guess,
                                              self._delay)
         self.log("Checking from the model")
         #            from tema.model.parallellstsmodel import ParallelLstsModel as Oraakkeli
         #            self._oraakkeli = Oraakkeli()
         #            self._oraakkeli.loadFromFile(open(self.getParameter("model"),"r"))
         self._oraakkeli = loadModel(self.getParameter("model_type"),
                                     open(self.getParameter("model"), "r"))
         self._current_state = [self._oraakkeli.getInitialState()]
     else:
         Adapter.sendInput = DelayedExecution(self, Adapter._wild_guess,
                                              self._delay)
         self.log("Taking a guess")
Beispiel #8
0
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
Beispiel #9
0
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()
Beispiel #10
0
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 ''
Beispiel #11
0
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 ''