Skip to content

Commit da77a8e

Browse files
committed
ensure functionality of file access is complete
1 parent f15ab51 commit da77a8e

3 files changed

Lines changed: 20 additions & 17 deletions

File tree

cterasdk/asynchronous/core/files/browser.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,23 @@ async def download(self, path, destination=None):
4747
"""
4848
return await Download(io.handle, self._core, path, destination).a_execute()
4949

50-
async def download_many(self, target, objects, destination=None):
50+
async def download_many(self, directory, objects, destination=None):
5151
"""
5252
Download selected files and/or directories as a ZIP archive.
5353
5454
.. warning::
5555
Only existing files and directories will be included in the resulting ZIP file.
5656
57-
:param str target: Path to cloud folder containing files and directories.
58-
:param list[str] objects: List of file and/or directory names to include.
57+
:param str directory: Path to a folder.
58+
:param list[str] objects: List of files and / or directory names to download.
5959
:param str destination: Optional path to destination file or directory. Defaults to default download directory.
6060
:returns: Path to local file.
6161
:rtype: str
6262
:raises cterasdk.exceptions.io.core.GetMetadataError: If directory not found.
6363
:raises cterasdk.exceptions.io.core.NotADirectoryException: If target path is not a directory.
6464
"""
65-
return await DownloadMany(io.handle_many, self._core, target, objects, destination).a_execute()
65+
async with EnsureDirectory(io.listdir, self._core, directory) as (_, resource):
66+
return await DownloadMany(io.handle_many, self._core, resource, directory, objects, destination).a_execute()
6667

6768
async def listdir(self, path=None, include_deleted=False):
6869
"""

cterasdk/cio/core/commands.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ class OpenMany(PortalCommand):
365365

366366
def __init__(self, function, receiver, resource, directory, *objects):
367367
super().__init__(function, receiver)
368-
self.cloudfolder = str(resource.cloudFolderInfo.uid)
368+
self.uid = str(resource.cloudFolderInfo.uid)
369369
self.directory = automatic_resolution(directory, receiver.context)
370370
self.objects = objects
371371

@@ -383,38 +383,39 @@ def get_parameter(self):
383383

384384
def _execute(self):
385385
with self.trace_execution():
386-
return self._function(self._receiver, self.cloudfolder, self.get_parameter())
386+
return self._function(self._receiver, self.uid, self.get_parameter())
387387

388388
async def _a_execute(self):
389389
with self.trace_execution():
390-
return await self._function(self._receiver, self.cloudfolder, self.get_parameter())
390+
return await self._function(self._receiver, self.uid, self.get_parameter())
391391

392392

393393
class DownloadMany(PortalCommand):
394394

395-
def __init__(self, function, receiver, target, objects, destination):
395+
def __init__(self, function, receiver, resource, directory, objects, destination):
396396
super().__init__(function, receiver)
397-
self.target = automatic_resolution(target, receiver.context)
397+
self.resource = resource
398+
self.directory = automatic_resolution(directory, receiver.context)
398399
self.objects = objects
399400
self.destination = destination
400401

401402
def get_parameter(self):
402-
return commonfs.determine_directory_and_filename(self.target.reference, self.objects, destination=self.destination, archive=True)
403+
return commonfs.determine_directory_and_filename(self.directory.reference, self.objects, destination=self.destination, archive=True)
403404

404405
def _before_command(self):
405406
for o in self.objects:
406-
logger.info('Downloading: %s', self.target.join(o).relative)
407+
logger.info('Downloading: %s', self.directory.join(o).relative)
407408

408409
def _execute(self):
409410
directory, name = self.get_parameter()
410411
with self.trace_execution():
411-
with OpenMany(self._function, self._receiver, self.target, *self.objects) as handle:
412+
with OpenMany(self._function, self._receiver, self.resource, self.directory, *self.objects) as handle:
412413
return synfs.write(directory, name, handle)
413414

414415
async def _a_execute(self):
415416
directory, name = self.get_parameter()
416417
with self.trace_execution():
417-
async with OpenMany(self._function, self._receiver, self.target, *self.objects) as handle:
418+
async with OpenMany(self._function, self._receiver, self.resource, self.directory, *self.objects) as handle:
418419
return await asynfs.write(directory, name, handle)
419420

420421

cterasdk/core/files/browser.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,23 @@ def download(self, path, destination=None):
4848
"""
4949
return Download(io.handle, self._core, path, destination).execute()
5050

51-
def download_many(self, target, objects, destination=None):
51+
def download_many(self, directory, objects, destination=None):
5252
"""
5353
Download selected files and/or directories as a ZIP archive.
5454
5555
.. warning::
5656
Only existing files and directories will be included in the resulting ZIP file.
5757
58-
:param str target: Path to the cloud folder containing files and directories.
59-
:param list[str] objects: List of file and/or directory names to include.
58+
:param str directory: Path to a folder.
59+
:param list[str] objects: List of files and / or directory names to download.
6060
:param str destination: Optional path to destination file or directory. Defaults to the default download directory.
6161
:returns: Path to the local file.
6262
:rtype: str
6363
:raises cterasdk.exceptions.io.core.GetMetadataError: If the directory was not found.
6464
:raises cterasdk.exceptions.io.core.NotADirectoryException: If the target path is not a directory.
6565
"""
66-
return DownloadMany(io.handle_many, self._core, target, objects, destination).execute()
66+
with EnsureDirectory(io.listdir, self._core, directory) as (_, resource):
67+
return DownloadMany(io.handle_many, self._core, resource, directory, objects, destination).execute()
6768

6869
def listdir(self, path=None, include_deleted=False):
6970
"""

0 commit comments

Comments
 (0)