예제 #1
0
def drs_copy(args: argparse.Namespace):
    """
    Copy drs:// object to local file or Google Storage bucket

    If 'dst' is suffixed with "/", the destination is assumed to be a folder and the file name is
    derived from the drs response and appended to 'dst'. Otherwise the destination is assumed
    to be absolute.

    examples:
        tnu drs copy drs://my-drs-id /tmp/doom  # copy to /tmp/doom
        tnu drs copy drs://my-drs-id /tmp/doom/  # copy to /tmp/doom/{file-name-from-drs-resolution}
        tnu drs copy drs://my-drs-id gs://my-cool-bucket/my-cool-bucket-key
        tnu drs copy drs://my-drs-id gs://my-cool-bucket/my-cool-bucket-key/
    """
    args.workspace, args.workspace_namespace = CLIConfig.resolve(args.workspace, args.workspace_namespace)
    kwargs: Dict[str, Any] = dict(workspace_name=args.workspace, workspace_namespace=args.workspace_namespace)
    if CLIConfig.progress_indicator_type() is not None:
        kwargs['indicator_type'] = CLIConfig.progress_indicator_type()
    drs.copy(args.drs_url, args.dst, **kwargs)
예제 #2
0
def drs_copy_batch(args: argparse.Namespace):
    """
    Copy several drs:// objects to local directory or Google Storage bucket
    examples:
        tnu drs copy-batch drs://my-drs-1 drs://my-drs-2 drs://my-drs-3 --dst /tmp/doom/
        tnu drs copy-batch drs://my-drs-1 drs://my-drs-2 drs://my-drs-3 --dst gs://my-cool-bucket/my-cool-folder
        tnu drs copy-batch --manifest manifest.json

    When not using a manifest, 'dst' is treated as a folder, and file names are derived from the drs response.
    Otherwise, in a manifest, 'dst' can either be a folder (if suffixed with "/"), or an absolute path, e.g.
    '/home/me/my-file-name.vcf.gz' or 'gs://bucket-name/pfx/my-file.vcf.gz'.

    example manifest.json:
    [
      {
        "drs_uri": "drs://my/cool/drs/uri",
        "dst": "/path/to/local/dir/"
      },
      {
        "drs_uri": "drs://my/cool/drs/uri",
        "dst": "gs://my-cook-bucket/my-cool-prefix"
      }
    ]
    """
    args.workspace, args.workspace_namespace = CLIConfig.resolve(args.workspace, args.workspace_namespace)
    kwargs: Dict[str, Any] = dict(workspace_name=args.workspace, workspace_namespace=args.workspace_namespace)
    if CLIConfig.progress_indicator_type() is not None:
        kwargs['indicator_type'] = CLIConfig.progress_indicator_type()
    if args.drs_uris:
        assert args.manifest is None, "Cannot use 'drs_uris' with '--manifest'"
        assert args.dst is not None, "Must specify a destination with '--dst'"
        drs.copy_batch_urls(args.drs_uris, args.dst, **kwargs)
    elif args.manifest:
        with open(args.manifest) as fh:
            manifest = json.loads(fh.read())
        drs.copy_batch_manifest(manifest, **kwargs)
    else:
        raise RuntimeError("Must supply either 'drs_uris' or '--manifest'")