Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions mergin/client_pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,16 @@ class DownloadJob:
"""

def __init__(
self, project_path, total_size, version, update_tasks, download_queue_items, directory, mp, project_info
self,
project_path,
total_size,
version,
update_tasks,
download_queue_items,
directory,
mp,
project_info,
download_tmp_dir: typing.Optional[tempfile.TemporaryDirectory] = None,
):
self.project_path = project_path
self.total_size = total_size # size of data to download (in bytes)
Expand All @@ -57,6 +66,7 @@ def __init__(
self.is_cancelled = False
self.project_info = project_info # parsed JSON with project info returned from the server
self.failure_log_file = None # log file, copied from the project directory if download fails
self.download_tmp_dir = download_tmp_dir # temporary directory for downloads if specified

def dump(self):
print("--- JOB ---", self.total_size, "bytes")
Expand Down Expand Up @@ -154,11 +164,13 @@ def download_project_async(mc, project_path, directory, project_version=None):

mp.log.info(f"got project info. version {version}")

tmp_dir = tempfile.TemporaryDirectory(prefix="python-api-client-")

# prepare download
update_tasks = [] # stuff to do at the end of download
for file in project_info["files"]:
file["version"] = version
items = _download_items(file, directory)
items = _download_items(file, tmp_dir.name)
is_latest_version = project_version == latest_proj_info["version"]
update_tasks.append(UpdateTask(file["path"], items, latest_version=is_latest_version))

Expand All @@ -172,7 +184,9 @@ def download_project_async(mc, project_path, directory, project_version=None):

mp.log.info(f"will download {len(update_tasks)} files in {len(download_list)} chunks, total size {total_size}")

job = DownloadJob(project_path, total_size, version, update_tasks, download_list, directory, mp, project_info)
job = DownloadJob(
project_path, total_size, version, update_tasks, download_list, directory, mp, project_info, tmp_dir
)

# start download
job.executor = concurrent.futures.ThreadPoolExecutor(max_workers=4)
Expand Down Expand Up @@ -241,6 +255,9 @@ def download_project_finalize(job):
# final update of project metadata
job.mp.update_metadata(job.project_info)

if job.download_tmp_dir:
job.download_tmp_dir.cleanup()


def download_project_cancel(job):
"""
Expand Down
Loading