Skip to content

Commit 48e1a70

Browse files
authored
Saimon/copy move many to many (#312)
1 parent 0ffbf1e commit 48e1a70

File tree

4 files changed

+42
-12
lines changed

4 files changed

+42
-12
lines changed

cterasdk/asynchronous/core/files/browser.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,10 @@ async def copy(self, *paths, destination=None):
112112
:param list[str] paths: List of paths
113113
:param str destination: Destination
114114
"""
115-
if destination is None:
115+
try:
116+
return await io.copy(self._core, *[self.normalize(path) for path in paths], destination=self.normalize(destination))
117+
except ValueError:
116118
raise ValueError('Copy destination was not specified.')
117-
return await io.copy(self._core, *[self.normalize(path) for path in paths], destination=self.normalize(destination))
118119

119120
async def permalink(self, path):
120121
"""
@@ -206,6 +207,7 @@ async def move(self, *paths, destination=None):
206207
:param list[str] paths: List of paths
207208
:param str destination: Destination
208209
"""
209-
if destination is None:
210+
try:
211+
return await io.move(self._core, *[self.normalize(path) for path in paths], destination=self.normalize(destination))
212+
except ValueError:
210213
raise ValueError('Move destination was not specified.')
211-
return await io.move(self._core, *[self.normalize(path) for path in paths], destination=self.normalize(destination))

cterasdk/cio/core.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ def absolute(self):
7070
def instance(scope, entries):
7171
if isinstance(entries, list):
7272
return [CorePath(scope, e) for e in entries]
73+
if isinstance(entries, tuple):
74+
source, destination = entries
75+
return (CorePath(scope, source), CorePath(scope, destination))
7376
return CorePath(scope, entries)
7477

7578

@@ -237,11 +240,16 @@ def recover(*paths):
237240

238241
def _copy_or_move(paths, destination, *, message=None):
239242
param = ActionResourcesParam.instance()
240-
paths = [paths] if not isinstance(paths, list) else paths
241243
for path in paths:
242-
param.add(SrcDstParam.instance(src=path.absolute_encode, dest=destination.join(path.name).absolute_encode))
243-
if message:
244-
logger.info('%s from: %s to: %s', message, path.reference.as_posix(), destination.join(path.name).reference.as_posix())
244+
src, dest = path, destination
245+
if isinstance(path, tuple):
246+
src, dest = path
247+
else:
248+
if not dest.reference.name:
249+
raise ValueError(f'Error: No destination specified for: {src}')
250+
dest = dest.join(src.name)
251+
param.add(SrcDstParam.instance(src=src.absolute_encode, dest=dest.absolute_encode))
252+
logger.info('%s from: %s to: %s', message, src.reference.as_posix(), dest.reference.as_posix())
245253
yield param
246254

247255

cterasdk/core/files/browser.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,10 @@ def copy(self, *paths, destination=None):
118118
:param list[str] paths: List of paths
119119
:param str destination: Destination
120120
"""
121-
if destination is None:
121+
try:
122+
return io.copy(self._core, *[self.normalize(path) for path in paths], destination=self.normalize(destination))
123+
except ValueError:
122124
raise ValueError('Copy destination was not specified.')
123-
return io.copy(self._core, *[self.normalize(path) for path in paths], destination=self.normalize(destination))
124125

125126
def permalink(self, path):
126127
"""
@@ -212,9 +213,10 @@ def move(self, *paths, destination=None):
212213
:param list[str] paths: List of paths
213214
:param str destination: Destination
214215
"""
215-
if destination is None:
216+
try:
217+
return io.move(self._core, *[self.normalize(path) for path in paths], destination=self.normalize(destination))
218+
except ValueError:
216219
raise ValueError('Move destination was not specified.')
217-
return io.move(self._core, *[self.normalize(path) for path in paths], destination=self.normalize(destination))
218220

219221
def get_share_info(self, path):
220222
"""

docs/source/UserGuides/Miscellaneous/Changelog.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Improvements
88
^^^^^^^^^^^^
99

1010
* Added support for enabling or disabling Direct Mode on CTERA Portal Storage Nodes.
11+
* Support copying and moving multiple sources to multiple destinations on CTERA Portal.
1112

1213
Bug Fixes
1314
^^^^^^^^^
@@ -16,6 +17,23 @@ Bug Fixes
1617

1718
Related issues and pull requests on GitHub: `#310 <https://github.com/ctera/ctera-python-sdk/pull/310>`_,
1819
`#311 <https://github.com/ctera/ctera-python-sdk/pull/311>`_
20+
`#312 <https://github.com/ctera/ctera-python-sdk/pull/312>`_
21+
22+
.. code:: python
23+
24+
"""
25+
Copy multiple sources: the 'Sample.docx' file and the 'Spreadsheets' directory to 'My Files/Archive'
26+
"""
27+
user.files.copy('My Files/Documents/Sample.docx', 'My Files/Spreadsheets', destination='My Files/Archive')
28+
29+
"""
30+
Copy multiple sources to different destinations under a different name.
31+
"""
32+
user.files.copy(
33+
("Docs/Report_January.docx", "Archive/Jan_Report_Final.docx"),
34+
("Budget/Budget_2024.xlsx", "Finance/2024_Annual_Budget.xlsx"),
35+
("Presentations/Presentation.pptx", "Sales/Q2_Sales_Pitch.pptx")
36+
)
1937
2038
2.20.15
2139
-------

0 commit comments

Comments
 (0)