|
8 | 8 | import tempfile |
9 | 9 | import requests |
10 | 10 | from ddsc.core.upload import ProjectUpload |
11 | | -from ddsc.core.download import ProjectDownload |
| 11 | +from ddsc.core.download import ProjectFileDownloader |
12 | 12 | from ddsc.core.ddsapi import DataServiceAuth |
13 | 13 | from ddsc.core.util import KindType |
14 | 14 | from ddsc.versioncheck import get_internal_version_str |
15 | 15 | from ddsc.core.remotestore import ProjectNameOrId, RemotePath |
| 16 | +from ddsc.sdk.client import Client |
16 | 17 |
|
17 | 18 | UNAUTHORIZED_MESSAGE = """ |
18 | 19 | ERROR: Your account does not have authorization for D4S2 (the deliver/share service). |
@@ -242,6 +243,7 @@ def __init__(self, config, remote_store, print_func): |
242 | 243 | :param print_func: func used to print output somewhere |
243 | 244 | """ |
244 | 245 | self.config = config |
| 246 | + self.client = Client(config) |
245 | 247 | auth = DataServiceAuth(self.config) |
246 | 248 | api_token = auth.get_auth() |
247 | 249 | self.api = D4S2Api(config.d4s2_url, api_token) |
@@ -345,24 +347,32 @@ def _copy_project(self, project, new_project_name, path_filter): |
345 | 347 | if remote_project: |
346 | 348 | raise ValueError("A project with name '{}' already exists.".format(new_project_name)) |
347 | 349 | activity = CopyActivity(self.remote_store.data_service, project, new_project_name) |
348 | | - self._download_project(activity, project, temp_directory, path_filter) |
| 350 | + self._download_project(activity, project.id, temp_directory, path_filter) |
349 | 351 | self._upload_project(activity, new_project_name, temp_directory) |
350 | 352 | activity.finished() |
351 | 353 | shutil.rmtree(temp_directory) |
352 | 354 | return self.remote_store.fetch_remote_project(new_project_name_or_id, must_exist=True) |
353 | 355 |
|
354 | | - def _download_project(self, activity, project, temp_directory, path_filter): |
| 356 | + def _download_project(self, activity, project_id, temp_directory, path_filter): |
355 | 357 | """ |
356 | 358 | Download the project with project_name to temp_directory. |
357 | 359 | :param activity: CopyActivity: info about the copy activity are downloading for |
358 | | - :param project: remotestore.RemoteProject project to download |
| 360 | + :param project_id: uuid of the project to download |
359 | 361 | :param temp_directory: str path to directory we can download into |
360 | 362 | :param path_filter: PathFilter: filters what files are shared |
361 | 363 | """ |
| 364 | + project = self.client.get_project_by_id(project_id) |
362 | 365 | self.print_func("Downloading a copy of '{}'.".format(project.name)) |
363 | | - project_download = ProjectDownload(self.remote_store, project, temp_directory, path_filter, |
364 | | - file_download_pre_processor=DownloadedFileRelations(activity)) |
365 | | - project_download.run() |
| 366 | + |
| 367 | + downloader = ProjectFileDownloader(self.config, temp_directory, project, path_filter) |
| 368 | + downloader.run() |
| 369 | + |
| 370 | + downloaded_file_relations = DownloadedFileRelations(activity) |
| 371 | + for remote_path, dds_file in project.get_path_to_files().items(): |
| 372 | + if path_filter.include_path(remote_path): |
| 373 | + downloaded_file_relations.add(self.remote_store.data_service, |
| 374 | + remote_path, |
| 375 | + dds_file.current_version['id']) |
366 | 376 |
|
367 | 377 | def _upload_project(self, activity, project_name, temp_directory): |
368 | 378 | """ |
@@ -435,15 +445,10 @@ def __init__(self, activity): |
435 | 445 | """ |
436 | 446 | self.activity = activity |
437 | 447 |
|
438 | | - def run(self, data_service, project_file): |
| 448 | + def add(self, data_service, remote_path, file_version_id): |
439 | 449 | """ |
440 | 450 | Attach a remote file to activity with used relationship. |
441 | | - :param data_service: DataServiceApi: service used to attach relationship |
442 | | - :param project_file: ProjectFile: contains details about a file we will attach |
443 | 451 | """ |
444 | | - remote_path = project_file.path |
445 | | - file_dict = data_service.get_file(project_file.id).json() |
446 | | - file_version_id = file_dict['current_version']['id'] |
447 | 452 | data_service.create_used_relation(self.activity.id, KindType.file_str, file_version_id) |
448 | 453 | self.activity.remote_path_to_file_version_id[remote_path] = file_version_id |
449 | 454 |
|
|
0 commit comments