one.params
Functions for modifying, loading and saving ONE and Alyx database parameters.
Scenarios:
Load ONE with a cache dir: tries to load the Web client params from the dir
Load ONE with http address - gets cache dir from the URL map
The ONE params comprise two files: a caches file that contains a map of Alyx db URLs to cache directories, and a separate parameter file for each url containing the client parameters. The caches file also sets the default client for when no url is provided.
Module attributes
The default data download location |
Functions
Asserts that a given directory is not currently used as a cache directory. |
|
Default Web client parameters |
|
Delete parameter files. |
|
Returns the AlyxClient parameters |
|
Return the download directory for a given client. |
|
Returns the default AlyxClient URL, or None if no default is set |
|
Return the path to the root ONE parameters directory |
|
Save a set of parameters for a given client. |
|
Set up ONE parameters. |
- CACHE_DIR_DEFAULT = '/home/runner/Downloads/ONE'
The default data download location
- Type:
str
- setup(client=None, silent=False, make_default=None, username=None, cache_dir=None)[source]
Set up ONE parameters. If a client (i.e. Alyx database URL) is provided, settings for that instance will be set. If silent, the user will be prompted to input each parameter value. Pressing return will use either current parameter or the default.
- Parameters:
client (str) – An Alyx database URL. If None, the user will be prompted to input one.
silent (bool) – If True, user is not prompted for any input.
make_default (bool) – If True, client is set as the default and will be returned when calling get with no arguments.
username (str, optional) – The Alyx username to store in the params.
cache_dir (str, pathlib.Path) – The default cache directory to store in the params.
- Returns:
An updated cache map.
- Return type:
IBLParams
- get(client=None, silent=False, username=None)[source]
Returns the AlyxClient parameters
- Parameters:
silent (bool) – If true, defaults are chosen if no parameters found.
client (str) – The database URL to retrieve parameters for. If None, the default is loaded.
username (str) – The username to use. If None, the default is loaded.
- Returns:
A Params object for the AlyxClient.
- Return type:
IBLParams
- get_default_client(include_schema=True) str [source]
Returns the default AlyxClient URL, or None if no default is set
- Parameters:
include_schema (bool) – When True, the URL schema is included (i.e. http(s)://). Set to False to return the URL as a client key.
- Returns:
The default database URL with or without the schema, or None if no default is set
- Return type:
str
- save(par, client)[source]
Save a set of parameters for a given client.
- Parameters:
par (dict, IBLParams) – A set of Web client parameters to save
client (str) – The Alyx URL that corresponds to these parameters
- get_cache_dir(client=None) Path [source]
Return the download directory for a given client.
If no client is set up, the default download location is returned.
- Parameters:
client (str) – The client to return cache dir from. If None, the default client is used.
- Returns:
The download cache path
- Return type:
pathlib.Path
- get_params_dir() Path [source]
Return the path to the root ONE parameters directory
- Returns:
The root ONE parameters directory
- Return type:
pathlib.Path
- check_cache_conflict(cache_dir)[source]
Asserts that a given directory is not currently used as a cache directory. This function checks whether a given directory is used as a cache directory for an Alyx Web client. This function is called by the ONE factory to determine whether to return an OneAlyx object or not. It is also used when setting up params for a new client.
- Parameters:
cache_dir (str, pathlib.Path) – A directory to check.
- Raises:
AssertionError – The directory is set as a cache for a Web client