mergin/client_pull.py
def download_diffs_async(mc, project_directory, file_path, versions):
    """
    Starts background download project file diffs for specified versions.
    Returns handle to the pending download.

    Args:
        mc (MerginClient): MerginClient instance.
        project_directory (str): local project directory.
        file_path (str): file path relative to Mergin project root.
        versions (list): list of versions to download diffs for, e.g. ['v1', 'v2'].

    Returns:
        PullJob/None: a handle for the pending download.
    """
    mp = MerginProject(project_directory)
    project_path = mp.metadata["name"]
    file_history = mc.project_file_history_info(project_path, file_path)
    mp.log.info(f"--- version: {mc.user_agent_info()}")
    mp.log.info(f"--- start download diffs for {file_path} of {project_path}, versions: {[v for v in versions]}")

    try:
        server_info = mc.project_info(project_path)
        if file_history is None:
            file_history = mc.project_file_history_info(project_path, file_path)
    except ClientError as err:
        mp.log.error("Error getting project info: " + str(err))
        mp.log.info("--- downloading diffs aborted")
        raise

    fetch_files = []

    for version in versions:
        version_data = file_history["history"][version]
        if "diff" not in version_data:
            continue  # skip if there is no diff in history
        diff_data = copy.deepcopy(version_data)
        diff_data['version'] = version
        diff_data['diff'] = version_data['diff']
        fetch_files.append(diff_data)

    files_to_merge = []  # list of FileToMerge instances
    download_list = []  # list of all items to be downloaded
    total_size = 0
    for file in fetch_files:
        items = _download_items(file, mp.cache_dir, diff_only=True)
        dest_file_path = mp.fpath_cache(file['diff']['path'], version=file["version"])
        if os.path.exists(dest_file_path):
            continue
        files_to_merge.append(FileToMerge(dest_file_path, items))
        download_list.extend(items)
        for item in items:
            total_size += item.size

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

    job = PullJob(project_path, None, total_size, None, files_to_merge, download_list, mp.cache_dir, mp,
                  server_info, {}, mc.username())

    # start download
    job.executor = concurrent.futures.ThreadPoolExecutor(max_workers=4)
    job.futures = []
    for item in download_list:
        future = job.executor.submit(_do_download, item, mc, mp, project_path, job)
        job.futures.append(future)

    return job

    Starts background download project file diffs for specified versions.
    Returns handle to the pending download.

    Args:
        mc (MerginClient): MerginClient instance.
        project_directory (str): local project directory.
        file_path (str): file path relative to Mergin project root.
        versions (list): list of versions to download diffs for, e.g. ['v1', 'v2'].

    Returns:
        PullJob/None: a handle for the pending download.
    
Starts background download project file diffs for specified versions.
Returns handle to the pending download.
Starts background download project file diffs for specified versions . Returns handle to the pending download .
def download_diffs_async(mc, project_directory, file_path, versions):
    mp = MerginProject(project_directory)
    project_path = mp.metadata["name"]
    file_history = mc.project_file_history_info(project_path, file_path)
    mp.log.info(f"--- version: {mc.user_agent_info()}")
    mp.log.info(f"--- start download diffs for {file_path} of {project_path}, versions: {[v for v in versions]}")
    try:
        server_info = mc.project_info(project_path)
        if file_history is None:
            file_history = mc.project_file_history_info(project_path, file_path)
    except ClientError as err:
        mp.log.error("Error getting project info: " + str(err))
        mp.log.info("--- downloading diffs aborted")
        raise
    fetch_files = []
    for version in versions:
        version_data = file_history["history"][version]
        if "diff" not in version_data:
            continue  
        diff_data = copy.deepcopy(version_data)
        diff_data['version'] = version
        diff_data['diff'] = version_data['diff']
        fetch_files.append(diff_data)
    files_to_merge = []  
    download_list = []  
    total_size = 0
    for file in fetch_files:
        items = _download_items(file, mp.cache_dir, diff_only=True)
        dest_file_path = mp.fpath_cache(file['diff']['path'], version=file["version"])
        if os.path.exists(dest_file_path):
            continue
        files_to_merge.append(FileToMerge(dest_file_path, items))
        download_list.extend(items)
        for item in items:
            total_size += item.size
    mp.log.info(f"will download {len(download_list)} chunks, total size {total_size}")
    job = PullJob(project_path, None, total_size, None, files_to_merge, download_list, mp.cache_dir, mp,
                  server_info, {}, mc.username())
    job.executor = concurrent.futures.ThreadPoolExecutor(max_workers=4)
    job.futures = []
    for item in download_list:
        future = job.executor.submit(_do_download, item, mc, mp, project_path, job)
        job.futures.append(future)
    return job
def download_diffs_async ( mc , project_directory , file_path , versions ) : mp = MerginProject ( project_directory ) project_path = mp . metadata [ "name" ] file_history = mc . project_file_history_info ( project_path , file_path ) mp . log . info ( f"--- version: {mc.user_agent_info()}" ) mp . log . info ( f"--- start download diffs for {file_path} of {project_path}, versions: {[v for v in versions]}" ) try : server_info = mc . project_info ( project_path ) if file_history is None : file_history = mc . project_file_history_info ( project_path , file_path ) except ClientError as err : mp . log . error ( "Error getting project info: " + str ( err ) ) mp . log . info ( "--- downloading diffs aborted" ) raise fetch_files = [ ] for version in versions : version_data = file_history [ "history" ] [ version ] if "diff" not in version_data : continue diff_data = copy . deepcopy ( version_data ) diff_data [ 'version' ] = version diff_data [ 'diff' ] = version_data [ 'diff' ] fetch_files . append ( diff_data ) files_to_merge = [ ] download_list = [ ] total_size = 0 for file in fetch_files : items = _download_items ( file , mp . cache_dir , diff_only = True ) dest_file_path = mp . fpath_cache ( file [ 'diff' ] [ 'path' ] , version = file [ "version" ] ) if os . path . exists ( dest_file_path ) : continue files_to_merge . append ( FileToMerge ( dest_file_path , items ) ) download_list . extend ( items ) for item in items : total_size += item . size mp . log . info ( f"will download {len(download_list)} chunks, total size {total_size}" ) job = PullJob ( project_path , None , total_size , None , files_to_merge , download_list , mp . cache_dir , mp , server_info , { } , mc . username ( ) ) job . executor = concurrent . futures . ThreadPoolExecutor ( max_workers = 4 ) job . futures = [ ] for item in download_list : future = job . executor . submit ( _do_download , item , mc , mp , project_path , job ) job . futures . append ( future ) return job
Starts background download project file diffs for specified versions.
Starts background download project file diffs for specified versions .
"""
    Starts background download project file diffs for specified versions.
    Returns handle to the pending download.

    Args:
        mc (MerginClient): MerginClient instance.
        project_directory (str): local project directory.
        file_path (str): file path relative to Mergin project root.
        versions (list): list of versions to download diffs for, e.g. ['v1', 'v2'].

    Returns:
        PullJob/None: a handle for the pending download.
    """ # skip if there is no diff in history # list of FileToMerge instances # list of all items to be downloaded # start download
a handle for the pending download.
a handle for the pending download .
PullJob/None
mc
None
project_directory
local project directory.
local project directory .
file_path
file path relative to Mergin project root.
file path relative to Mergin project root .
versions
list of versions to download diffs for, e.g.
list of versions to download diffs for e . g .