U
    f»{jï,  ã                
   @   sž   d dl Z d dlZd dlZd dlmZ d dlmZ ddlm	Z
 ddlmZmZmZ ddlmZmZmZmZ ddlmZmZmZmZ dd	lmZ dZddd„ZdS )é    N)Úrmtreeé   )Ú__version__)ÚloggerÚwarnÚ_safe_inputé   )Ú_bst_license_textÚRELEASESÚTESTING_VERSIONEDÚMISC_VERSIONED)Ú_dataset_versionÚ_do_path_updateÚ	_get_pathÚ	_mne_path)Ú_compare_versionFTc           #      C   s  ddl }|	dk	r$t|	ƒdkr$tdƒ‚|dkr:|j|d�}n|dkrN|j|d�}t| tƒr^| g} dd	„ | D ƒ}|d }| d }| d
d¡}|d }t|||d�}t	 
||¡}| d¡rÀt	 
||¡}t|ƒ}t |d¡}|dkràtn|}t||ƒ}|dk	�ot|d|ƒ}|�r&t d|› d|› d|› �¡ tdƒ}|�s\|�r\|�s\t d¡ |�rX||fS |S |�s|�s| d¡�st	 |¡�rª|dk	�r˜t||||ƒ |�r¦||fS |S |�sÂ|�r¾||fS |S | d¡�r|�sàdtjk�ræd}ntdt dd�}| ¡ dk�rtdƒ‚ttjtjkd�}|dk�r0d|d< |	dk	�rB|	|d< |
dk	�r^dd |
› �i|d!< |jf |Ž}tƒ }tƒ }t|ƒD ]:\}}| | }|d" }|d# }|d$ } |||< | ||< �q~|j|dk�rÐt |ƒn|dd||dd%�}!| !¡  "t #¡ ¡ t$t|ƒƒD ]>}| | d" }|!j%|||d&� |dk	�r t& 't	 
||¡¡ �q |d'k�rlt(|d(d)� t& )t	 
|t*¡|¡ n*|d*k�r–t(|d(d)� t& )t	 
|t+¡|¡ |dk	�rÂ| d¡�r°d+n|}"t||||"ƒ t||ƒ}|�rút|d,t, -d-¡ƒ�rút.d.j/||t,d/�ƒ |�r||fS |S )0ax  Fetch an MNE-compatible dataset using pooch.

    Parameters
    ----------
    dataset_params : list of dict | dict
        The dataset name(s) and corresponding parameters to download the
        dataset(s). The dataset parameters that contains the following keys:
        ``archive_name``, ``url``, ``folder_name``, ``hash``,
        ``config_key`` (optional). See Notes.
    processor : None | "unzip" | "untar" | instance of pooch.Unzip | instance of pooch.Untar
        What to do after downloading the file. ``"unzip"`` and ``"untar"`` will
        decompress the downloaded file in place; for custom extraction (e.g.,
        only extracting certain files from the archive) pass an instance of
        :class:`pooch.Unzip` or :class:`pooch.Untar`. If ``None`` (the
        default), the files are left as-is.
    path : None | str
        Directory in which to put the dataset. If ``None``, the dataset
        location is determined by first checking whether
        ``dataset_params['config_key']`` is defined, and if so, whether that
        config key exists in the MNE-Python config file. If so, the configured
        path is used; if not, the location is set to the value of the
        ``MNE_DATA`` config key (if it exists), or ``~/mne_data`` otherwise.
    force_update : bool
        Force update of the dataset even if a local copy exists.
        Default is False.
    update_path : bool | None
        If True (default), set the mne-python config to the given
        path. If None, the user is prompted.
    download : bool
        If False and the dataset has not been downloaded yet, it will not be
        downloaded and the path will be returned as ``''`` (empty string). This
        is mostly used for testing purposes and can be safely ignored by most
        users.
    check_version : bool
        Whether to check the version of the dataset or not. Each version
        of the dataset is stored in the root with a ``version.txt`` file.
    return_version : bool
        Whether or not to return the version of the dataset or not.
        Defaults to False.
    accept : bool
        Some MNE-supplied datasets require acceptance of an additional license.
        Default is ``False``.
    auth : tuple | None
        Optional authentication tuple containing the username and
        password/token, passed to :class:`pooch.HTTPDownloader` (e.g.,
        ``auth=('foo', 012345)``).
    token : str | None
        Optional authentication token passed to :class:`pooch.HTTPDownloader`.

    Returns
    -------
    data_path : instance of Path
        The path to the fetched dataset.
    version : str
        Only returned if ``return_version`` is True.

    See Also
    --------
    mne.get_config
    mne.set_config
    mne.datasets.has_dataset

    Notes
    -----
    The ``dataset_params`` argument must contain the following keys:

    - ``archive_name``: The name of the (possibly compressed) file to download
    - ``url``: URL from which the file can be downloaded
    - ``folder_name``: the subfolder within the ``MNE_DATA`` folder in which to
        save and uncompress (if needed) the file(s)
    - ``hash``: the cryptographic hash type of the file followed by a colon and
        then the hash value (examples: "sha256:19uheid...", "md5:upodh2io...")
    - ``config_key`` (optional): key passed to :func:`mne.set_config` to store
        the on-disk location of the downloaded dataset (e.g.,
        ``"MNE_DATASETS_EEGBCI_PATH"``). This will only work for the provided
        datasets listed :ref:`here <datasets>`; do not use for user-defined
        datasets.

    An example would look like::

        {'dataset_name': 'sample',
         'archive_name': 'MNE-sample-data-processed.tar.gz',
         'hash': 'md5:12b75d1cb7df9dfb4ad73ed82f61094f',
         'url': 'https://osf.io/86qa2/download?version=5',
         'folder_name': 'MNE-sample-data',
         'config_key': 'MNE_DATASETS_SAMPLE_PATH'}

    For datasets where a single (possibly compressed) file must be downloaded,
    pass a single :class:`dict` as ``dataset_params``. For datasets where
    multiple files must be downloaded and (optionally) uncompressed separately,
    pass a list of dicts.
    r   Nr   zEauth should be a 2-tuple consisting of a username and password/token.Zuntar)Úextract_dirZunzipc                 S   s   g | ]}|d  ‘qS )Zdataset_name© )Ú.0Úparamsr   r   úR/var/www/html/bwave/python/venv/lib/python3.8/site-packages/mne/datasets/_fetch.pyÚ
<listcomp>–   s     z!fetch_dataset.<locals>.<listcomp>Ú
config_keyÚfolder_name)ÚpathÚkeyÚnameZbst_Zfakeú>zDataset z	 version z  out of date, latest version is Ú zXDataset out of date but force_update=False and download=False, returning empty data_pathZhf_sef_z--accept-brainstorm-licenseÚyz%sAgree (y/[n])? )Zusez1You must agree to the license to use this dataset)ÚprogressbarFr    ÚauthÚAuthorizationztoken ÚheadersÚarchive_nameÚurlÚhash)r   Úbase_urlÚversionÚurlsÚregistryZretry_if_failed)ÚfnameÚ
downloaderÚ	processorÚmiscT)Úignore_errorsZtestingZ
brainstormú<z.gitzÍThe {name} dataset (version {current}) is older than mne-python (version {newest}). If the examples fail, you may need to update the {name} dataset by using mne.datasets.{name}.data_path(force_update=True))r   ÚcurrentZnewest)0ÚpoochÚlenÚRuntimeErrorZUntarZUnzipÚ
isinstanceÚdictÚgetr   ÚopÚjoinÚ
startswithr   r
   Ú_FAKE_VERSIONr   r   r   ÚinfoÚisdirr   ÚsysÚargvr   r	   ÚlowerÚlevelÚloggingÚINFOZHTTPDownloaderÚ	enumerateÚcreateÚstrZ
get_loggerÚsetLevelÚgetEffectiveLevelÚrangeÚfetchÚosÚremover   Úreplacer   r   Úmne_versionÚstripr   Úformat)#Zdataset_paramsr-   r   Zforce_updateZupdate_pathÚdownloadZcheck_versionZreturn_versionÚacceptr!   Útokenr2   Únamesr   Zdataset_dictr   r   Z
final_pathZwant_versionZdata_versionZoutdatedÚemptyZanswerZdownload_paramsr,   r)   r*   ÚidxZ	this_nameZthis_datasetr$   Zdataset_urlZdataset_hashZfetcherZold_namer   r   r   Úfetch_dataset   sê    iÿ




ÿÿÿÿþý
 ÿÿ


ú
  ÿ




ÿ  üÿrW   )
NNFTTFFFNN)rB   r>   rK   Úos.pathr   r8   Úshutilr   r   r   rN   Úutilsr   r   r   Úconfigr	   r
   r   r   r   r   r   r   Úfixesr   r;   rW   r   r   r   r   Ú<module>   s*             õ