... |
... |
@@ -147,33 +147,41 @@ def _create_digest(digest_string): |
147
|
147
|
return digest
|
148
|
148
|
|
149
|
149
|
|
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)
|
|
150
|
+@cli.command('download-file', short_help="Download one or more files from the CAS server. "
|
|
151
|
+ "(Specified as a space-separated list of DIGEST FILE_PATH)")
|
|
152
|
+@click.argument('digest-path-list', nargs=-1, type=str, required=True) # 'digest path' pairs
|
153
|
153
|
@click.option('--verify', is_flag=True, show_default=True,
|
154
|
154
|
help="Check downloaded file's integrity.")
|
155
|
155
|
@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)
|
|
156
|
+def download_file(context, digest_path_list, verify):
|
|
157
|
+ # Downloading files:
|
|
158
|
+ downloaded_files = {}
|
163
|
159
|
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)
|
|
160
|
+ for (digest_string, file_path) in zip(digest_path_list[0::2],
|
|
161
|
+ digest_path_list[1::2]):
|
|
162
|
+ if os.path.exists(file_path):
|
|
163
|
+ click.echo("Error: Invalid value for " +
|
|
164
|
+ "path=[{}] already exists.".format(file_path), err=True)
|
|
165
|
+ continue
|
|
166
|
+
|
|
167
|
+ digest = _create_digest(digest_string)
|
|
168
|
+
|
|
169
|
+ downloader.download_file(digest, file_path)
|
|
170
|
+ downloaded_files[file_path] = digest
|
|
171
|
+
|
|
172
|
+ # Verifying:
|
|
173
|
+ for (file_path, digest) in downloaded_files.items():
|
|
174
|
+ if verify:
|
|
175
|
+ file_digest = create_digest(read_file(file_path))
|
|
176
|
+ if file_digest != digest:
|
|
177
|
+ click.echo("Error: Failed to verify path=[{}]".format(file_path), err=True)
|
|
178
|
+ continue
|
|
179
|
+
|
|
180
|
+ if os.path.isfile(file_path):
|
|
181
|
+ click.echo("Success: Pulled path=[{}] from digest=[{}/{}]"
|
|
182
|
+ .format(file_path, digest.hash, digest.size_bytes))
|
|
183
|
+ else:
|
|
184
|
+ click.echo('Error: Failed pulling "{}"'.format(file_path), err=True)
|
177
|
185
|
|
178
|
186
|
|
179
|
187
|
@cli.command('download-dir', short_help="Download a directory from the CAS server.")
|