utilities
Download and management utilities
General Methods
- class IceAdvect.utilities.reify(wrapped)[source]
Class decorator that puts the result of the method it decorates into the instance
- IceAdvect.utilities.get_data_path(relpath: list | str | Path)[source]
Get the absolute path within a package from a relative path
- Parameters:
- relpath: list, str or pathlib.Path
Relative path
- IceAdvect.utilities.get_cache_path(relpath: list | str | Path | None = None, appname='advect')[source]
Get the path to the user cache directory for an application
- Parameters:
- relpath: list, str, pathlib.Path or None
Relative path
- appname: str, default ‘advect’
Application name
- IceAdvect.utilities.import_dependency(name: str, extra: str = '', raise_exception: bool = False)[source]
Import an optional dependency
Adapted from
pandas.compat._optional::import_optional_dependency- Parameters:
- name: str
Module name
- extra: str, default “”
Additional text to include in the
ImportErrormessage- raise_exception: bool, default False
Raise an
ImportErrorif the module is not found
- Returns:
- module: obj
Imported module
- IceAdvect.utilities.dependency_available(name: str, minversion: str | None = None)[source]
Checks whether a module is installed without importing it
Adapted from
xarray.namedarray.utils.module_available- Parameters:
- name: str
Module name
- minversionstr, optional
Minimum version of the module
- Returns:
- availablebool
Whether the module is installed
- IceAdvect.utilities.Path(filename: str | Path, *args, **kwargs)[source]
Create a
URLorpathlib.Pathobject- Parameters:
- filename: str or pathlib.Path
File path or URL
- class IceAdvect.utilities.URL(urlname: str | Path, *args, **kwargs)[source]
Handles URLs similar to
pathlib.Pathobjects- classmethod from_parts(parts: str | list | tuple)[source]
Return a
URLobject from components- Parameters:
- parts: str, list or tuple
URL components
- joinpath(*pathsegments: list[str])[source]
Append URL components to existing
- Parameters:
- pathsegments: list[str]
URL components to append
- property name
URL basename
- property netloc
URL network location
- property parent
URL parent path as a
URLobject
- property parents
URL parents as a list of
URLobjects
- property parts
URL parts as a tuple
- property path
URL path
- property scheme
URL scheme
- property stem
URL stem
- IceAdvect.utilities.get_hash(local: str | IOBase | Path, algorithm: str = 'md5', include_algorithm: bool = False)[source]
Get the hash value from a local file or
BytesIOobject- Parameters:
- local: obj, str or pathlib.Path
BytesIOobject or path to file- algorithm: str, default ‘md5’
Hashing algorithm for checksum validation
- include_algorithm: bool, default False
Include the algorithm name in the returned hash
- IceAdvect.utilities.get_git_revision_hash(refname: str = 'HEAD', short: bool = False)[source]
Get the
githash value for a particular reference- Parameters:
- refname: str, default HEAD
Symbolic reference name
- short: bool, default False
Return the shorted hash value
- IceAdvect.utilities.url_split(s: str)[source]
Recursively split a URL path into a list
- Parameters:
- s: str
URL string
- IceAdvect.utilities.get_unix_time(time_string: str, format: str = '%Y-%m-%d %H:%M:%S')[source]
Get the Unix timestamp value for a formatted date string
- Parameters:
- time_string: str
Formatted time string to parse
- format: str, default ‘%Y-%m-%d %H:%M:%S’
Format for input time string
- IceAdvect.utilities._create_default_ssl_context() SSLContext[source]
Creates the default
SSLcontext
- IceAdvect.utilities._create_ssl_context_no_verify() SSLContext[source]
Creates an
SSLcontext for unverified connections
- IceAdvect.utilities._set_ssl_context_options(context: SSLContext) None[source]
Sets the default options for the
SSLcontext
- IceAdvect.utilities.check_connection(HOST: str, context: ~ssl.SSLContext = <ssl.SSLContext object>, timeout: int = 20)[source]
Check internet connection with
httphost- Parameters:
- HOST: str
Remote
httphost- context: obj, default IceAdvect.utilities._default_ssl_context
SSLcontext forurllibopener object- timeout: int, default 20
Timeout in seconds for blocking operations
- IceAdvect.utilities.http_list(HOST: str | list, timeout: int | None = None, context: ~ssl.SSLContext = <ssl.SSLContext object>, parser=<lxml.etree.HTMLParser object>, format: str = '%Y-%m-%d %H:%M', pattern: str = '', sort: bool = False, **kwargs)[source]
List a directory on an Apache
httpServer- Parameters:
- HOST: str or list
Remote
httphost path- timeout: int or NoneType, default None
Timeout in seconds for blocking operations
- context: obj, default IceAdvect.utilities._default_ssl_context
SSLcontext forurllibopener object- parser: obj, default lxml.etree.HTMLParser()
HTMLparser forlxml- format: str, default ‘%Y-%m-%d %H:%M’
Format for input time string
- pattern: str, default ‘’
Regular expression pattern for reducing list
- sort: bool, default False
Sort output list
- Returns:
- colnames: list
Column names in a directory
- collastmod: list
Last modification times for items in the directory
- IceAdvect.utilities.from_http(HOST: str | list, timeout: int | None = None, context: ~ssl.SSLContext = <ssl.SSLContext object>, local: str | ~pathlib.Path | None = None, hash: str = '', chunk: int = 16384, headers: dict = {}, verbose: bool = False, fid: object = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, label: str | None = None, mode: oct = 509, **kwargs)[source]
Download a file from a
httphost- Parameters:
- HOST: str or list
Remote
httphost path split as list- timeout: int or NoneType, default None
Timeout in seconds for blocking operations
- context: obj, default IceAdvect.utilities._default_ssl_context
SSLcontext forurllibopener object- local: str, pathlib.Path or NoneType, default None
Path to local file
- hash: str, default ‘’
MD5hash of local file- chunk: int, default 16384
Chunk size for transfer encoding
- headers: dict, default {}
Dictionary of headers to append from URL request
- verbose: bool, default False
Print file transfer information
- fid: object, default sys.stdout
Open file object for logging file transfers if verbose
- label: str or None, default None
Label for logging file transfer information if verbose
- mode: oct, default 0o775
Permissions mode of output local file
- Returns:
- remote_buffer: obj
BytesIOrepresentation of file
- IceAdvect.utilities.from_json(HOST: str | list, timeout: int | None = None, context: ~ssl.SSLContext = <ssl.SSLContext object>, headers: dict = {}) dict[source]
Load a
JSONresponse from ahttphost- Parameters:
- HOST: str or list
Remote
httphost path split as list- timeout: int or NoneType, default None
Timeout in seconds for blocking operations
- context: obj, default IceAdvect.utilities._default_ssl_context
SSLcontext forurllibopener object- headers: dict, default {}
Dictionary of headers to append from URL request
- Returns:
- json_response: dict
JSONresponse