in airavata_django_portal_sdk/user_storage/api.py [0:0]
def create_user_dir(request, path="", dir_names=(), create_unique=False, storage_resource_id=None, experiment_id=None):
"""
Creates a directory, and intermediate directories if given, at the given
path in the user's storage. `dir_names` should be either a list or tuple of
directories names to create at the given path. If `create_unique` is True
and the given `dir_names` results in an already existing directory, the
`dir_names` will be modified (for example, random suffix added) until it
results in a name for a directory that doesn't exist and that directory will
get created. If `create_unique` is False (the default) and the directory
already exists, no directory will be created, but the directory resource
information will be returned. `dir_names` may also be modified to sanitize
them for file paths, for example, converting spaces to underscores. Returns
a tuple of the storage_resource_id and resource_path of the directory
resource.
If `experiment_id` provided then the path will be relative to the experiment
data directory.
"""
if remoteapi.is_remote_api_configured():
full_path = os.path.join(path, *dir_names)
resp = remoteapi.call(request,
"/user-storage/~/{path}",
path_params={"path": full_path},
data={"experiment-id": experiment_id},
method="post")
json = resp.json()
# 'path' is a new response attribute, for backwards compatibility check if it exists first
if 'path' in json:
path = json['path']
# FIXME: should use the storage_resource_id returned from remote API call
return storage_resource_id, path
backend = get_user_storage_provider(request, storage_resource_id=storage_resource_id)
# For backwards compatibility, manufacture the dir_names array as needed
final_path = _get_final_path(request, path, experiment_id)
if len(dir_names) == 0:
dir_names = []
while not backend.exists(final_path):
final_path, dir_name = os.path.split(final_path)
if dir_name == '':
break
dir_names.insert(0, dir_name)
storage_resource_id, resource_path = backend.create_dirs(final_path, dir_names=dir_names, create_unique=create_unique)
return storage_resource_id, resource_path