Ejemplo n.º 1
0
def downloader():
    """
    This functions initiates the download
    :return:
    """
    user_id = session["uid"]
    filetype = request.form["type"]
    project_id = request.form["pid"]
    project_config_path = get_project_config_path(user_id, project_id)
    project = Project(project_config_path)
    data_file_name, sheet_name = project.get_current_file_and_sheet()
    data_file_path = str(Path.cwd() / "config" / "uploads" / user_id /
                         project_id / "df" / data_file_name)

    yaml_file_id = project.get_yaml_file_id(data_file_name, sheet_name)
    yaml_config_file_name = yaml_file_id + ".pickle"
    yaml_config_file_path = str(Path.cwd() / "config" / "uploads" / user_id /
                                project_id / "yf" / yaml_config_file_name)
    yaml_config = load_yaml_config(yaml_config_file_path)
    template = yaml_config.get_template()
    region = yaml_config.get_region()
    created_by = yaml_config.get_created_by()

    region_map, region_file_name = get_region_mapping(user_id, project_id,
                                                      project)
    item_table = ItemTable(region_map)
    sparql_endpoint = project.get_sparql_endpoint()
    response = generate_download_file(user_id,
                                      item_table,
                                      data_file_path,
                                      sheet_name,
                                      region,
                                      template,
                                      filetype,
                                      sparql_endpoint,
                                      created_by=created_by)
    return json.dumps(response, indent=3)
Ejemplo n.º 2
0
def get_project_files():
    """
    This function fetches the last session of the last opened files in a project when that project is reopened later.
    :return:
    """
    response = {
        "tableData": None,
        "yamlData": None,
        "wikifierData": None,
        "settings": {
            "endpoint": None
        }
    }
    if 'uid' in session:
        user_id = session["uid"]
        project_id = request.form['pid']
        project_config_path = get_project_config_path(user_id, project_id)
        project = Project(project_config_path)
        data_file_id, sheet_name = project.get_current_file_and_sheet()
        if data_file_id:
            file_extension = get_file_extension(data_file_id)
            response["tableData"] = dict()
            response["tableData"]["isCSV"] = True if file_extension.lower(
            ) == "csv" else False
            response["tableData"]["filename"] = project.get_file_name_by_id(
                data_file_id)
            data_file_path = str(
                Path(app.config['UPLOAD_FOLDER']) / user_id / project_id /
                "df" / data_file_id)
            response["tableData"].update(
                excel_to_json(data_file_path, sheet_name, True))
            if response["tableData"]["isCSV"]:
                response["tableData"]["currSheetName"] = None
                response["tableData"]["sheetNames"] = None
        else:
            response["tableData"] = None
        wikifier_config_file_name = project.get_wikifier_region_filename()
        if wikifier_config_file_name:
            wikifier_config = deserialize_wikifier_config(
                user_id, project_id, wikifier_config_file_name)
            item_table = ItemTable(wikifier_config)
            region_qnodes = item_table.get_region_qnodes()
            response["wikifierData"] = region_qnodes
        else:
            response["wikifierData"] = None
            item_table = ItemTable()

        yaml_file_id = project.get_yaml_file_id(data_file_id, sheet_name)
        if yaml_file_id:
            response["yamlData"] = dict()
            yaml_file_name = yaml_file_id + ".yaml"
            yaml_file_path = str(Path.cwd() / "config" / "uploads" / user_id /
                                 project_id / "yf" / yaml_file_name)
            response["yamlData"]["yamlFileContent"] = read_file(yaml_file_path)
            if data_file_id:
                yaml_config_file_name = yaml_file_id + ".pickle"
                yaml_config_file_path = str(Path.cwd() / "config" / "uploads" /
                                            user_id / project_id / "yf" /
                                            yaml_config_file_name)
                data_file_path = str(
                    Path(app.config['UPLOAD_FOLDER']) / user_id / project_id /
                    "df" / data_file_id)

                yaml_config = load_yaml_config(yaml_config_file_path)
                template = yaml_config.get_template()
                region = yaml_config.get_region()
                response["yamlData"]['yamlRegions'] = highlight_region(
                    item_table, data_file_path, sheet_name, region, template)
        else:
            response["yamlData"] = None
        response["settings"]["endpoint"] = project.get_sparql_endpoint()
    response_json = json.dumps(response)
    return response_json