caterva2.copy#

caterva2.copy(src, dst, urlbase=None, auth_cookie=None)#

Copy a dataset or directory to a new location.

Parameters:
  • src (Path) – The source path of the dataset or directory.

  • dst (Path) – The destination path of the dataset or directory.

  • urlbase (str) – The base of URLs of the subscriber to query. Default is caterva2.sub_urlbase_default.

  • auth_cookie (str) – An HTTP cookie for authorizing access. This must be specified unless it was already specified inside a :py_obj:`caterva2.c2context`.

Returns:

The new path of the dataset.

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=urlbase, auth_cookie=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