예제 #1
0
파일: index.py 프로젝트: elimgoodman/Facts
def execute():
    connect()

    #build up scope
    scope = {}
    facts_not_main = facts.Fact.objects(fact_type__ne='main_block')
    for fact in facts_not_main:
        plyer.lexer.input(fact.body)
        statements = plyer.parser.parse(fact.body, lexer=plyer.lexer)

        #FIXME: varname hack
        #FIXME: eval hack, this is awful
        param_set = exprs.NamedParamSet()
        params = fact.parseParamsFromMetadata()
        for name, typ in params.iteritems():
            param_obj = exprs.NamedParam(name, typ)
            param_set.add(param_obj)

        fn_def = exprs.FunctionDef(param_set, statements)
        
        #I'm pretty sure I have to build up the scope and then map 
        #through everything with eval and that scope
        scope["$" + fact.name] = fn_def.evaluate({})

    (main_block, created) = facts.Fact.objects.get_or_create(fact_type="main_block")
    data = main_block.body

    plyer.lexer.input(data)

    try:
        parsed = plyer.parser.parse(data, lexer=plyer.lexer)
        parsed.evaluate(scope)
    except plyer.ParseError as e:
        return jsonify(success=False, line_no=e.line_no, elem=e.elem)

    return jsonify(success=True, output=std.flush())
예제 #2
0
 def setUp(self):
     std.flush()