[Notes] [Git][BuildGrid/buildgrid][santi/76-batch-read-blobs] `download_file` command: accept list of files



Title: GitLab

Santiago Gil pushed to branch santi/76-batch-read-blobs at BuildGrid / buildgrid

Commits:

1 changed file:

Changes:

  • buildgrid/_app/commands/cmd_cas.py
    ... ... @@ -148,32 +148,33 @@ def _create_digest(digest_string):
    148 148
     
    
    149 149
     
    
    150 150
     @cli.command('download-file', short_help="Download a file from the CAS server.")
    
    151
    -@click.argument('digest-string', nargs=1, type=click.STRING, required=True)
    
    152
    -@click.argument('file-path', nargs=1, type=click.Path(exists=False), required=True)
    
    151
    +@click.argument('digest-path-list', nargs=-1, type=str)  # 'digest path' pairs
    
    153 152
     @click.option('--verify', is_flag=True, show_default=True,
    
    154 153
                   help="Check downloaded file's integrity.")
    
    155 154
     @pass_context
    
    156
    -def download_file(context, digest_string, file_path, verify):
    
    157
    -    if os.path.exists(file_path):
    
    158
    -        click.echo("Error: Invalid value for " +
    
    159
    -                   "path=[{}] already exists.".format(file_path), err=True)
    
    160
    -        return
    
    161
    -
    
    162
    -    digest = _create_digest(digest_string)
    
    163
    -    with download(context.channel, instance=context.instance_name) as downloader:
    
    164
    -        downloader.download_file(digest, file_path)
    
    165
    -
    
    166
    -    if verify:
    
    167
    -        file_digest = create_digest(read_file(file_path))
    
    168
    -        if file_digest != digest:
    
    169
    -            click.echo("Error: Failed to verify path=[{}]".format(file_path), err=True)
    
    170
    -            return
    
    171
    -
    
    172
    -    if os.path.isfile(file_path):
    
    173
    -        click.echo("Success: Pulled path=[{}] from digest=[{}/{}]"
    
    174
    -                   .format(file_path, digest.hash, digest.size_bytes))
    
    175
    -    else:
    
    176
    -        click.echo('Error: Failed pulling "{}"'.format(file_path), err=True)
    
    155
    +def download_file(context, digest_path_list, verify):
    
    156
    +    for (digest_string, file_path) in zip(digest_path_list[0::2],
    
    157
    +                                          digest_path_list[1::2]):
    
    158
    +        if os.path.exists(file_path):
    
    159
    +            click.echo("Error: Invalid value for " +
    
    160
    +                       "path=[{}] already exists.".format(file_path), err=True)
    
    161
    +            continue
    
    162
    +
    
    163
    +        digest = _create_digest(digest_string)
    
    164
    +        with download(context.channel, instance=context.instance_name) as downloader:
    
    165
    +            downloader.download_file(digest, file_path)
    
    166
    +
    
    167
    +        if verify:
    
    168
    +            file_digest = create_digest(read_file(file_path))
    
    169
    +            if file_digest != digest:
    
    170
    +                click.echo("Error: Failed to verify path=[{}]".format(file_path), err=True)
    
    171
    +                continue
    
    172
    +
    
    173
    +        if os.path.isfile(file_path):
    
    174
    +            click.echo("Success: Pulled path=[{}] from digest=[{}/{}]"
    
    175
    +                       .format(file_path, digest.hash, digest.size_bytes))
    
    176
    +        else:
    
    177
    +            click.echo('Error: Failed pulling "{}"'.format(file_path), err=True)
    
    177 178
     
    
    178 179
     
    
    179 180
     @cli.command('download-dir', short_help="Download a directory from the CAS server.")
    



  • [Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]