Exemple #1
0
def upload_wf():
    messages = []
    data = []
    try:
        login_required()
        assert 'file' in request.files, 'No file received.'

        import_file = request.files['file']

        assert import_file.filename != '', "No file specified."

        # save the file to the CWL directory:
        metadata = json_loads(request.form.get("meta"))
        import_filename = secure_filename(import_file.filename) 
        wf_type = metadata["wf_type"] if "wf_type" in metadata.keys() else None
        
        temp_dir = make_temp_dir()
        imported_filepath = os.path.join(temp_dir, import_filename)
        import_file.save(imported_filepath)

        import_name = secure_filename(metadata["import_name"]) \
            if "import_name" in metadata.keys() and metadata["import_name"] != "" \
            else import_filename
        import_wf_(wf_path=imported_filepath, name=import_name, wf_type=wf_type)
        
        try:
            rmtree(temp_dir)
        except Exception as e:
            pass

        messages.append( { 
            "time": get_time_string(),
            "type":"success", 
            "text": import_file.filename + " successfully imported."
        } )

    except AssertionError as e:
        messages.append( handle_known_error(e, return_front_end_message=True))
    except Exception as e:
        messages.append(handle_unknown_error(e, return_front_end_message=True))
    
    return jsonify({"data":data,"messages":messages})
Exemple #2
0
def import_wf_by_path_or_url():
    messages = []
    data = []
    try:
        data_req = request.get_json()
        access_token = data_req["access_token"]
        login_required(access_token=access_token)
        wf_path = data_req["wf_path"]
        is_url = data_req["is_url"] if "is_url" in data_req.keys() else None
        import_name = data_req["import_name"]
        wf_type = data_req["wf_type"] if "wf_type" in data_req.keys() else None

        if is_url:
            validate_url(wf_path)
        else:
            allowed_dirs = get_allowed_base_dirs(
                allow_input=True,
                allow_upload=True,
                allow_download=False,
                include_tmp_dir=True
            )
            assert os.path.isfile(wf_path) and \
                check_if_path_in_dirs(wf_path, allowed_dirs) is not None, \
                "Path does not exist or you have no permission to enter it."

        import_wf_(wf_path=wf_path, name=import_name, wf_type=wf_type)

        messages.append( { 
            "time": get_time_string(),
            "type":"success", 
            "text": import_name + " successfully imported."
        } )

    except AssertionError as e:
        messages.append( handle_known_error(e, return_front_end_message=True))
    except Exception as e:
        messages.append(handle_unknown_error(e, return_front_end_message=True))
    
    return jsonify({"data":data,"messages":messages})
Exemple #3
0
def upload_wf():
    messages = []
    data = []
    try:
        metadata = json_loads(request.form.get("meta"))
        access_token = metadata["access_token"]
        login_required(access_token=access_token)

        # load metadata:
        wf_type = metadata["wf_type"] if "wf_type" in metadata.keys() else None
        # only relavant for janis:
        translate_to_cwl = metadata["translate_to_cwl"] \
            if "translate_to_cwl" in metadata.keys() else True
        translate_to_wdl = metadata["translate_to_wdl"] \
            if "translate_to_wdl" in metadata.keys() else True
        wf_name_in_script = metadata["wf_name_in_script"] \
            if "wf_name_in_script" in metadata.keys() else None

        # save the file to the CWL directory:
        assert 'wf_file' in request.files, 'No file received.'
        import_wf_file = request.files['wf_file']
        assert import_wf_file.filename != '', "No file specified."
        import_wf_filename = secure_filename(import_wf_file.filename)
        temp_dir = make_temp_dir()
        imported_wf_filepath = os.path.join(temp_dir, import_wf_filename)
        import_wf_file.save(imported_wf_filepath)

        # if existent, save imports.zip:
        wf_imports_zip_filepath = None
        if 'wf_imports_zip' in request.files.keys():
            wf_imports_zip_file = request.files['wf_imports_zip']
            wf_imports_zip_filepath = os.path.join(temp_dir, "imports.zip")
            wf_imports_zip_file.save(wf_imports_zip_filepath)

        # import workflow:
        import_name = secure_filename(metadata["import_name"]) \
            if "import_name" in metadata.keys() and metadata["import_name"] != "" \
            else import_wf_filename
        import_wf_(wf_path=imported_wf_filepath,
                   name=os.path.splitext(import_name)[0],
                   wf_type=wf_type,
                   wf_imports_zip_path=wf_imports_zip_filepath,
                   translate_to_cwl=translate_to_cwl,
                   translate_to_wdl=translate_to_wdl,
                   wf_name_in_script=wf_name_in_script)

        # cleanup temp:
        try:
            rmtree(temp_dir)
        except Exception as e:
            pass

        messages.append({
            "time":
            get_time_string(),
            "type":
            "success",
            "text":
            import_wf_file.filename + " successfully imported."
        })

    except AssertionError as e:
        messages.append(handle_known_error(e, return_front_end_message=True))
    except Exception as e:
        messages.append(handle_unknown_error(e, return_front_end_message=True))

    return jsonify({"data": data, "messages": messages})