예제 #1
0
def to_script(ctx, path, job_path, **kwds):
    if schema_salad is None:
        raise Exception(
            "This functionality requires schema_salad and Python 2.7.")

    if cwltool is None:
        raise Exception("This functionality requires cwltool and Python 2.7.")

    uri = "file://" + os.path.abspath(job_path)

    loader = schema_salad.ref_resolver.Loader({
        "@base": uri,
        "path": {
            "@type": "@id"
        }
    })

    job, _ = loader.resolve_ref(uri)

    t = load_tool(path, False, False, cwltool.workflow.defaultMakeTool, True)

    if type(t) == int:
        return t

    process.checkRequirements(t.tool, cwl2script.supportedProcessRequirements)

    for inp in t.tool["inputs"]:
        if process.shortname(inp["id"]) in job:
            pass
        elif process.shortname(inp["id"]) not in job and "default" in inp:
            job[process.shortname(inp["id"])] = copy.copy(inp["default"])
        elif process.shortname(
                inp["id"]) not in job and inp["type"][0] == "null":
            pass
        else:
            raise Exception("Missing inputs `%s`" %
                            process.shortname(inp["id"]))

    if not kwds.get("basedir", None):
        kwds["basedir"] = os.path.dirname(os.path.abspath(job_path))

    outdir = kwds.get("outdir")

    if t.tool["class"] == "Workflow":
        print(cwl2script.generateScriptForWorkflow(t, job, outdir))
    elif t.tool["class"] == "CommandLineTool":
        print(cwl2script.generateScriptForTool(t, job, outdir))

    return 0
예제 #2
0
def to_script(ctx, path, job_path, **kwds):
    if schema_salad is None:
        raise Exception("This functionality requires schema_salad and Python 2.7.")

    if cwltool is None:
        raise Exception("This functionality requires cwltool and Python 2.7.")

    uri = "file://" + os.path.abspath(job_path)

    loader = schema_salad.ref_resolver.Loader({
        "@base": uri,
        "path": {
            "@type": "@id"
        }
    })

    job, _ = loader.resolve_ref(uri)

    t = load_tool(path, False, False, cwltool.workflow.defaultMakeTool, True)

    if type(t) == int:
        return t

    process.checkRequirements(t.tool, cwl2script.supportedProcessRequirements)

    for inp in t.tool["inputs"]:
        if process.shortname(inp["id"]) in job:
            pass
        elif process.shortname(inp["id"]) not in job and "default" in inp:
            job[process.shortname(inp["id"])] = copy.copy(inp["default"])
        elif process.shortname(inp["id"]) not in job and inp["type"][0] == "null":
            pass
        else:
            raise Exception("Missing inputs `%s`" % process.shortname(inp["id"]))

    if not kwds.get("basedir", None):
        kwds["basedir"] = os.path.dirname(os.path.abspath(job_path))

    outdir = kwds.get("outdir")

    if t.tool["class"] == "Workflow":
        print(cwl2script.generateScriptForWorkflow(t, job, outdir))
    elif t.tool["class"] == "CommandLineTool":
        print(cwl2script.generateScriptForTool(t, job, outdir))

    return 0
예제 #3
0
def main(args=None):
    parser = argparse.ArgumentParser()
    parser.add_argument("cwltool", type=str)
    parser.add_argument("cwljob", type=str)

    parser.add_argument("--conformance-test", action="store_true")
    parser.add_argument("--no-container", action="store_true")
    parser.add_argument("--basedir", type=str)
    parser.add_argument("--outdir", type=str, default=os.getcwd())

    options = parser.parse_args(args)

    uri = "file://" + os.path.abspath(options.cwljob)

    if options.conformance_test:
        loader = schema_salad.ref_resolver.Loader({})
    else:
        loader = schema_salad.ref_resolver.Loader({
            "@base": uri,
            "path": {
                "@type": "@id"
            }
        })

    job, _ = loader.resolve_ref(uri)

    t = cwltool.main.load_tool(options.cwltool, False, False, cwltool.workflow.defaultMakeTool, True)

    if type(t) == int:
        return t

    try:
        checkRequirements(t.tool, supportedProcessRequirements)
    except Exception as e:
        logging.error(e)
        return 33

    for inp in t.tool["inputs"]:
        if shortname(inp["id"]) in job:
            pass
        elif shortname(inp["id"]) not in job and "default" in inp:
            job[shortname(inp["id"])] = copy.copy(inp["default"])
        elif shortname(inp["id"]) not in job and inp["type"][0] == "null":
            pass
        else:
            raise Exception("Missing inputs `%s`" % shortname(inp["id"]))

    if options.conformance_test:
        sys.stdout.write(json.dumps(cwltool.main.single_job_executor(t, job, options.basedir, options, conformance_test=True), indent=4))
        return 0

    if not options.basedir:
        options.basedir = os.path.dirname(os.path.abspath(options.cwljob))

    outdir = options.outdir

    if t.tool["class"] == "Workflow":
        print generateScriptForWorkflow(t, job, outdir)
    elif t.tool["class"] == "CommandLineTool":
        print generateScriptForTool(t, job, outdir)

    return 0