def main(*args, **kwargs):
    usage = """
        Usage: ./pnml_comparator_script.py <.ini config filename>

        Config file options:
     %s\n
NOTE: Do you have the needed environment variables?
    - XES : Path to .xes file with traces (for running PacH)
    - PNML : Path to .pnml file with Petri net model (for simplifying PROM models)
    - NXES : Path to .xes file with negative traces
    - PETRI : Path where simplified .pnml files should be moved to after script ends
    - STATS : Path where statistic files should be moved to after script ends
  IMPORTANT: NO PATH MUST END IN '/' (it is added automatically)
    """%(config_options)
    if not check_argv(sys.argv, minimum=1, maximum=4):
        print usage
        ret = -1
    else:
        ret = 0
        try:
            config_file = sys.argv[1]
            if not config_file.endswith('.ini'):
                print config_file, ' does not end in .ini. It should...'
                raise Exception('Filename has wrong extension')
            if not isfile(config_file):
                raise Exception("No such file")
            if '--debug' in sys.argv:
                pdb.set_trace()
            for filename, arguments in parse_config(config_file):
                comparator = ComparatorPnml(filename, **arguments)
                complexity = comparator.compare()
                logger.info('%s complexity -> %s',filename,complexity)
                comparator.generate_pnml()
                comparator.generate_outputs()
                comparator.check_hull()
            pnml_folder,out_folder = parse_config_output(config_file)
            pwd = os.getcwd()
            for basename in os.listdir(pwd):
                if basename.endswith('.pnml'):
                    pnml_file = os.path.join(pwd, basename)
                    if os.path.isfile(pnml_file):
                        shutil.copy2(pnml_file, pnml_folder)
                        os.remove(pnml_file)
                elif basename.endswith('.out'):
                    out_file = os.path.join(pwd, basename)
                    if os.path.isfile(out_file):
                        shutil.copy2(out_file, out_folder)
                        os.remove(out_file)
        except Exception, err:
            ret = 1
            if hasattr(err, 'message'):
                print 'Error: ', err.message
            else:
                print 'Error: ', err
            logger.error('Error: %s' % err, exc_info=True)
            raise err
        return ret
示例#2
0
def main(*args, **kwargs):
    usage = """
        Usage: ./pnml_comparator_script.py <.ini config filename>
    """
    if not check_argv(sys.argv, minimum=1, maximum=4):
        print usage
        ret = -1
    else:
        ret = 0
        try:
            config_file = sys.argv[1]
            if not config_file.endswith('.ini'):
                print config_file, ' does not end in .ini. It should...'
                raise Exception('Filename has wrong extension')
            if not isfile(config_file):
                raise Exception("El archivo especificado no existe")
            if '--debug' in sys.argv:
                pdb.set_trace()
            for filename, arguments in parse_config(config_file):
                comparator = ComparatorPnml(filename, **arguments)
                comparator.check_hull()
                complexity = comparator.compare()
                logger.info('%s complexity -> %s',filename,complexity)
                comparator.generate_pnml()
                comparator.generate_outputs()
                comparator.check_hull()
            pnml_folder,out_folder = parse_config_output(config_file)
            pwd = os.getcwd()
            for basename in os.listdir(pwd):
                if basename.endswith('.pnml'):
                    pnml_file = os.path.join(pwd, basename)
                    if os.path.isfile(pnml_file):
                        shutil.copy2(pnml_file, pnml_folder)
                        os.remove(pnml_file)
                elif basename.endswith('.out'):
                    out_file = os.path.join(pwd, basename)
                    if os.path.isfile(out_file):
                        shutil.copy2(out_file, out_folder)
                        os.remove(out_file)
        except Exception, err:
            ret = 1
            if hasattr(err, 'message'):
                print 'Error: ', err.message
            else:
                print 'Error: ', err
            raise err
        return ret
示例#3
0
文件: mains.py 项目: Macuyiko/PacH
def pnml_comparator_main():
    usage = """
        Usage: ./comparator_pnml.py <PNML filename> [--debug]
        '\n\t[--negative <Negative XES points filename>] [max_coeficient]]'\
        '\n\t[--smt-matrix [<timeout>]]'\
        '\n\t[--smt-iter [<timeout>]]'
    """
    if not check_argv(sys.argv, minimum=1, maximum=10):
        print usage
        ret = -1
    else:
        ret = 0
        try:
            args = {}
            filename = sys.argv[1]
            if not (filename.endswith('.pnml')):
                print filename, ' does not end in .pnml. It should...'
                raise Exception('Filename has wrong extension')
            if not isfile(filename):
                raise Exception("El archivo especificado no existe")
            if '--negative' in sys.argv or '-n' in sys.argv:
                nidx = '-n' in sys.argv and sys.argv.index('-n') or\
                    sys.argv.index('--negative')
                nfilename = sys.argv[nidx+1]
                if not (nfilename.endswith('.xes')):
                    print nfilename, ' does not end in .xes. It should...'
                    raise Exception('Filename does not end in .xes')
                if not isfile(nfilename):
                    raise Exception("El archivo especificado no existe")
                args['nfilename'] = nfilename
                try:
                    args['max_coef'] = int(sys.argv[nidx+2])
                except:
                    pass
            if '--smt-matrix' in sys.argv or '-smt-m' in sys.argv:
                smt_idx = '-smt-m' in sys.argv and sys.argv.index('-smt-m') or\
                    sys.argv.index('--smt-matrix')
                try:
                    args['smt_timeout_matrix'] = int(sys.argv[smt_idx+1])
                except:
                    pass
            elif '--smt-iter' in sys.argv or '-smt-i' in sys.argv:
                smt_idx = '-smt-i' in sys.argv and sys.argv.index('-smt-i') or\
                    sys.argv.index('--smt-iter')
                args['smt_iter'] = True
                try:
                    args['smt_timeout_iter'] = int(sys.argv[smt_idx+1])
                except:
                    pass
            if '--debug' in sys.argv:
                pdb.set_trace()
            if '--check' in sys.argv or '-c' in sys.argv:
                lidx = '-c' in sys.argv and sys.argv.index('-c') or\
                    sys.argv.index('--check')
                log_file = sys.argv[lidx+1]
                if not (log_file.endswith('.xes')):
                    print log_file, ' does not end in .xes. It should...'
                    raise Exception('Filename does not end in .xes')
                if not isfile(log_file):
                    raise Exception("El archivo especificado no existe")
                args['positive_log'] = log_file
            comparator = ComparatorPnml(filename, **args)
            complexity = comparator.compare()
            comparator.generate_pnml()
            comparator.generate_outputs()
            comparator.check_hull()
            if '--verbose' in sys.argv:
                print complexity
        except Exception, err:
            ret = 1
            if hasattr(err, 'message'):
                print 'Error: ', err.message
            else:
                print 'Error: ', err
            raise err
        return ret