def script(inbox, cfg):
    """
    Execute arbitrary scripts. 

    Arguments:
    
      - cfg(``dict``) script configuartion dictionary

    """
    script_name = cfg["id"]
    script_id = str(abs(hash((cfg["id"],) + tuple(inbox[0].values()))))[0:8]
    # LOG.log(mp.DEFAULT, "@papy;script %s:%s started" % (script_name, script_id))
    # LOG.log(mp.SUBDEFAULT, "@papy;%s:%s received: %s" % (script_name, script_id, inbox))
    args = {}
    args["params"] = dict(cfg["params"])
    args["in"] = {}
    for in_port in cfg["in"]:
        for inin_ports in inbox:
            in_path = inin_ports.get(in_port, None)
            if (in_path is not None):
                # first matching input-output (including type) port is linked remaining ignored
                args["in"][in_port] = in_path
                break
    # check that all input ports are connected
    if len(args["in"]) < len(cfg["in"]):
        raise Exception("not all in_ports connected, got: %s" % (args["in"],))
    # create output file for out_ports
    args["out"] = {}
    out = {}
    for i, (out_port, out_ext) in enumerate(cfg["out"]):
        if cfg["in"] == tuple(out_port_ for out_port_, _ in cfg["out"]):
            pfx = args["in"][cfg["in"][i]].split("/")[-1].split(".")[0] + "_"
            base = cfg["id"]
        else:
            pfx = args["in"][cfg["in"][0]].split("/")[-1].split(".")[0] + "_"
            base = cfg["id"] + "-" + out_port 
        if out_ext:
            out_path = cfg["dir"] + "/" + pfx + base + "." + out_ext
        else:
            out_path = cfg["dir"] + "/" + pfx + base
        args["out"][out_port] = out_path
        out[out_port] = out_path
    # evaluate and check for errors
    ret = _eval_script(cfg["evaluator"], cfg["preamble"], cfg["dir"], cfg["executable"], cfg["script"], args)
    if ret[0] != 0:
        # LOG.error("@papy;%s:%s %s:%s:%s" % (script_name, script_id, ret[0], 
        #                                                              ret[1].replace("\n", "<br>"), 
        #                                                              ret[2].replace("\n", "<br>")))
        raise Exception(ret[0], cfg["script"], ret[1], ret[2])
    #LOG.log(mp.SUBDEFAULT, "@papy;%s:%s produced:%s" % (script_name, script_id, out))
    #LOG.log(mp.DEFAULT, "@papy;script %s:%s finished" % (script_name, script_id))
    return out
Execute arbitrary scripts. 

    Arguments:
    
      - cfg(``dict``) script configuartion dictionary