Example #1
0
def file_list(username, root_wf_id, wf_id, path=""):
    try:
        dashboard = Dashboard(g.master_db_url, root_wf_id, wf_id=wf_id)
        details = dashboard.get_workflow_details(wf_id)
        submit_dir = details.submit_dir

        if os.path.isdir(submit_dir):
            dest = os.path.join(submit_dir, path)

            if os.path.isfile(dest):
                return "", 204

            folders = {"dirs": [], "files": []}

            for entry in os.listdir(dest):
                if os.path.isdir(os.path.join(dest, entry)):
                    folders["dirs"].append(os.path.normpath(os.path.join(path, entry)))
                else:
                    folders["files"].append(os.path.normpath(os.path.join(path, entry)))

            return serialize(folders), 200, {"Content-Type": "application/json"}

        else:
            raise ServiceError(
                ErrorResponse(
                    "SUBMIT_DIR_NOT_FOUND",
                    "%r is not a valid directory" % str(submit_dir),
                )
            )

    except NoResultFound:
        return render_template("error/workflow/workflow_details_missing.html")

    return "Error", 500
Example #2
0
def file_list(username, root_wf_id, wf_id, path=''):
    try:
        dashboard = Dashboard(g.master_db_url, root_wf_id, wf_id=wf_id)
        details = dashboard.get_workflow_details(wf_id)
        submit_dir = details.submit_dir

        if os.path.isdir(submit_dir):
            dest = os.path.join(submit_dir, path)

            if os.path.isfile(dest):
                return '', 204

            folders = {
                'dirs': [],
                'files': []
            }

            for entry in os.listdir(dest):
                if os.path.isdir(os.path.join(dest, entry)):
                    folders['dirs'].append(os.path.normpath(os.path.join(path, entry)))
                else:
                    folders['files'].append(os.path.normpath(os.path.join(path, entry)))

            return json.dumps(folders), 200, {'Content-Type': 'application/json'}

        else:
            raise ServiceError(ErrorResponse('SUBMIT_DIR_NOT_FOUND', '%r is not a valid directory' % str(submit_dir)))

    except NoResultFound:
        return render_template('error/workflow/workflow_details_missing.html')

    return 'Error', 500
Example #3
0
def file_browser(username, root_wf_id, wf_id):
    try:
        dashboard = Dashboard(g.master_db_url, root_wf_id, wf_id=wf_id)
        details = dashboard.get_workflow_details(wf_id)
        submit_dir = details.submit_dir

        if os.path.isdir(submit_dir):
            init_file = request.args.get("init_file", None)
            return render_template(
                "file-browser.html",
                root_wf_id=root_wf_id,
                wf_id=wf_id,
                init_file=init_file,
            )
        else:
            raise ServiceError(
                ErrorResponse(
                    "SUBMIT_DIR_NOT_FOUND",
                    "%r is not a valid directory" % str(submit_dir),
                )
            )

    except NoResultFound:
        return render_template("error/workflow/workflow_details_missing.html")

    return "Error", 500
Example #4
0
def file_list(username, root_wf_id, wf_id):
    try:
        dashboard = Dashboard(g.master_db_url, root_wf_id, wf_id=wf_id)
        details = dashboard.get_workflow_details(wf_id)
        submit_dir = details.submit_dir

        if os.path.isdir(submit_dir):
            folders = {}

            for folder, sub_folders, files in os.walk(submit_dir):
                folder = '/' + folder.replace(submit_dir, '', 1).lstrip('/')
                folders[folder] = {'D': [], 'F': files}

                for sub_folder in sub_folders:
                    full_sub_folder = os.path.normpath(
                        os.path.join(folder, sub_folder))
                    folders[folder]['D'].append(full_sub_folder)

            return json.dumps(folders), 200, {
                'Content-Type': 'application/json'
            }

        else:
            raise ServiceError(
                ErrorResponse('SUBMIT_DIR_NOT_FOUND',
                              '%r is not a valid directory' % str(submit_dir)))

    except NoResultFound:
        return render_template('error/workflow/workflow_details_missing.html')

    return 'Error', 500
Example #5
0
def catch_all(error):
    app_code, http_code = error.codes if hasattr(error, 'codes') else ('UNKNOWN', 500)

    log.exception(app_code)

    e = ErrorResponse(app_code, error.message)
    response_json = jsonify(e)

    return make_response(response_json, http_code, JSON_HEADER)
Example #6
0
def catch_all(error):
    log.exception(error)

    app_code, http_code = error.codes if hasattr(error, "codes") else ("UNKNOWN", 500)

    e = ErrorResponse(app_code, str(error))
    response_json = jsonify(e)

    return make_response(response_json, http_code, JSON_HEADER)
Example #7
0
def invalid_json_error(error):
    e = ErrorResponse('INVALID_JSON', error.message)
    response_json = jsonify(e)

    return make_response(response_json, 400, JSON_HEADER)
Example #8
0
def no_result_found(error):
    e = ErrorResponse('NOT_FOUND', error.message)
    response_json = jsonify(e)

    return make_response(response_json, 404, JSON_HEADER)
Example #9
0
def invalid_json_error(error):
    e = ErrorResponse("INVALID_JSON", str(error))
    response_json = jsonify(e)

    return make_response(response_json, 400, JSON_HEADER)
Example #10
0
def no_result_found(error):
    e = ErrorResponse("NOT_FOUND", str(error))
    response_json = jsonify(e)

    return make_response(response_json, 404, JSON_HEADER)