示例#1
0
def visualize_component_internals(filename, component):
    with open(filename, 'r') as f:
        source_text = f.read()
        ir, errors, warnings = calvin_parser(source_text)
        if component in ir['components']:
            comp_def = ir['components'][component]
            return CompInternalsViz(comp_def).render()
示例#2
0
def visualize_component_internals(filename, component):
    with open(filename, 'r') as f:
        source_text = f.read()
        ir, errors, warnings = calvin_parser(source_text, 'filename')
        for comp_def in ir['components']:
            if comp_def['name'] == component:
                return CompInternalsViz(comp_def).render()
                break
def visualize_component_internals(filename, component):
    with open(filename, 'r') as f:
        source_text = f.read()
        ir, errors, warnings = calvin_parser(source_text, 'filename')
        for comp_def in ir['components']:
            if comp_def['name'] == component:
                return CompInternalsViz(comp_def).render()
                break
示例#4
0
def compile(source_text, filename=''):
    # Steps taken:
    # 1) parser .calvin file -> IR. May produce syntax errors/warnings
    # 2) checker IR -> IR. May produce syntax errors/warnings
    # 3) analyzer IR -> app. Should not fail. Sets 'valid' property of IR to True/False
    deployable = {'valid': False, 'actors': {}, 'connections': {}}
    ir, errors, warnings = calvin_parser(source_text, filename)
    # If there were errors during parsing no IR will be generated
    if not errors:
        c_errors, c_warnings = check(ir)
        errors.extend(c_errors)
        warnings.extend(c_warnings)
        deployable = generate_app_info(ir)
    return deployable, errors, warnings
示例#5
0
def compile(source_text, filename=''):
    # Steps taken:
    # 1) parser .calvin file -> IR. May produce syntax errors/warnings
    # 2) checker IR -> IR. May produce syntax errors/warnings
    # 3) analyzer IR -> app. Should not fail. Sets 'valid' property of IR to True/False
    deployable = {'valid': False, 'actors': {}, 'connections': {}}
    ir, errors, warnings = calvin_parser(source_text, filename)
    # If there were errors during parsing no IR will be generated
    if not errors:
        c_errors, c_warnings = check(ir)
        errors.extend(c_errors)
        warnings.extend(c_warnings)
        deployable = generate_app_info(ir)
    return deployable, errors, warnings
示例#6
0
def check_script(file):
    try:
        with open(file, 'r') as source:
            source_text = source.read()
    except:
        return {}, [{'reason': 'File not found', 'line': 0, 'col': 0}], []
    # Steps taken:
    # 1) parser .calvin file -> IR. May produce syntax errors/warnings
    # 2) checker IR -> IR. May produce syntax errors/warnings
    ir, errors, warnings = calvin_parser(source_text, file)
    # If there were errors during parsing no IR will be generated
    if not errors:
        c_errors, c_warnings = check(ir)
        errors.extend(c_errors)
        warnings.extend(c_warnings)
    return ir, errors, warnings
示例#7
0
def check_script(file):
    try:
        with open(file, 'r') as source:
            source_text = source.read()
    except:
        return {}, [{'reason': 'File not found', 'line': 0, 'col': 0}], []
    # Steps taken:
    # 1) parser .calvin file -> IR. May produce syntax errors/warnings
    # 2) checker IR -> IR. May produce syntax errors/warnings
    ir, errors, warnings = calvin_parser(source_text, file)
    # If there were errors during parsing no IR will be generated
    if not errors:
        c_errors, c_warnings = check(ir)
        errors.extend(c_errors)
        warnings.extend(c_warnings)
    return ir, errors, warnings
示例#8
0
def compile(source_text, filename='', verify=True):
    # Steps taken:
    # 1) parser .calvin file -> IR. May produce syntax errors/warnings
    # 2) checker IR -> IR. May produce syntax errors/warnings
    # 3) analyzer IR -> app. Should not fail. Sets 'valid' property of IR to True/False
    deployable = {'valid': False, 'actors': {}, 'connections': {}}
    _log.debug("Parsing...")
    ir, errors, warnings = calvin_parser(source_text, filename)
    _log.debug("Parsed %s, %s, %s" % (ir, errors, warnings))
    # If there were errors during parsing no IR will be generated
    if not errors:
        c_errors, c_warnings = check(ir, verify=verify)
        errors.extend(c_errors)
        warnings.extend(c_warnings)
        deployable = generate_app_info(ir, verify=verify)
        if errors:
            deployable['valid'] = False
    _log.debug("Compiled %s, %s, %s" % (deployable, errors, warnings))
    return deployable, errors, warnings
示例#9
0
def compile(source_text, filename='', verify=True):
    # Steps taken:
    # 1) parser .calvin file -> IR. May produce syntax errors/warnings
    # 2) checker IR -> IR. May produce syntax errors/warnings
    # 3) analyzer IR -> app. Should not fail. Sets 'valid' property of IR to True/False
    deployable = {'valid': False, 'actors': {}, 'connections': {}}
    _log.debug("Parsing...")
    ir, errors, warnings = calvin_parser(source_text, filename)
    _log.debug("Parsed %s, %s, %s" % (ir, errors, warnings))
    # If there were errors during parsing no IR will be generated
    if not errors:
        c_errors, c_warnings = check(ir, verify=verify)
        errors.extend(c_errors)
        warnings.extend(c_warnings)
        deployable = generate_app_info(ir, verify=verify)
        if errors:
            deployable['valid'] = False
    _log.debug("Compiled %s, %s, %s" % (deployable, errors, warnings))
    return deployable, errors, warnings
示例#10
0
def compile(source_text, filename='', content=None, credentials=None, verify=True, node=None):
    # Steps taken:
    # 1) Verify signature when credentials supplied
    # 2) parser .calvin file -> IR. May produce syntax errors/warnings
    # 3) checker IR -> IR. May produce syntax errors/warnings
    # 4) analyzer IR -> app. Should not fail. Sets 'valid' property of IR to True/False

    deployable = {'valid': False, 'actors': {}, 'connections': {}}
    errors = [] #TODO: fill in something meaningful
    warnings = []
    if credentials:
        _log.debug("Check credentials...")
        sec = Security(node)
        sec.set_subject(credentials)
        if not sec.authenticate_subject():
            _log.error("Check credentials...failed authentication")
            # This error reason is detected in calvin control and gives proper REST response
            errors.append({'reason': "401: UNAUTHORIZED", 'line': 0, 'col': 0})
            return deployable, errors, warnings
        if (not sec.verify_signature_content(content, "application") or not sec.check_security_policy()):
            # Verification not OK if sign or cert not OK or if the signer is denied by security policies
            print "\n IN DEPLOYER\n "
            _log.error("Check credentials...failed application verification")
            # This error reason is detected in calvin control and gives proper REST response
            errors.append({'reason': "401: UNAUTHORIZED", 'line': None, 'col': None})
            return deployable, errors, warnings

    _log.debug("Parsing...")
    ir, errors, warnings = calvin_parser(source_text, filename)
    _log.debug("Parsed %s, %s, %s" % (ir, errors, warnings))
    # If there were errors during parsing no IR will be generated
    if not errors:
        c_errors, c_warnings = check(ir, verify=verify)
        errors.extend(c_errors)
        warnings.extend(c_warnings)
        deployable = generate_app_info(ir, verify=verify)
        if errors:
            deployable['valid'] = False
    _log.debug("Compiled %s, %s, %s" % (deployable, errors, warnings))
    return deployable, errors, warnings
示例#11
0
def visualize_script(filename):
    with open(filename, 'r') as f:
        source_text = f.read()
        ir, errors, warnings = calvin_parser(source_text)
        return ScriptViz(ir).render()
示例#12
0
        source_text = \
"""# Test script
component Foo() in -> out {

  x:std.Foo()

  in > x.in
  x.out > out
}

a:Foo()
b:io.StandardOut()
"""
    else:
        script = sys.argv[1]
        script = os.path.expanduser(script)
        try:
            with open(script, 'r') as source:
                source_text = source.read()
        except:
            print "Error: Could not read file: '%s'" % script
            sys.exit(1)

    result, errors, warnings = calvin_parser(source_text, script)
    if errors:
        print "{reason} {script} [{line}:{col}]".format(script=script, **error)
    else:
        errors, warnings = check(result)
        print "errors:", [x['reason'] for x in errors]
        print "warnings:", [x['reason'] for x in warnings]
 def invoke_parser(self, test, source_text=None):
     if not source_text:
         test = self.test_script_dir + test + ".calvin"
         source_text = self._read_file(test)
     return calvin_parser(source_text, test)
示例#14
0
 def invoke_parser(self, test, source_text=None):
     if not source_text:
         test = self.test_script_dir + test + '.calvin'
         source_text = self._read_file(test)
     return calvin_parser(source_text, test)