caterva2.move#

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

Move 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 move 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'))
>>> path = f'@personal/dir{np.random.randint(0, 100)}/ds-4d.b2nd'
>>> uploaded_path = cat2.upload('root-example/dir2/ds-4d.b2nd', path, urlbase=urlbase, auth_cookie=auth_cookie)
>>> newpath = f'@personal/dir{np.random.randint(0, 100)}/ds-4d-moved.b2nd'
>>> moved_path = cat2.move(path, newpath, urlbase, auth_cookie)
>>> str(moved_path) == newpath
True
>>> path.replace('@personal/', '') in cat2.get_list('@personal', urlbase, auth_cookie)
False