Example #1
0
File: utils.py Project: nyue/CWLab
def import_cwl(wf_path, name):
    wf_target_name = "{}.{}".format(name, supported_workflow_exts["CWL"][0])
    wf_target_path = get_path("wf", wf_target=wf_target_name)
    assert not os.path.exists(wf_target_path), f"The workflow with name \"{wf_target_name}\" already exists."
    try:
        packed_cwl = pack_cwl(wf_path)
    except Exception as e:
        raise AssertionError(
            "The provided CWL document is not valid, the error was: {}".format(str(e))
        )
    temp_dir = make_temp_dir()
    wf_temp_path = os.path.join(temp_dir, "packed.cwl")
    try:
        with open(wf_temp_path, 'w') as cwl_file:
            json.dump(packed_cwl, cwl_file)
    except Exception as e:
        raise AssertionError("Could not write CWL file.")
    job_templ_path = os.path.join(temp_dir, "job_templ.xlsx")
    generate_job_template_from_wf(
        workflow_file=wf_temp_path, 
        wf_type="CWL",
        output_file=job_templ_path, 
        show_please_fill=True
    )
    copyfile(wf_temp_path, wf_target_path)
    job_templ_target_path = get_path("job_templ", wf_target=wf_target_name)
    copyfile(job_templ_path, job_templ_target_path)
    rmtree(temp_dir)
Example #2
0
def import_wdl(wf_path, name, wf_imports_zip_path=None):
    wf_target_name = "{}.{}".format(name, supported_workflow_exts["WDL"][0])
    wf_target_path = get_path("wf", wf_target=wf_target_name)
    assert not os.path.exists(
        wf_target_path
    ), f"The workflow with name \"{wf_target_name}\" already exists."
    if wf_imports_zip_path is not None:
        # move wf and wf_import_zip to another dir for save unzipping
        # this is needed as the WDL library cannot yet
        temp_val_dir = make_temp_dir()
        wf_val_path = os.path.join(temp_val_dir, "wf_to_validate.wdl")
        copyfile(wf_path, wf_val_path)
        wf_imports_zip_val_path = os.path.join(temp_val_dir, "imports.zip")
        copyfile(wf_imports_zip_path, wf_imports_zip_val_path)
        try:
            with zipfile.ZipFile(wf_imports_zip_val_path, "r") as zip_ref:
                zip_ref.extractall(temp_val_dir)
        except Exception as e:
            raise AssertionError(
                "Could not extract the imports zip of the workflow, the error was: {}"
                .format(str(e)))
    else:
        wf_val_path = wf_path
    try:
        set_event_loop(new_event_loop())
        _ = load_and_validate_wdl(wf_val_path)
    except Exception as e:
        raise AssertionError(
            "The provided WDL document is not valid, the error was: {}".format(
                str(e)))
    temp_dir = make_temp_dir()
    job_templ_path = os.path.join(temp_dir, "job_templ.xlsx")
    generate_job_template_from_wf(workflow_file=wf_val_path,
                                  wf_type="WDL",
                                  output_file=job_templ_path,
                                  show_please_fill=True)
    copyfile(wf_path, wf_target_path)
    job_templ_target_path = get_path("job_templ", wf_target=wf_target_name)
    copyfile(job_templ_path, job_templ_target_path)
    if wf_imports_zip_path is not None:
        rmtree(temp_val_dir)
        wf_imports_zip_target_path = get_path("wf_imports_zip",
                                              wf_target=wf_target_name)
        copyfile(wf_imports_zip_path, wf_imports_zip_target_path)
    rmtree(temp_dir)