Beispiel #1
0
def _extract_ds_name(dataset_path):
    """
    If a path is provided, clean it to have a proper datasetname.

    If a dataset name is already provided, then i just returns it.

    Parameters
    ----------
    dataset_path: ``str``
        The path in the form of a

    Returns
    -------
    dataset_name: ``str``
        The name of the dataset (all lowercase, without "." etc.)

    """

    try:
        dataset_path = str(dataset_path)
    except:
        raise Grid2OpException(
            _EXTRACT_DS_NAME_CONVERT_ERR.format(dataset_path))

    try:
        dataset_name = os.path.split(dataset_path)[-1]
    except:
        raise UnknownEnv(_EXTRACT_DS_NAME_RECO_ERR.format(dataset_path))
    dataset_name = dataset_name.lower().rstrip().lstrip()
    dataset_name = os.path.splitext(dataset_name)[0]
    return dataset_name
Beispiel #2
0
def _update_files(env_name=None):
    """
    .. warning:: /!\\\\ Internal, do not use unless you know what you are doing /!\\\\

    Update all the "modified" files of a given environment. If ``None`` is provided as input, all local environments
    will be checked for update.

    Parameters
    ----------
    env_name: ``str``
        Name of the environment you want to update (should be locally available)

    """
    avail_envs = list_available_local_env()
    if env_name is None:
        for env_name in avail_envs:
            _update_files(env_name)
    else:
        if env_name in avail_envs:
            answer_json = _retrieve_github_content(_LIST_REMOTE_URL)

            if env_name in answer_json:
                dict_main = answer_json[env_name]
                for k, dict_ in dict_main.items():
                    _update_file(dict_, env_name, file_name=k)
            else:
                # environment is up to date
                print("Environment \"{}\" is up to date".format(env_name))
        else:
            raise UnknownEnv(
                "Impossible to locate the environment named \"{}\". Have you downlaoded it?"
                "".format(env_name))
Beispiel #3
0
def _fecth_environments(dataset_name):
    avail_datasets_json = _list_available_remote_env_aux()
    if not dataset_name in avail_datasets_json:
        known_ds = sorted(avail_datasets_json.keys())
        raise UnknownEnv(_FETCH_ENV_UNKNOWN_ERR.format(dataset_name, known_ds))
    url = _FETCH_ENV_TAR_URL.format(avail_datasets_json[dataset_name], dataset_name)
    return url
Beispiel #4
0
def _fecth_environments(dataset_name):
    avail_datasets_json = _list_available_remote_env_aux()
    if not dataset_name in avail_datasets_json:
        known_ds = sorted(avail_datasets_json.keys())
        raise UnknownEnv(_FETCH_ENV_UNKNOWN_ERR.format(dataset_name, known_ds))
    # url = _FETCH_ENV_TAR_URL.format(avail_datasets_json[dataset_name], dataset_name)
    dict_ = avail_datasets_json[dataset_name]
    baseurl, filename = dict_["base_url"], dict_["filename"]
    url = baseurl + filename
    # name is "tar.bz2" so i need to get rid of 2 extensions
    ds_name_dl = os.path.splitext(os.path.splitext(filename)[0])[0]
    return url, ds_name_dl