caterva2.copy#
- caterva2.copy(src, dst, urlbase=None, auth_cookie=None)#
Copies a dataset or directory to a new location.
- Parameters:
src¶ (Path) – Source path of the dataset or directory.
dst¶ (Path) – Destination path for the dataset or directory.
urlbase¶ (str, optional) – Base URL to query. Default to
caterva2.sub_urlbase_default
.auth_cookie¶ (str, optional) – HTTP cookie for authorization. Must be provided unless specified in a :py_obj:`caterva2.c2context`.
- Returns:
New path of the copied dataset or directory.
- Return type:
str
Examples
>>> import caterva2 as cat2 >>> import numpy as np >>> # To copy a file you need to be a registered used >>> urlbase = 'https://cat2.cloud/demo' >>> auth_cookie = cat2.get_auth_cookie(urlbase, dict(username='user@example.com', password='foo')) >>> src_path = f'@personal/dir{np.random.randint(0, 100)}/ds-4d.b2nd' >>> uploaded_path = cat2.upload('root-example/dir2/ds-4d.b2nd', src_path, urlbase, auth_cookie) >>> copy_path = f'@personal/dir{np.random.randint(0, 100)}/ds-4d-copy.b2nd' >>> copied_path = cat2.copy(src_path, copy_path, urlbase, auth_cookie) >>> str(copied_path) == copy_path True >>> datasets = cat2.get_list('@personal', urlbase, auth_cookie) >>> src_path.replace('@personal/', '') in datasets True >>> copy_path.replace('@personal/', '') in datasets True