hed_cache¶
Infrastructure for caching HED schema from remote repositories.
Functions
|
Cache all schemas included with the hed installation. |
|
Cache a file from a URL. |
|
Cache all schemas at the given URLs. |
Return the current value of HED_CACHE_DIRECTORY. |
|
|
Get latest HED XML file path in a directory. |
|
Get the HED versions in the hed directory. |
|
Return the HED XML file path for a version. |
|
Set default global hed cache directory. |
- cache_local_versions(cache_folder)[source]¶
Cache all schemas included with the hed installation.
- Parameters:
cache_folder (str) – The folder holding the cache.
- Returns:
Returns -1 on cache access failure. None otherwise
- Return type:
int or None
- cache_specific_url(hed_xml_url, xml_version=None, library_name=None, cache_folder=None)[source]¶
Cache a file from a URL.
- Parameters:
hed_xml_url (str) – Path to an exact file at a URL, or a GitHub API url to a directory.
xml_version (str) – If not None and hed_xml_url is a directory, return this version or None.
library_name (str or None) – Optional schema library name.
cache_folder (str) – The path of the hed cache. Defaults to HED_CACHE_DIRECTORY.
- Returns:
Path to local hed XML file to use.
- Return type:
str
- cache_xml_versions(hed_base_urls=('https://api.github.com/repos/hed-standard/hed-schemas/contents/standard_schema/hedxml', 'https://api.github.com/repos/hed-standard/hed-schemas/contents/library_schemas'), skip_folders=('deprecated',), cache_folder=None)[source]¶
Cache all schemas at the given URLs.
- Parameters:
hed_base_urls (str or list) – Path or list of paths.
skip_folders (list) – A list of subfolders to skip over when downloading.
cache_folder (str) – The folder holding the cache.
- Returns:
- Returns -1 if cache failed, a positive number meaning time in seconds since last update
if it didn’t cache, 0 if it cached successfully this time.
- Return type:
float
Notes
The Default skip_folders is ‘deprecated’.
The HED cache folder defaults to HED_CACHE_DIRECTORY.
- The directories on Github are of the form:
https://api.github.com/repos/hed-standard/hed-schemas/contents/standard_schema/hedxml
- get_hed_version_path(xml_version=None, library_name=None, local_hed_directory=None)[source]¶
Get latest HED XML file path in a directory. Only returns filenames that exist.
- Parameters:
library_name (str or None) – Optional the schema library name.
xml_version (str or None) – If not None, return this version or None.
local_hed_directory (str) – Path to local hed directory. Defaults to HED_CACHE_DIRECTORY
- Returns:
The path to the latest HED version the hed directory.
- Return type:
str
- get_hed_versions(local_hed_directory=None, library_name=None)[source]¶
Get the HED versions in the hed directory.
- Parameters:
local_hed_directory (str) – Directory to check for versions which defaults to hed_cache.
library_name (str or None) – An optional schema library name. None retrieves the standard schema only. Pass “all” to retrieve all standard and library schemas as a dict.
- Returns:
List of version numbers or dictionary {library_name: [versions]}.
- Return type:
list or dict
- get_path_from_hed_version(hed_version, library_name=None, local_hed_directory=None)[source]¶
Return the HED XML file path for a version.
- Parameters:
hed_version (str) – The HED version that is in the hed directory.
library_name (str or None) – An optional schema library name.
local_hed_directory (str) – The local hed path to use.
- Returns:
The HED XML file path in the hed directory that corresponds to the hed version specified.
- Return type:
str
Notes
Note if no local directory is given, it defaults to HED_CACHE_DIRECTORY.