Exemple #1
0
def do_compile(options, config):
    """
        Run run run
    """
    libs = config.get("config", "lib-dir").split(":")

    console = logging.StreamHandler()
    LOGGER.addHandler(console)

    if options.debug:
        LOGGER.setLevel(logging.DEBUG)
    else:
        LOGGER.setLevel(logging.INFO)

    compiler = Compiler(config, libs)

    success = False
    try:
        graph = compiler.graph
        statements = compiler.compile()
        sched = scheduler.Scheduler(graph)
        success = sched.run(compiler, statements)

        if not success:
            sys.stderr.write("Unable to execute all statements.\n")
        else:
            return graph.root_scope

    finally:
        pass
Exemple #2
0
def run_test(test_dir):
    """
        Run a test in the given dir
    """   
    result_module = load_module(test_dir)
    
    test_name = "<No name set>"
    try:
        test_name = result_module.NAME
    except AttributeError:
        pass
    
    result = TestResult(test_dir, test_name)

    libs = []
    
    if os.path.isdir(os.path.join(test_dir, "libs")):
        libs = [os.path.join(test_dir, "libs")]

    graph = None
    try:
        compiler = Compiler(cfg, libs, os.path.join(test_dir, "main.cf"))
        graph = compiler.graph
        statements = compiler.compile()
        sched = scheduler.Scheduler(graph)
        
        if not sched.run(compiler, statements):
            raise Exception("Unable to evaluate all statements")
            
        
        scope = graph.root_scope
        
    except Exception as exception:
        result.mark_fail(exception)
        return result
    
    validate_func = lambda graph, scope: True
    try:
        validate_func = result_module.validate
    except AttributeError:
        pass
    
    try:
        vars = scope.get_variables()
        validate_func(graph, scope)
        result.mark_success()
    except Exception as exception:
        result.mark_fail(exception)
       
    try:
        os.remove(test_dir + "c")
    except:
        pass
    
    return result
Exemple #3
0
def compile_model(config, bootstrap="true"):
    """
        Compile the configuration model
    """
    config["config"]["offline"] = "true"
    config["config"]["bootstrap"] = bootstrap

    libs = config.get("config", "lib-dir").split(":")
    compiler = Compiler(config, libs)

    graph = compiler.graph
    statements = compiler.compile()
    sched = scheduler.Scheduler(graph)
    success = sched.run(compiler, statements)

    if not success:
        sys.stderr.write("Unable to execute all statements.\n")
        sys.exit()

    return graph.root_scope